KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > junit > runner > manipulation > Sorter


1 package org.junit.runner.manipulation;
2
3 import java.util.Comparator JavaDoc;
4
5 import org.junit.runner.Description;
6 import org.junit.runner.Runner;
7
8 /**
9  * 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 JavaDoc<Description> {
15     private final Comparator JavaDoc<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 JavaDoc<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 }
42
Popular Tags