Skip to content

Commit

Permalink
Rename GeneralOrdering to Orderer and make it no longer implement Ord…
Browse files Browse the repository at this point in the history
…ering
  • Loading branch information
kcooney committed Jun 1, 2018
1 parent 78ee8c6 commit 29772c2
Show file tree
Hide file tree
Showing 9 changed files with 86 additions and 88 deletions.
6 changes: 3 additions & 3 deletions src/main/java/junit/framework/JUnit4TestAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import org.junit.runner.Runner;
import org.junit.runner.manipulation.Filter;
import org.junit.runner.manipulation.Filterable;
import org.junit.runner.manipulation.GeneralOrdering;
import org.junit.runner.manipulation.Orderer;
import org.junit.runner.manipulation.InvalidOrderingException;
import org.junit.runner.manipulation.NoTestsRemainException;
import org.junit.runner.manipulation.Orderable;
Expand Down Expand Up @@ -101,7 +101,7 @@ public void sort(Sorter sorter) {
*
* @since 4.13
*/
public void order(GeneralOrdering ordering) throws InvalidOrderingException {
ordering.apply(fRunner);
public void order(Orderer orderer) throws InvalidOrderingException {
orderer.apply(fRunner);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import org.junit.runner.Runner;
import org.junit.runner.manipulation.Filter;
import org.junit.runner.manipulation.Filterable;
import org.junit.runner.manipulation.GeneralOrdering;
import org.junit.runner.manipulation.Orderer;
import org.junit.runner.manipulation.InvalidOrderingException;
import org.junit.runner.manipulation.NoTestsRemainException;
import org.junit.runner.manipulation.Orderable;
Expand Down Expand Up @@ -179,10 +179,10 @@ public void sort(Sorter sorter) {
*
* @since 4.13
*/
public void order(GeneralOrdering ordering) throws InvalidOrderingException {
public void order(Orderer orderer) throws InvalidOrderingException {
if (getTest() instanceof Orderable) {
Orderable adapter = (Orderable) getTest();
adapter.order(ordering);
adapter.order(orderer);
}
}

Expand Down
41 changes: 0 additions & 41 deletions src/main/java/org/junit/runner/manipulation/GeneralOrdering.java

This file was deleted.

2 changes: 1 addition & 1 deletion src/main/java/org/junit/runner/manipulation/Orderable.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ public interface Orderable extends Sortable {
* @throws InvalidOrderingException if ordering does something invalid (like remove or add
* children)
*/
void order(GeneralOrdering ordering) throws InvalidOrderingException;
void order(Orderer ordering) throws InvalidOrderingException;
}
62 changes: 62 additions & 0 deletions src/main/java/org/junit/runner/manipulation/Orderer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package org.junit.runner.manipulation;

import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.junit.runner.Description;

/**
* Orders tests.
*
* @since 4.13
*/
public final class Orderer {
private final Ordering ordering;

Orderer(Ordering delegate) {
this.ordering = delegate;
}

/**
* Orders the descriptions.
*
* @return descriptions in order
*/
public List<Description> order(Collection<Description> descriptions)
throws InvalidOrderingException {
List<Description> inOrder = ordering.orderItems(
Collections.unmodifiableCollection(descriptions));
if (!ordering.validateOrderingIsCorrect()) {
return inOrder;
}

Set<Description> uniqueDescriptions = new HashSet<Description>(descriptions);
if (!uniqueDescriptions.containsAll(inOrder)) {
throw new InvalidOrderingException("Ordering added items");
}
Set<Description> resultAsSet = new HashSet<Description>(inOrder);
if (resultAsSet.size() != inOrder.size()) {
throw new InvalidOrderingException("Ordering duplicated items");
} else if (!resultAsSet.containsAll(uniqueDescriptions)) {
throw new InvalidOrderingException("Ordering removed items");
}

return inOrder;
}

/**
* Order the tests in <code>target</code>.
*
* @throws InvalidOrderingException if ordering does something invalid (like remove or add
* children)
*/
public void apply(Object target) throws InvalidOrderingException {
if (target instanceof Orderable) {
Orderable orderable = (Orderable) target;
orderable.order(this);
}
}
}
38 changes: 6 additions & 32 deletions src/main/java/org/junit/runner/manipulation/Ordering.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Random;
import java.util.Set;

import org.junit.runner.Description;
import org.junit.runner.OrderWith;
Expand Down Expand Up @@ -118,46 +116,22 @@ public void apply(Object target) throws InvalidOrderingException {
/*
* Note that some subclasses of Ordering override apply(). The Sorter
* subclass of Ordering overrides apply() to apply the sort (this is
* done because sorting is more efficient than ordering) the
* GeneralOrdering overrides apply() to avoid having a GenericOrdering
* wrap another GenericOrdering.
* done because sorting is more efficient than ordering).
*/
if (target instanceof Orderable) {
Orderable orderable = (Orderable) target;
orderable.order(new GeneralOrdering(this));
orderable.order(new Orderer(this));
}
}

/**
* Returns {@code true} if this ordering could produce invalid results (i.e.
* if it could add or remove values).
*/
boolean validateOrderingIsCorrect() {
return true;
}

/**
* Orders the descriptions.
*
* @return descriptions in order
*/
public final List<Description> order(Collection<Description> descriptions)
throws InvalidOrderingException {
List<Description> inOrder = orderItems(Collections.unmodifiableCollection(descriptions));
if (!validateOrderingIsCorrect()) {
return inOrder;
}

Set<Description> uniqueDescriptions = new HashSet<Description>(descriptions);
if (!uniqueDescriptions.containsAll(inOrder)) {
throw new InvalidOrderingException("Ordering added items");
}
Set<Description> resultAsSet = new HashSet<Description>(inOrder);
if (resultAsSet.size() != inOrder.size()) {
throw new InvalidOrderingException("Ordering duplicated items");
} else if (!resultAsSet.containsAll(uniqueDescriptions)) {
throw new InvalidOrderingException("Ordering removed items");
}

return inOrder;
}

/**
* Implemented by sub-classes to order the descriptions.
*
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/org/junit/runner/manipulation/Sorter.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,16 @@ public int compare(Description o1, Description o2) {
* to sort tests
*
* @param comparator the {@link Comparator} to use when sorting tests
* @since 4.0
*/
public Sorter(Comparator<Description> comparator) {
this.comparator = comparator;
}

/**
* Sorts the tests in <code>target</code> using <code>comparator</code>.
*
* @since 4.0
*/
@Override
public void apply(Object target) {
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/org/junit/runners/ParentRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import org.junit.runner.Runner;
import org.junit.runner.manipulation.Filter;
import org.junit.runner.manipulation.Filterable;
import org.junit.runner.manipulation.GeneralOrdering;
import org.junit.runner.manipulation.Orderer;
import org.junit.runner.manipulation.InvalidOrderingException;
import org.junit.runner.manipulation.NoTestsRemainException;
import org.junit.runner.manipulation.Orderable;
Expand Down Expand Up @@ -449,11 +449,11 @@ public void sort(Sorter sorter) {
}

/**
* Implementation of {@link Orderable#order(GeneralOrdering)}.
* Implementation of {@link Orderable#order(Orderer)}.
*
* @since 4.13
*/
public void order(GeneralOrdering ordering) throws InvalidOrderingException {
public void order(Orderer orderer) throws InvalidOrderingException {
childrenLock.lock();
try {
List<T> children = getFilteredChildren();
Expand All @@ -469,10 +469,10 @@ public void order(GeneralOrdering ordering) throws InvalidOrderingException {
childMap.put(description, childrenWithDescription);
}
childrenWithDescription.add(child);
ordering.apply(child);
orderer.apply(child);
}

List<Description> inOrder = ordering.order(childMap.keySet());
List<Description> inOrder = orderer.order(childMap.keySet());

children = new ArrayList<T>(children.size());
for (Description description : inOrder) {
Expand Down
6 changes: 3 additions & 3 deletions src/test/java/org/junit/tests/manipulation/OrderableTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import org.junit.runner.Request;
import org.junit.runner.RunWith;
import org.junit.runner.Runner;
import org.junit.runner.manipulation.GeneralOrdering;
import org.junit.runner.manipulation.Orderer;
import org.junit.runner.manipulation.InvalidOrderingException;
import org.junit.runner.manipulation.Orderable;
import org.junit.runner.manipulation.Sorter;
Expand Down Expand Up @@ -142,8 +142,8 @@ public Description getDescription() {
return delegate.getDescription();
}

public void order(GeneralOrdering ordering) throws InvalidOrderingException {
delegate.order(ordering);
public void order(Orderer orderer) throws InvalidOrderingException {
delegate.order(orderer);
}

public void sort(Sorter sorter) {
Expand Down

0 comments on commit 29772c2

Please sign in to comment.