Skip to content

Commit

Permalink
Remove unreachable code
Browse files Browse the repository at this point in the history
  • Loading branch information
kcooney committed Apr 25, 2015
1 parent 44b64df commit 00ec63f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ public List<Description> order(Collection<Description> 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);
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/org/junit/runner/manipulation/Ordering.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@ public static Ordering definedBy(Class<? extends Ordering> 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));
Expand Down
13 changes: 5 additions & 8 deletions src/main/java/org/junit/runner/manipulation/Sorter.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,14 @@ public Sorter(Comparator<Description> 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);
}
}
}

Expand Down

0 comments on commit 00ec63f

Please sign in to comment.