Skip to content

Commit 29772c2

Browse files
committed
Rename GeneralOrdering to Orderer and make it no longer implement Ordering
1 parent 78ee8c6 commit 29772c2

File tree

9 files changed

+86
-88
lines changed

9 files changed

+86
-88
lines changed

src/main/java/junit/framework/JUnit4TestAdapter.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import org.junit.runner.Runner;
1010
import org.junit.runner.manipulation.Filter;
1111
import org.junit.runner.manipulation.Filterable;
12-
import org.junit.runner.manipulation.GeneralOrdering;
12+
import org.junit.runner.manipulation.Orderer;
1313
import org.junit.runner.manipulation.InvalidOrderingException;
1414
import org.junit.runner.manipulation.NoTestsRemainException;
1515
import org.junit.runner.manipulation.Orderable;
@@ -101,7 +101,7 @@ public void sort(Sorter sorter) {
101101
*
102102
* @since 4.13
103103
*/
104-
public void order(GeneralOrdering ordering) throws InvalidOrderingException {
105-
ordering.apply(fRunner);
104+
public void order(Orderer orderer) throws InvalidOrderingException {
105+
orderer.apply(fRunner);
106106
}
107107
}

src/main/java/org/junit/internal/runners/JUnit38ClassRunner.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import org.junit.runner.Runner;
1616
import org.junit.runner.manipulation.Filter;
1717
import org.junit.runner.manipulation.Filterable;
18-
import org.junit.runner.manipulation.GeneralOrdering;
18+
import org.junit.runner.manipulation.Orderer;
1919
import org.junit.runner.manipulation.InvalidOrderingException;
2020
import org.junit.runner.manipulation.NoTestsRemainException;
2121
import org.junit.runner.manipulation.Orderable;
@@ -179,10 +179,10 @@ public void sort(Sorter sorter) {
179179
*
180180
* @since 4.13
181181
*/
182-
public void order(GeneralOrdering ordering) throws InvalidOrderingException {
182+
public void order(Orderer orderer) throws InvalidOrderingException {
183183
if (getTest() instanceof Orderable) {
184184
Orderable adapter = (Orderable) getTest();
185-
adapter.order(ordering);
185+
adapter.order(orderer);
186186
}
187187
}
188188

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

-41
This file was deleted.

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@ public interface Orderable extends Sortable {
1717
* @throws InvalidOrderingException if ordering does something invalid (like remove or add
1818
* children)
1919
*/
20-
void order(GeneralOrdering ordering) throws InvalidOrderingException;
20+
void order(Orderer ordering) throws InvalidOrderingException;
2121
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
package org.junit.runner.manipulation;
2+
3+
import java.util.Collection;
4+
import java.util.Collections;
5+
import java.util.HashSet;
6+
import java.util.List;
7+
import java.util.Set;
8+
9+
import org.junit.runner.Description;
10+
11+
/**
12+
* Orders tests.
13+
*
14+
* @since 4.13
15+
*/
16+
public final class Orderer {
17+
private final Ordering ordering;
18+
19+
Orderer(Ordering delegate) {
20+
this.ordering = delegate;
21+
}
22+
23+
/**
24+
* Orders the descriptions.
25+
*
26+
* @return descriptions in order
27+
*/
28+
public List<Description> order(Collection<Description> descriptions)
29+
throws InvalidOrderingException {
30+
List<Description> inOrder = ordering.orderItems(
31+
Collections.unmodifiableCollection(descriptions));
32+
if (!ordering.validateOrderingIsCorrect()) {
33+
return inOrder;
34+
}
35+
36+
Set<Description> uniqueDescriptions = new HashSet<Description>(descriptions);
37+
if (!uniqueDescriptions.containsAll(inOrder)) {
38+
throw new InvalidOrderingException("Ordering added items");
39+
}
40+
Set<Description> resultAsSet = new HashSet<Description>(inOrder);
41+
if (resultAsSet.size() != inOrder.size()) {
42+
throw new InvalidOrderingException("Ordering duplicated items");
43+
} else if (!resultAsSet.containsAll(uniqueDescriptions)) {
44+
throw new InvalidOrderingException("Ordering removed items");
45+
}
46+
47+
return inOrder;
48+
}
49+
50+
/**
51+
* Order the tests in <code>target</code>.
52+
*
53+
* @throws InvalidOrderingException if ordering does something invalid (like remove or add
54+
* children)
55+
*/
56+
public void apply(Object target) throws InvalidOrderingException {
57+
if (target instanceof Orderable) {
58+
Orderable orderable = (Orderable) target;
59+
orderable.order(this);
60+
}
61+
}
62+
}

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

+6-32
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,8 @@
44
import java.util.ArrayList;
55
import java.util.Collection;
66
import java.util.Collections;
7-
import java.util.HashSet;
87
import java.util.List;
98
import java.util.Random;
10-
import java.util.Set;
119

1210
import org.junit.runner.Description;
1311
import org.junit.runner.OrderWith;
@@ -118,46 +116,22 @@ public void apply(Object target) throws InvalidOrderingException {
118116
/*
119117
* Note that some subclasses of Ordering override apply(). The Sorter
120118
* subclass of Ordering overrides apply() to apply the sort (this is
121-
* done because sorting is more efficient than ordering) the
122-
* GeneralOrdering overrides apply() to avoid having a GenericOrdering
123-
* wrap another GenericOrdering.
119+
* done because sorting is more efficient than ordering).
124120
*/
125121
if (target instanceof Orderable) {
126122
Orderable orderable = (Orderable) target;
127-
orderable.order(new GeneralOrdering(this));
123+
orderable.order(new Orderer(this));
128124
}
129125
}
130126

127+
/**
128+
* Returns {@code true} if this ordering could produce invalid results (i.e.
129+
* if it could add or remove values).
130+
*/
131131
boolean validateOrderingIsCorrect() {
132132
return true;
133133
}
134134

135-
/**
136-
* Orders the descriptions.
137-
*
138-
* @return descriptions in order
139-
*/
140-
public final List<Description> order(Collection<Description> descriptions)
141-
throws InvalidOrderingException {
142-
List<Description> inOrder = orderItems(Collections.unmodifiableCollection(descriptions));
143-
if (!validateOrderingIsCorrect()) {
144-
return inOrder;
145-
}
146-
147-
Set<Description> uniqueDescriptions = new HashSet<Description>(descriptions);
148-
if (!uniqueDescriptions.containsAll(inOrder)) {
149-
throw new InvalidOrderingException("Ordering added items");
150-
}
151-
Set<Description> resultAsSet = new HashSet<Description>(inOrder);
152-
if (resultAsSet.size() != inOrder.size()) {
153-
throw new InvalidOrderingException("Ordering duplicated items");
154-
} else if (!resultAsSet.containsAll(uniqueDescriptions)) {
155-
throw new InvalidOrderingException("Ordering removed items");
156-
}
157-
158-
return inOrder;
159-
}
160-
161135
/**
162136
* Implemented by sub-classes to order the descriptions.
163137
*

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

+3
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,16 @@ public int compare(Description o1, Description o2) {
3232
* to sort tests
3333
*
3434
* @param comparator the {@link Comparator} to use when sorting tests
35+
* @since 4.0
3536
*/
3637
public Sorter(Comparator<Description> comparator) {
3738
this.comparator = comparator;
3839
}
3940

4041
/**
4142
* Sorts the tests in <code>target</code> using <code>comparator</code>.
43+
*
44+
* @since 4.0
4245
*/
4346
@Override
4447
public void apply(Object target) {

src/main/java/org/junit/runners/ParentRunner.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
import org.junit.runner.Runner;
3333
import org.junit.runner.manipulation.Filter;
3434
import org.junit.runner.manipulation.Filterable;
35-
import org.junit.runner.manipulation.GeneralOrdering;
35+
import org.junit.runner.manipulation.Orderer;
3636
import org.junit.runner.manipulation.InvalidOrderingException;
3737
import org.junit.runner.manipulation.NoTestsRemainException;
3838
import org.junit.runner.manipulation.Orderable;
@@ -449,11 +449,11 @@ public void sort(Sorter sorter) {
449449
}
450450

451451
/**
452-
* Implementation of {@link Orderable#order(GeneralOrdering)}.
452+
* Implementation of {@link Orderable#order(Orderer)}.
453453
*
454454
* @since 4.13
455455
*/
456-
public void order(GeneralOrdering ordering) throws InvalidOrderingException {
456+
public void order(Orderer orderer) throws InvalidOrderingException {
457457
childrenLock.lock();
458458
try {
459459
List<T> children = getFilteredChildren();
@@ -469,10 +469,10 @@ public void order(GeneralOrdering ordering) throws InvalidOrderingException {
469469
childMap.put(description, childrenWithDescription);
470470
}
471471
childrenWithDescription.add(child);
472-
ordering.apply(child);
472+
orderer.apply(child);
473473
}
474474

475-
List<Description> inOrder = ordering.order(childMap.keySet());
475+
List<Description> inOrder = orderer.order(childMap.keySet());
476476

477477
children = new ArrayList<T>(children.size());
478478
for (Description description : inOrder) {

src/test/java/org/junit/tests/manipulation/OrderableTest.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import org.junit.runner.Request;
1111
import org.junit.runner.RunWith;
1212
import org.junit.runner.Runner;
13-
import org.junit.runner.manipulation.GeneralOrdering;
13+
import org.junit.runner.manipulation.Orderer;
1414
import org.junit.runner.manipulation.InvalidOrderingException;
1515
import org.junit.runner.manipulation.Orderable;
1616
import org.junit.runner.manipulation.Sorter;
@@ -142,8 +142,8 @@ public Description getDescription() {
142142
return delegate.getDescription();
143143
}
144144

145-
public void order(GeneralOrdering ordering) throws InvalidOrderingException {
146-
delegate.order(ordering);
145+
public void order(Orderer orderer) throws InvalidOrderingException {
146+
delegate.order(orderer);
147147
}
148148

149149
public void sort(Sorter sorter) {

0 commit comments

Comments
 (0)