|
4 | 4 | import java.util.ArrayList;
|
5 | 5 | import java.util.Collection;
|
6 | 6 | import java.util.Collections;
|
7 |
| -import java.util.HashSet; |
8 | 7 | import java.util.List;
|
9 | 8 | import java.util.Random;
|
10 |
| -import java.util.Set; |
11 | 9 |
|
12 | 10 | import org.junit.runner.Description;
|
13 | 11 | import org.junit.runner.OrderWith;
|
@@ -118,46 +116,22 @@ public void apply(Object target) throws InvalidOrderingException {
|
118 | 116 | /*
|
119 | 117 | * Note that some subclasses of Ordering override apply(). The Sorter
|
120 | 118 | * 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). |
124 | 120 | */
|
125 | 121 | if (target instanceof Orderable) {
|
126 | 122 | Orderable orderable = (Orderable) target;
|
127 |
| - orderable.order(new GeneralOrdering(this)); |
| 123 | + orderable.order(new Orderer(this)); |
128 | 124 | }
|
129 | 125 | }
|
130 | 126 |
|
| 127 | + /** |
| 128 | + * Returns {@code true} if this ordering could produce invalid results (i.e. |
| 129 | + * if it could add or remove values). |
| 130 | + */ |
131 | 131 | boolean validateOrderingIsCorrect() {
|
132 | 132 | return true;
|
133 | 133 | }
|
134 | 134 |
|
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 |
| - |
161 | 135 | /**
|
162 | 136 | * Implemented by sub-classes to order the descriptions.
|
163 | 137 | *
|
|
0 commit comments