File tree 3 files changed +16
-8
lines changed
src/main/java/org/junit/runner/manipulation
3 files changed +16
-8
lines changed Original file line number Diff line number Diff line change @@ -24,6 +24,10 @@ public List<Description> order(Collection<Description> siblings) {
24
24
25
25
@ Override
26
26
public void apply (Object runner ) throws InvalidOrderingException {
27
+ /*
28
+ * We overwrite apply() to avoid having a GenericOrdering wrap another
29
+ * GenericOrdering.
30
+ */
27
31
if (runner instanceof Orderable ) {
28
32
Orderable orderable = (Orderable ) runner ;
29
33
orderable .order (this );
Original file line number Diff line number Diff line change @@ -56,6 +56,13 @@ public static Ordering definedBy(Class<? extends Ordering> orderingClass)
56
56
* @throws InvalidOrderingException if ordering does something invalid (like remove or add children)
57
57
*/
58
58
public void apply (Object runner ) throws InvalidOrderingException {
59
+ /*
60
+ * If the runner is Sortable but not Orderable and this Ordering is a
61
+ * Sorter, then the Sorter subclass overrides apply() to apply the sort.
62
+ *
63
+ * Note that GenericOrdering also overrides apply() to avoid having a
64
+ * GenericOrdering wrap another GenericOrdering.
65
+ */
59
66
if (runner instanceof Orderable ) {
60
67
Orderable orderable = (Orderable ) runner ;
61
68
orderable .order (new GenericOrdering (this ));
Original file line number Diff line number Diff line change @@ -41,17 +41,14 @@ public Sorter(Comparator<Description> comparator) {
41
41
*/
42
42
@ Override
43
43
public void apply (Object runner ) {
44
- // Sorting is more efficient than ordering, so check if the runner is Sortable first
44
+ /*
45
+ * Note that all runners that are Orderable are also Sortable (because
46
+ * Orderable extends Sortable). Sorting is more efficient than ordering,
47
+ * so we override the parent behavior so we sort instead.
48
+ */
45
49
if (runner instanceof Sortable ) {
46
50
Sortable sortable = (Sortable ) runner ;
47
51
sortable .sort (this );
48
- } else {
49
- try {
50
- super .apply (runner );
51
- } catch (InvalidOrderingException e ) {
52
- // Can never get here when applying a sortable ordering.
53
- throw new AssertionError (e );
54
- }
55
52
}
56
53
}
57
54
You can’t perform that action at this time.
0 commit comments