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 |
|
/** |
182 |
|
*/ |
183 |
|
@Test(dataProvider = "NavigableSet<?>", dataProviderClass = EmptyNavigableSet.class) |
184 |
|
public void testFirst(String description, NavigableSet<?> navigableSet) { |
185 |
< |
assertThrowsNSEE(() -> { |
186 |
< |
navigableSet.first(); |
187 |
< |
}, description); |
185 |
> |
assertThrowsNSEE(navigableSet::first, description); |
186 |
|
} |
187 |
|
|
188 |
|
/** |
208 |
|
*/ |
209 |
|
@Test(dataProvider = "NavigableSet<?>", dataProviderClass = EmptyNavigableSet.class) |
210 |
|
public void testLast(String description, NavigableSet<?> navigableSet) { |
211 |
< |
assertThrowsNSEE(() -> { |
214 |
< |
navigableSet.last(); |
215 |
< |
}, description); |
211 |
> |
assertThrowsNSEE(navigableSet::last, description); |
212 |
|
} |
213 |
|
|
214 |
|
/** |
273 |
|
Object last = (BigInteger.ZERO == first) ? BigInteger.TEN : BigInteger.ZERO; |
274 |
|
|
275 |
|
assertThrowsIAE( |
276 |
< |
() -> { |
281 |
< |
navigableSet.subSet(last, true, first, false); |
282 |
< |
}, |
276 |
> |
() -> navigableSet.subSet(last, true, first, false), |
277 |
|
description |
278 |
|
+ ": Must throw IllegalArgumentException when fromElement is not less than toElement."); |
279 |
|
|
293 |
|
// slightly smaller |
294 |
|
NavigableSet ns = subSet.subSet(first, false, last, false); |
295 |
|
// slight expansion |
296 |
< |
assertThrowsIAE(() -> { |
297 |
< |
ns.subSet(first, true, last, true); |
304 |
< |
}, |
296 |
> |
assertThrowsIAE( |
297 |
> |
() -> ns.subSet(first, true, last, true), |
298 |
|
description + ": Expansion should not be allowed"); |
299 |
|
|
300 |
|
// much smaller |
312 |
|
NavigableSet ns = subSet.headSet(BigInteger.ONE, false); |
313 |
|
|
314 |
|
// slight expansion |
315 |
< |
assertThrowsIAE(() -> { |
316 |
< |
ns.headSet(BigInteger.ONE, true); |
324 |
< |
}, |
315 |
> |
assertThrowsIAE( |
316 |
> |
() -> ns.headSet(BigInteger.ONE, true), |
317 |
|
description + ": Expansion should not be allowed"); |
318 |
|
|
319 |
|
// much smaller |
331 |
|
NavigableSet ns = subSet.tailSet(BigInteger.ONE, false); |
332 |
|
|
333 |
|
// slight expansion |
334 |
< |
assertThrowsIAE(() -> { |
335 |
< |
ns.tailSet(BigInteger.ONE, true); |
344 |
< |
}, |
334 |
> |
assertThrowsIAE( |
335 |
> |
() -> ns.tailSet(BigInteger.ONE, true), |
336 |
|
description + ": Expansion should not be allowed"); |
337 |
|
|
338 |
|
// much smaller |
344 |
|
*/ |
345 |
|
@Test(dataProvider = "NavigableSet<?>", dataProviderClass = EmptyNavigableSet.class) |
346 |
|
public void testTailSet(String description, NavigableSet navigableSet) { |
347 |
< |
assertThrowsNPE(() -> { |
348 |
< |
navigableSet.tailSet(null); |
358 |
< |
}, |
347 |
> |
assertThrowsNPE( |
348 |
> |
() -> navigableSet.tailSet(null), |
349 |
|
description + ": Must throw NullPointerException for null element"); |
350 |
|
|
351 |
< |
assertThrowsCCE(() -> { |
352 |
< |
navigableSet.tailSet(new Object()); |
353 |
< |
}, description); |
351 |
> |
assertThrowsCCE( |
352 |
> |
() -> navigableSet.tailSet(new Object()), |
353 |
> |
description); |
354 |
|
|
355 |
|
NavigableSet ss = navigableSet.tailSet("1", true); |
356 |
|
|