27 |
|
* @summary Unit test for Collections.emptyNavigableSet |
28 |
|
* @run testng EmptyNavigableSet |
29 |
|
*/ |
30 |
+ |
|
31 |
+ |
import org.testng.Assert; |
32 |
+ |
import org.testng.Assert.ThrowingRunnable; |
33 |
+ |
import org.testng.annotations.DataProvider; |
34 |
+ |
import org.testng.annotations.Test; |
35 |
+ |
|
36 |
|
import java.math.BigInteger; |
37 |
|
import java.util.Arrays; |
38 |
|
import java.util.Collection; |
39 |
|
import java.util.Collections; |
40 |
|
import java.util.Comparator; |
41 |
|
import java.util.Iterator; |
36 |
– |
import java.util.NoSuchElementException; |
42 |
|
import java.util.NavigableSet; |
43 |
+ |
import java.util.NoSuchElementException; |
44 |
|
import java.util.SortedSet; |
45 |
|
import java.util.TreeSet; |
46 |
|
|
41 |
– |
import org.testng.Assert; |
42 |
– |
import org.testng.Assert.ThrowingRunnable; |
43 |
– |
import org.testng.annotations.Test; |
44 |
– |
import org.testng.annotations.DataProvider; |
45 |
– |
|
47 |
|
import static org.testng.Assert.assertFalse; |
48 |
+ |
import static org.testng.Assert.assertNull; |
49 |
|
import static org.testng.Assert.assertSame; |
50 |
|
import static org.testng.Assert.assertTrue; |
51 |
|
|
52 |
|
public class EmptyNavigableSet { |
53 |
|
|
54 |
|
public static <T> void assertInstance(T actual, Class<? extends T> expected) { |
55 |
< |
assertInstance(expected.isInstance(actual), null); |
55 |
> |
assertInstance(actual, expected, null); |
56 |
|
} |
57 |
|
|
58 |
|
public static <T> void assertInstance(T actual, Class<? extends T> expected, String message) { |
132 |
|
*/ |
133 |
|
@Test(dataProvider = "NavigableSet<?>", dataProviderClass = EmptyNavigableSet.class) |
134 |
|
public void testContainsRequiresComparable(String description, NavigableSet<?> navigableSet) { |
135 |
< |
assertThrowsCCE(() -> { |
136 |
< |
navigableSet.contains(new Object()); |
137 |
< |
}, |
136 |
< |
description + ": Compareable should be required"); |
135 |
> |
assertThrowsCCE( |
136 |
> |
() -> navigableSet.contains(new Object()), |
137 |
> |
description + ": Comparable should be required"); |
138 |
|
} |
139 |
|
|
140 |
|
/** |
164 |
|
*/ |
165 |
|
@Test(dataProvider = "NavigableSet<?>", dataProviderClass = EmptyNavigableSet.class) |
166 |
|
public void testEmptyIterator(String description, NavigableSet<?> navigableSet) { |
167 |
< |
Iterator emptyIterator = navigableSet.iterator(); |
167 |
< |
|
168 |
< |
assertFalse((emptyIterator != null) && (emptyIterator.hasNext()), |
169 |
< |
"The iterator is not empty."); |
167 |
> |
assertFalse(navigableSet.iterator().hasNext(), "The iterator is not empty."); |
168 |
|
} |
169 |
|
|
170 |
|
/** |
180 |
|
*/ |
181 |
|
@Test(dataProvider = "NavigableSet<?>", dataProviderClass = EmptyNavigableSet.class) |
182 |
|
public void testFirst(String description, NavigableSet<?> navigableSet) { |
183 |
< |
assertThrowsNSEE(() -> { |
186 |
< |
navigableSet.first(); |
187 |
< |
}, description); |
183 |
> |
assertThrowsNSEE(navigableSet::first, description); |
184 |
|
} |
185 |
|
|
186 |
|
/** |
206 |
|
*/ |
207 |
|
@Test(dataProvider = "NavigableSet<?>", dataProviderClass = EmptyNavigableSet.class) |
208 |
|
public void testLast(String description, NavigableSet<?> navigableSet) { |
209 |
< |
assertThrowsNSEE(() -> { |
214 |
< |
navigableSet.last(); |
215 |
< |
}, description); |
209 |
> |
assertThrowsNSEE(navigableSet::last, description); |
210 |
|
} |
211 |
|
|
212 |
|
/** |
271 |
|
Object last = (BigInteger.ZERO == first) ? BigInteger.TEN : BigInteger.ZERO; |
272 |
|
|
273 |
|
assertThrowsIAE( |
274 |
< |
() -> { |
281 |
< |
navigableSet.subSet(last, true, first, false); |
282 |
< |
}, |
274 |
> |
() -> navigableSet.subSet(last, true, first, false), |
275 |
|
description |
276 |
|
+ ": Must throw IllegalArgumentException when fromElement is not less than toElement."); |
277 |
|
|
291 |
|
// slightly smaller |
292 |
|
NavigableSet ns = subSet.subSet(first, false, last, false); |
293 |
|
// slight expansion |
294 |
< |
assertThrowsIAE(() -> { |
295 |
< |
ns.subSet(first, true, last, true); |
304 |
< |
}, |
294 |
> |
assertThrowsIAE( |
295 |
> |
() -> ns.subSet(first, true, last, true), |
296 |
|
description + ": Expansion should not be allowed"); |
297 |
|
|
298 |
|
// much smaller |
310 |
|
NavigableSet ns = subSet.headSet(BigInteger.ONE, false); |
311 |
|
|
312 |
|
// slight expansion |
313 |
< |
assertThrowsIAE(() -> { |
314 |
< |
ns.headSet(BigInteger.ONE, true); |
324 |
< |
}, |
313 |
> |
assertThrowsIAE( |
314 |
> |
() -> ns.headSet(BigInteger.ONE, true), |
315 |
|
description + ": Expansion should not be allowed"); |
316 |
|
|
317 |
|
// much smaller |
329 |
|
NavigableSet ns = subSet.tailSet(BigInteger.ONE, false); |
330 |
|
|
331 |
|
// slight expansion |
332 |
< |
assertThrowsIAE(() -> { |
333 |
< |
ns.tailSet(BigInteger.ONE, true); |
344 |
< |
}, |
332 |
> |
assertThrowsIAE( |
333 |
> |
() -> ns.tailSet(BigInteger.ONE, true), |
334 |
|
description + ": Expansion should not be allowed"); |
335 |
|
|
336 |
|
// much smaller |
342 |
|
*/ |
343 |
|
@Test(dataProvider = "NavigableSet<?>", dataProviderClass = EmptyNavigableSet.class) |
344 |
|
public void testTailSet(String description, NavigableSet navigableSet) { |
345 |
< |
assertThrowsNPE(() -> { |
346 |
< |
navigableSet.tailSet(null); |
358 |
< |
}, |
345 |
> |
assertThrowsNPE( |
346 |
> |
() -> navigableSet.tailSet(null), |
347 |
|
description + ": Must throw NullPointerException for null element"); |
348 |
|
|
349 |
< |
assertThrowsCCE(() -> { |
350 |
< |
navigableSet.tailSet(new Object()); |
351 |
< |
}, description); |
349 |
> |
assertThrowsCCE( |
350 |
> |
() -> navigableSet.tailSet(new Object()), |
351 |
> |
description); |
352 |
|
|
353 |
|
NavigableSet ss = navigableSet.tailSet("1", true); |
354 |
|
|
370 |
|
|
371 |
|
assertSame(emptyNavigableSetArray, result); |
372 |
|
|
373 |
< |
assertTrue(result[0] == null); |
373 |
> |
assertNull(result[0]); |
374 |
|
} |
375 |
|
|
376 |
|
@DataProvider(name = "NavigableSet<?>", parallel = true) |