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.assertSame; |
49 |
|
import static org.testng.Assert.assertTrue; |
131 |
|
*/ |
132 |
|
@Test(dataProvider = "NavigableSet<?>", dataProviderClass = EmptyNavigableSet.class) |
133 |
|
public void testContainsRequiresComparable(String description, NavigableSet<?> navigableSet) { |
134 |
< |
assertThrowsCCE(() -> { |
135 |
< |
navigableSet.contains(new Object()); |
136 |
< |
}, |
136 |
< |
description + ": Compareable should be required"); |
134 |
> |
assertThrowsCCE( |
135 |
> |
() -> navigableSet.contains(new Object()), |
136 |
> |
description + ": Comparable should be required"); |
137 |
|
} |
138 |
|
|
139 |
|
/** |
163 |
|
*/ |
164 |
|
@Test(dataProvider = "NavigableSet<?>", dataProviderClass = EmptyNavigableSet.class) |
165 |
|
public void testEmptyIterator(String description, NavigableSet<?> navigableSet) { |
166 |
< |
Iterator emptyIterator = navigableSet.iterator(); |
167 |
< |
|
168 |
< |
assertFalse((emptyIterator != null) && (emptyIterator.hasNext()), |
169 |
< |
"The iterator is not empty."); |
166 |
> |
assertFalse(navigableSet.iterator().hasNext(), "The iterator is not empty."); |
167 |
|
} |
168 |
|
|
169 |
|
/** |
270 |
|
Object last = (BigInteger.ZERO == first) ? BigInteger.TEN : BigInteger.ZERO; |
271 |
|
|
272 |
|
assertThrowsIAE( |
273 |
< |
() -> { |
277 |
< |
navigableSet.subSet(last, true, first, false); |
278 |
< |
}, |
273 |
> |
() -> navigableSet.subSet(last, true, first, false), |
274 |
|
description |
275 |
|
+ ": Must throw IllegalArgumentException when fromElement is not less than toElement."); |
276 |
|
|
290 |
|
// slightly smaller |
291 |
|
NavigableSet ns = subSet.subSet(first, false, last, false); |
292 |
|
// slight expansion |
293 |
< |
assertThrowsIAE(() -> { |
294 |
< |
ns.subSet(first, true, last, true); |
300 |
< |
}, |
293 |
> |
assertThrowsIAE( |
294 |
> |
() -> ns.subSet(first, true, last, true), |
295 |
|
description + ": Expansion should not be allowed"); |
296 |
|
|
297 |
|
// much smaller |
309 |
|
NavigableSet ns = subSet.headSet(BigInteger.ONE, false); |
310 |
|
|
311 |
|
// slight expansion |
312 |
< |
assertThrowsIAE(() -> { |
313 |
< |
ns.headSet(BigInteger.ONE, true); |
320 |
< |
}, |
312 |
> |
assertThrowsIAE( |
313 |
> |
() -> ns.headSet(BigInteger.ONE, true), |
314 |
|
description + ": Expansion should not be allowed"); |
315 |
|
|
316 |
|
// much smaller |
328 |
|
NavigableSet ns = subSet.tailSet(BigInteger.ONE, false); |
329 |
|
|
330 |
|
// slight expansion |
331 |
< |
assertThrowsIAE(() -> { |
332 |
< |
ns.tailSet(BigInteger.ONE, true); |
340 |
< |
}, |
331 |
> |
assertThrowsIAE( |
332 |
> |
() -> ns.tailSet(BigInteger.ONE, true), |
333 |
|
description + ": Expansion should not be allowed"); |
334 |
|
|
335 |
|
// much smaller |
341 |
|
*/ |
342 |
|
@Test(dataProvider = "NavigableSet<?>", dataProviderClass = EmptyNavigableSet.class) |
343 |
|
public void testTailSet(String description, NavigableSet navigableSet) { |
344 |
< |
assertThrowsNPE(() -> { |
345 |
< |
navigableSet.tailSet(null); |
354 |
< |
}, |
344 |
> |
assertThrowsNPE( |
345 |
> |
() -> navigableSet.tailSet(null), |
346 |
|
description + ": Must throw NullPointerException for null element"); |
347 |
|
|
348 |
< |
assertThrowsCCE(() -> { |
349 |
< |
navigableSet.tailSet(new Object()); |
350 |
< |
}, description); |
348 |
> |
assertThrowsCCE( |
349 |
> |
() -> navigableSet.tailSet(new Object()), |
350 |
> |
description); |
351 |
|
|
352 |
|
NavigableSet ss = navigableSet.tailSet("1", true); |
353 |
|
|
369 |
|
|
370 |
|
assertSame(emptyNavigableSetArray, result); |
371 |
|
|
372 |
< |
assertTrue(result[0] == null); |
372 |
> |
assertNull(result[0]); |
373 |
|
} |
374 |
|
|
375 |
|
@DataProvider(name = "NavigableSet<?>", parallel = true) |