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)}. * * */ public class Sorter implements Comparator { /** * NULL is a Sorter that leaves elements in an undefined order */ public static Sorter NULL= new Sorter(new Comparator() { public int compare(Description o1, Description o2) { return 0; }}); private final Comparator fComparator; /** * Creates a Sorter that uses comparator * to sort tests * @param comparator the {@link Comparator} to use when sorting tests */ public Sorter(Comparator comparator) { fComparator= comparator; } /** * Sorts the test in runner using comparator * @param object */ public void apply(Object object) { if (object instanceof Sortable) { Sortable sortable = (Sortable) object; sortable.sort(this); } } public int compare(Description o1, Description o2) { return fComparator.compare(o1, o2); } }