ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/jtreg/util/Collections/EmptyNavigableSet.java
(Generate patch)

Comparing jsr166/src/test/jtreg/util/Collections/EmptyNavigableSet.java (file contents):
Revision 1.6 by jsr166, Mon May 15 21:39:24 2017 UTC vs.
Revision 1.14 by jsr166, Mon Jul 23 01:11:22 2018 UTC

# Line 27 | Line 27
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) {
# Line 130 | Line 132 | public class EmptyNavigableSet {
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      /**
# Line 163 | Line 164 | public class EmptyNavigableSet {
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      /**
# Line 182 | Line 180 | public class EmptyNavigableSet {
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      /**
# Line 210 | Line 206 | public class EmptyNavigableSet {
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      /**
# Line 277 | Line 271 | public class EmptyNavigableSet {
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  
# Line 299 | Line 291 | public class EmptyNavigableSet {
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
# Line 319 | Line 310 | public class EmptyNavigableSet {
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
# Line 339 | Line 329 | public class EmptyNavigableSet {
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
# Line 353 | Line 342 | public class EmptyNavigableSet {
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  
# Line 382 | Line 370 | public class EmptyNavigableSet {
370  
371          assertSame(emptyNavigableSetArray, result);
372  
373 <        assertTrue(result[0] == null);
373 >        assertNull(result[0]);
374      }
375  
376      @DataProvider(name = "NavigableSet<?>", parallel = true)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines