Skip to content

Commit cb5c609

Browse files
committed
Remove unreachable code
1 parent 44b64df commit cb5c609

File tree

3 files changed

+16
-8
lines changed

3 files changed

+16
-8
lines changed

src/main/java/org/junit/runner/manipulation/GenericOrdering.java

+4
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ public List<Description> order(Collection<Description> siblings) {
2424

2525
@Override
2626
public void apply(Object runner) throws InvalidOrderingException {
27+
/*
28+
* We overwrite apply() to avoid having a GenericOrdering wrap another
29+
* GenericOrdering.
30+
*/
2731
if (runner instanceof Orderable) {
2832
Orderable orderable = (Orderable) runner;
2933
orderable.order(this);

src/main/java/org/junit/runner/manipulation/Ordering.java

+7
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,13 @@ public static Ordering definedBy(Class<? extends Ordering> orderingClass)
5656
* @throws InvalidOrderingException if ordering does something invalid (like remove or add children)
5757
*/
5858
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+
*/
5966
if (runner instanceof Orderable) {
6067
Orderable orderable = (Orderable) runner;
6168
orderable.order(new GenericOrdering(this));

src/main/java/org/junit/runner/manipulation/Sorter.java

+5-8
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,14 @@ public Sorter(Comparator<Description> comparator) {
4141
*/
4242
@Override
4343
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+
*/
4549
if (runner instanceof Sortable) {
4650
Sortable sortable = (Sortable) runner;
4751
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-
}
5552
}
5653
}
5754

0 commit comments

Comments
 (0)