01: package org.junit.runner.manipulation;
02:
03: import java.util.Comparator;
04:
05: import org.junit.runner.Description;
06: import org.junit.runner.Runner;
07:
08: /**
09: * A <code>Sorter</code> orders tests. In general you will not need
10: * to use a <code>Sorter</code> directly. Instead, use {@link org.junit.runner.Request#sortWith(Comparator)}.
11: *
12: *
13: */
14: public class Sorter implements Comparator<Description> {
15: private final Comparator<Description> fComparator;
16:
17: /**
18: * Creates a <code>Sorter</code> that uses <code>comparator</code>
19: * to sort tests
20: * @param comparator the {@link Comparator} to use when sorting tests
21: */
22: public Sorter(Comparator<Description> comparator) {
23: fComparator = comparator;
24: }
25:
26: /**
27: * Sorts the test in <code>runner</code> using <code>comparator</code>
28: * @param runner
29: */
30: public void apply(Runner runner) {
31: if (runner instanceof Sortable) {
32: Sortable sortable = (Sortable) runner;
33: sortable.sort(this );
34: }
35: }
36:
37: /** @inheritDoc */
38: public int compare(Description o1, Description o2) {
39: return fComparator.compare(o1, o2);
40: }
41: }
|