org.junit.runner.manipulation.Sorter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of junit Show documentation
Show all versions of junit Show documentation
JUnit is a unit testing framework for Java, created by Erich Gamma and Kent Beck.
package org.junit.runner.manipulation;
import java.util.Comparator;
import org.junit.runner.Description;
/**
* A Sorter
orders tests. In general you will not need
* to use a Sorter
directly. Instead, use {@link org.junit.runner.Request#sortWith(Comparator)}.
*
* @since 4.0
*/
public class Sorter implements Comparator {
/**
* NULL is a Sorter
that leaves elements in an undefined order
*/
public static final Sorter NULL = new Sorter(new Comparator() {
public int compare(Description o1, Description o2) {
return 0;
}
});
private final Comparator comparator;
/**
* Creates a Sorter
that uses comparator
* to sort tests
*
* @param comparator the {@link Comparator} to use when sorting tests
*/
public Sorter(Comparator comparator) {
this.comparator = comparator;
}
/**
* Sorts the test in runner
using comparator
*/
public void apply(Object object) {
if (object instanceof Sortable) {
Sortable sortable = (Sortable) object;
sortable.sort(this);
}
}
public int compare(Description o1, Description o2) {
return comparator.compare(o1, o2);
}
}