From e68c0159d92b5306783a50713ef35b0b539e58c5 Mon Sep 17 00:00:00 2001 From: Kevin Cooney Date: Sat, 25 Apr 2015 13:03:55 -0700 Subject: [PATCH] Remove unreachable code --- .../junit/runner/manipulation/GenericOrdering.java | 4 ++++ .../org/junit/runner/manipulation/Ordering.java | 7 +++++++ .../java/org/junit/runner/manipulation/Sorter.java | 13 +++++-------- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/junit/runner/manipulation/GenericOrdering.java b/src/main/java/org/junit/runner/manipulation/GenericOrdering.java index 17fc1a5dfd52..e8ca38f9497f 100644 --- a/src/main/java/org/junit/runner/manipulation/GenericOrdering.java +++ b/src/main/java/org/junit/runner/manipulation/GenericOrdering.java @@ -24,6 +24,10 @@ public List order(Collection siblings) { @Override public void apply(Object runner) throws InvalidOrderingException { + /* + * We overwrite apply() to avoid having a GenericOrdering wrap another + * GenericOrdering. + */ if (runner instanceof Orderable) { Orderable orderable = (Orderable) runner; orderable.order(this); diff --git a/src/main/java/org/junit/runner/manipulation/Ordering.java b/src/main/java/org/junit/runner/manipulation/Ordering.java index c5a9d399bf20..aeccd3f4fcdf 100644 --- a/src/main/java/org/junit/runner/manipulation/Ordering.java +++ b/src/main/java/org/junit/runner/manipulation/Ordering.java @@ -56,6 +56,13 @@ public static Ordering definedBy(Class orderingClass) * @throws InvalidOrderingException if ordering does something invalid (like remove or add children) */ public void apply(Object runner) throws InvalidOrderingException { + /* + * If the runner is Sortable but not Orderable and this Ordering is a + * Sorter, then the Sorter subclass overrides apply() to apply the sort. + * + * Note that GenericOrdering also overrides apply() to avoid having a + * GenericOrdering wrap another GenericOrdering. + */ if (runner instanceof Orderable) { Orderable orderable = (Orderable) runner; orderable.order(new GenericOrdering(this)); diff --git a/src/main/java/org/junit/runner/manipulation/Sorter.java b/src/main/java/org/junit/runner/manipulation/Sorter.java index 5d0a6c640c68..697227c222b4 100644 --- a/src/main/java/org/junit/runner/manipulation/Sorter.java +++ b/src/main/java/org/junit/runner/manipulation/Sorter.java @@ -41,17 +41,14 @@ public Sorter(Comparator comparator) { */ @Override public void apply(Object runner) { - // Sorting is more efficient than ordering, so check if the runner is Sortable first + /* + * Note that all runners that are Orderable are also Sortable (because + * Orderable extends Sortable). Sorting is more efficient than ordering, + * so we override the parent behavior so we sort instead. + */ if (runner instanceof Sortable) { Sortable sortable = (Sortable) runner; sortable.sort(this); - } else { - try { - super.apply(runner); - } catch (InvalidOrderingException e) { - // Can never get here when applying a sortable ordering. - throw new AssertionError(e); - } } }