test/java/util/Collections/EmptyNavigableSet.java

Print this page
rev 7291 : 7129185: Add Collections.{checked|empty|unmodifiable}Navigable{Map|Set}
Reviewed-by: dmocek
   1 /*
   2  * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /*
  25  * @test
  26  * @bug 4533691
  27  * @summary Unit test for Collections.emptySortedSet

  28  */
  29 
  30 import java.lang.reflect.Method;
  31 import java.math.BigInteger;


  32 import java.util.Collections;
  33 import java.util.Comparator;
  34 import java.util.Iterator;
  35 import java.util.NoSuchElementException;

  36 import java.util.SortedSet;
  37 import java.util.TreeSet;


  38 
  39 public class EmptySortedSet {
  40     static int status = 0;
  41     private static final String FAILED = " failed. ";
  42     private static final String PERIOD = ".";
  43     private final String thisClassName = this.getClass().getName();
  44 
  45     public static void main(String[] args) throws Exception {
  46         new EmptySortedSet();
  47     }
  48 
  49     public EmptySortedSet() throws Exception {
  50         run();
  51     }
  52 
  53     /**
  54      * Returns {@code true} if the {@link Object} passed in is an empty
  55      * {@link SortedSet}.
  56      *
  57      * @param obj the object to test
  58      * @return {@code true} if the {@link Object} is an empty {@link SortedSet}
  59      *         otherwise {@code false}.
  60      */
  61     private boolean isEmptySortedSet(Object obj) {
  62         boolean isEmptySortedSet = false;
  63 
  64         // We determine if the object is an empty sorted set by testing if it's
  65         // an instance of SortedSet, and if so, if it's empty.  Currently the
  66         // testing doesn't include checks of the other methods.
  67         if (obj instanceof SortedSet) {
  68             SortedSet ss = (SortedSet) obj;
  69 
  70             if ((ss.isEmpty()) && (ss.size() == 0)) {
  71                 isEmptySortedSet = true;
  72             }




  73         }
  74 
  75         return isEmptySortedSet;



  76     }
  77 
  78     private void run() throws Exception {
  79         Method[] methods = this.getClass().getDeclaredMethods();
  80 
  81         for (int i = 0; i < methods.length; i++) {
  82             Method method = methods[i];
  83             String methodName = method.getName();
  84 
  85             if (methodName.startsWith("test")) {





  86                 try {
  87                     Object obj = method.invoke(this, new Object[0]);
  88                 } catch(Exception e) {
  89                     throw new Exception(this.getClass().getName() + "." +
  90                             methodName + " test failed, test exception "
  91                             + "follows\n" + e.getCause());
  92                 }


  93             }





  94         }




  95     }
  96 
  97     private void throwException(String methodName, String reason)
  98             throws Exception
  99     {
 100         StringBuilder sb = new StringBuilder(thisClassName);
 101         sb.append(PERIOD);
 102         sb.append(methodName);
 103         sb.append(FAILED);
 104         sb.append(reason);
 105         throw new Exception(sb.toString());
 106     }
 107 
 108     /**
 109      *
 110      */
 111     private void test00() throws Exception {
 112         //throwException("test00", "This test has not been implemented yet.");
 113     }
 114 
 115     /**
 116      * Tests that the comparator is {@code null}.
 117      */
 118     private void testComparatorIsNull() throws Exception {
 119         SortedSet sortedSet = Collections.emptySortedSet();
 120         Comparator comparator = sortedSet.comparator();
 121 
 122         if (comparator != null) {
 123             throwException("testComparatorIsNull", "Comparator is not null.");
 124         }











 125     }
 126 
 127     /**
 128      * Tests that the contains method returns {@code false}.
 129      */
 130     private void testContains() throws Exception {
 131         SortedSet sortedSet = Collections.emptySortedSet();
 132 
 133         if (sortedSet.contains(new Object())) {
 134             throwException("testContains", "Should not contain any elements.");
 135         }
 136     }
 137 
 138     /**
 139      * Tests that the containsAll method returns {@code false}.
 140      */
 141     private void testContainsAll() throws Exception {
 142         SortedSet sortedSet = Collections.emptySortedSet();
 143         TreeSet treeSet = new TreeSet();
 144         treeSet.add("1");
 145         treeSet.add("2");
 146         treeSet.add("3");
 147 
 148         if (sortedSet.containsAll(treeSet)) {
 149             throwException("testContainsAll",
 150                     "Should not contain any elements.");
 151         }
 152     }
 153 
 154     /**
 155      * Tests that the iterator is empty.
 156      */
 157     private void testEmptyIterator() throws Exception {
 158         SortedSet sortedSet = Collections.emptySortedSet();
 159         Iterator emptyIterator = sortedSet.iterator();
 160 
 161         if ((emptyIterator != null) && (emptyIterator.hasNext())) {
 162             throwException("testEmptyIterator", "The iterator is not empty.");
 163         }
 164     }
 165 
 166     /**
 167      * Tests that the set is empty.
 168      */
 169     private void testIsEmpty() throws Exception {
 170         SortedSet sortedSet = Collections.emptySortedSet();
 171 
 172         if ((sortedSet != null) && (!sortedSet.isEmpty())) {
 173             throwException("testSizeIsZero", "The set is not empty.");
 174         }
 175     }
 176 
 177     /**
 178      * Tests that the first() method throws NoSuchElementException
 179      */
 180     private void testFirst() throws Exception {
 181         SortedSet sortedSet = Collections.emptySortedSet();
 182 
 183         try {
 184             sortedSet.first();
 185             throwException("testFirst",
 186                     "NoSuchElemenException was not thrown.");
 187         } catch(NoSuchElementException nsee) {
 188             // Do nothing
 189         }
 190     }
 191 
 192     /**
 193      * Tests the headSet() method.
 194      */
 195     private void testHeadSet() throws Exception {
 196         SortedSet sortedSet = Collections.emptySortedSet();
 197         SortedSet ss;
 198 
 199         try {
 200             ss = sortedSet.headSet(null);
 201             throwException("testHeadSet",
 202                     "Must throw NullPointerException for null element");
 203         } catch(NullPointerException npe) {
 204             // Do nothing
 205         }
 206 
 207         try {
 208             ss = sortedSet.headSet(new Object());
 209             throwException("testHeadSet",
 210                     "Must throw ClassCastException for non-Comparable element");
 211         } catch(ClassCastException cce) {
 212             // Do nothing.
 213         }
 214 
 215         ss = sortedSet.headSet("1");
 216 
 217         if ((ss == null) || !isEmptySortedSet(ss)) {
 218             throwException("testHeadSet",
 219                     "Returned value is null or not an EmptySortedSet.");
 220         }
 221     }
 222 
 223     /**
 224      * Tests that the last() method throws NoSuchElementException
 225      */
 226     private void testLast() throws Exception {
 227         SortedSet sortedSet = Collections.emptySortedSet();
 228 
 229         try {
 230             sortedSet.last();
 231             throwException("testLast",
 232                     "NoSuchElemenException was not thrown.");
 233         } catch(NoSuchElementException nsee) {
 234             // Do nothing
 235         }
 236     }
 237 
 238     /**
 239      * Tests that the size is 0.
 240      */
 241     private void testSizeIsZero() throws Exception {
 242         SortedSet sortedSet = Collections.emptySortedSet();
 243         int size = sortedSet.size();
 244 
 245         if (size > 0) {
 246             throwException("testSizeIsZero",
 247                     "The size of the set is greater then 0.");
 248         }
 249     }
 250 
 251     /**
 252      * Tests the subSet() method.
 253      */
 254     private void testSubSet() throws Exception {
 255         SortedSet sortedSet = Collections.emptySortedSet();
 256         SortedSet ss = sortedSet.headSet("1");



















 257 
 258         try {
 259             ss = sortedSet.subSet(null, BigInteger.TEN);
 260             ss = sortedSet.subSet(BigInteger.ZERO, null);
 261             ss = sortedSet.subSet(null, null);
 262             throwException("testSubSet",
 263                     "Must throw NullPointerException for null element");
 264         } catch(NullPointerException npe) {
 265             // Do nothing
 266         }
 267 
 268         try {
 269             Object obj1 = new Object();
 270             Object obj2 = new Object();
 271             ss = sortedSet.subSet(obj1, BigInteger.TEN);
 272             ss = sortedSet.subSet(BigInteger.ZERO, obj2);
 273             ss = sortedSet.subSet(obj1, obj2);
 274             throwException("testSubSet",
 275                     "Must throw ClassCastException for parameter which is "
 276                     + "not Comparable.");
 277         } catch(ClassCastException cce) {
 278             // Do nothing.
 279         }
 280 
 281         try {
 282             ss = sortedSet.subSet(BigInteger.ZERO, BigInteger.ZERO);
 283             ss = sortedSet.subSet(BigInteger.TEN, BigInteger.ZERO);
 284             throwException("testSubSet",
 285                     "Must throw IllegalArgumentException when fromElement is "
 286                     + "not less then then toElement.");
 287         } catch(IllegalArgumentException iae) {
 288             // Do nothing.
 289         }
 290 
 291         ss = sortedSet.subSet(BigInteger.ZERO, BigInteger.TEN);

































































































 292 
 293         if (!isEmptySortedSet(ss)) {
 294             throw new Exception("Returned value is not empty sorted set.");
 295         }
 296     }
 297 
 298     /**
 299      * Tests the tailSet() method.
 300      */
 301     private void testTailSet() throws Exception {
 302         SortedSet sortedSet = Collections.emptySortedSet();
 303         SortedSet ss;








 304 
 305         try {
 306             ss = sortedSet.tailSet(null);
 307             throwException("testTailSet",
 308                     "Must throw NullPointerException for null element");
 309         } catch(NullPointerException npe) {
 310             // Do nothing
 311         }
 312 
 313         try {
 314             SortedSet ss2 = sortedSet.tailSet(new Object());
 315             throwException("testTailSet",
 316                     "Must throw ClassCastException for non-Comparable element");
 317         } catch(ClassCastException cce) {
 318             // Do nothing.
 319         }
 320 
 321         ss = sortedSet.tailSet("1");
 322 
 323         if ((ss == null) || !isEmptySortedSet(ss)) {
 324             throwException("testTailSet",
 325                     "Returned value is null or not an EmptySortedSet.");
 326         }
 327     }
 328 
 329     /**
 330      * Tests that the array has a size of 0.
 331      */
 332     private void testToArray() throws Exception {
 333         SortedSet sortedSet = Collections.emptySortedSet();
 334         Object[] emptySortedSetArray = sortedSet.toArray();
 335 
 336         if ((emptySortedSetArray == null) || (emptySortedSetArray.length > 0)) {
 337             throwException("testToArray",
 338                     "Returned null array or array with length > 0.");
 339         }
 340 
 341         String[] strings = new String[2];
 342         strings[0] = "1";
 343         strings[1] = "2";
 344         emptySortedSetArray = sortedSet.toArray(strings);
 345 
 346         if ((emptySortedSetArray == null) || (emptySortedSetArray[0] != null)) {
 347             throwException("testToArray",
 348                     "Returned null array or array with length > 0.");

 349         }










 350     }
 351 }
   1 /*
   2  * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /*
  25  * @test
  26  * @bug 4533691 7129185
  27  * @summary Unit test for Collections.emptyNavigableSet
  28  * @run testng EmptyNavigableSet
  29  */


  30 import java.math.BigInteger;
  31 import java.util.Arrays;
  32 import java.util.Collection;
  33 import java.util.Collections;
  34 import java.util.Comparator;
  35 import java.util.Iterator;
  36 import java.util.NoSuchElementException;
  37 import java.util.NavigableSet;
  38 import java.util.SortedSet;
  39 import java.util.TreeSet;
  40 import org.testng.annotations.Test;
  41 import org.testng.annotations.DataProvider;
  42 
  43 import static org.testng.Assert.fail;
  44 import static org.testng.Assert.assertEquals;
  45 import static org.testng.Assert.assertTrue;
  46 import static org.testng.Assert.assertFalse;
  47 import static org.testng.Assert.assertSame;
  48 
  49 public class EmptyNavigableSet {


  50 
  51     public static <T> void assertInstance(T actual, Class<? extends T> expected) {
  52         assertInstance(expected.isInstance(actual), null);
  53     }
  54 
  55     public static <T> void assertInstance(T actual, Class<? extends T> expected, String message) {
  56         assertTrue(expected.isInstance(actual), ((null != message) ? message : "")
  57             + " " + (actual == null ? "<null>" : actual.getClass().getSimpleName()) + " != " + expected.getSimpleName() + ". ");
















  58     }
  59 
  60     public static <T extends Throwable> void assertEmptyNavigableSet(Object obj) {
  61         assertInstance(obj, NavigableSet.class);
  62         assertTrue(((NavigableSet)obj).isEmpty() && (((NavigableSet)obj).size() == 0));
  63     }
  64 
  65     public static <T extends Throwable> void assertEmptyNavigableSet(Object obj, String message) {
  66         assertInstance(obj, NavigableSet.class, message);
  67         assertTrue(((NavigableSet)obj).isEmpty() && (((NavigableSet)obj).size() == 0),
  68             ((null != message) ? message : "") + " Not empty. ");
  69     }
  70 
  71     public interface Thrower<T extends Throwable> {

  72 
  73         public void run() throws T;
  74     }

  75 
  76     public static <T extends Throwable> void assertThrows(Thrower<T> thrower, Class<T> throwable) {
  77         assertThrows(thrower, throwable, null);
  78     }
  79 
  80     public static <T extends Throwable> void assertThrows(Thrower<T> thrower, Class<T> throwable, String message) {
  81         Throwable result;
  82         try {
  83             thrower.run();
  84             fail(((null != message) ? message : "") + "Failed to throw " + throwable.getCanonicalName() + ". ");
  85             return;
  86         } catch (Throwable caught) {
  87             result = caught;
  88         }
  89 
  90         assertInstance(result, throwable, ((null != message) ? message : "") + "Failed to throw " + throwable.getCanonicalName() + ". ");
  91     }
  92 
  93     public static final boolean isDescending(SortedSet<?> set) {
  94         if (null == set.comparator()) {
  95             // natural order
  96             return false;
  97         }
  98 
  99         if (Collections.reverseOrder() == set.comparator()) {
 100             // reverse natural order.
 101             return true;
 102         }
 103 
 104         if (set.comparator().equals(Collections.reverseOrder(Collections.reverseOrder(set.comparator())))) {
 105             // it's a Collections.reverseOrder(Comparator).
 106             return true;






 107         }
 108 
 109         throw new IllegalStateException("can't determine ordering for " + set);




 110     }
 111 
 112     /**
 113      * Tests that the comparator is {@code null}.
 114      */
 115     @Test(dataProvider = "NavigableSet<?>", dataProviderClass = EmptyNavigableSet.class)
 116     public void testComparatorIsNull(String description, NavigableSet<?> navigableSet) {
 117         Comparator comparator = navigableSet.comparator();
 118 
 119         assertTrue(comparator == null || comparator == Collections.reverseOrder(), description + ": Comparator (" + comparator + ") is not null.");

 120     }
 121 
 122     /**
 123      * Tests that contains requires Comparable
 124      */
 125     @Test(dataProvider = "NavigableSet<?>", dataProviderClass = EmptyNavigableSet.class)
 126     public void testContainsRequiresComparable(String description, NavigableSet<?> navigableSet) {
 127         assertThrows(() -> {
 128             navigableSet.contains(new Object());
 129         },
 130             ClassCastException.class,
 131             description + ": Compareable should be required");
 132     }
 133 
 134     /**
 135      * Tests that the contains method returns {@code false}.
 136      */
 137     @Test(dataProvider = "NavigableSet<?>", dataProviderClass = EmptyNavigableSet.class)
 138     public void testContains(String description, NavigableSet<?> navigableSet) {
 139         assertFalse(navigableSet.contains(new Integer(1)),
 140             description + ": Should not contain any elements.");


 141     }
 142 
 143     /**
 144      * Tests that the containsAll method returns {@code false}.
 145      */
 146     @Test(dataProvider = "NavigableSet<?>", dataProviderClass = EmptyNavigableSet.class)
 147     public void testContainsAll(String description, NavigableSet<?> navigableSet) {
 148         TreeSet treeSet = new TreeSet();
 149         treeSet.add("1");
 150         treeSet.add("2");
 151         treeSet.add("3");
 152 
 153         assertFalse(navigableSet.containsAll(treeSet), "Should not contain any elements.");



 154     }
 155 
 156     /**
 157      * Tests that the iterator is empty.
 158      */
 159     @Test(dataProvider = "NavigableSet<?>", dataProviderClass = EmptyNavigableSet.class)
 160     public void testEmptyIterator(String description, NavigableSet<?> navigableSet) {
 161         Iterator emptyIterator = navigableSet.iterator();
 162 
 163         assertFalse((emptyIterator != null) && (emptyIterator.hasNext()),
 164             "The iterator is not empty.");

 165     }
 166 
 167     /**
 168      * Tests that the set is empty.
 169      */
 170     @Test(dataProvider = "NavigableSet<?>", dataProviderClass = EmptyNavigableSet.class)
 171     public void testIsEmpty(String description, NavigableSet<?> navigableSet) {
 172         assertTrue(navigableSet.isEmpty(), "The set is not empty.");



 173     }
 174 
 175     /**
 176      * Tests that the first() method throws NoSuchElementException
 177      */
 178     @Test(dataProvider = "NavigableSet<?>", dataProviderClass = EmptyNavigableSet.class)
 179     public void testFirst(String description, NavigableSet<?> navigableSet) {
 180         assertThrows(() -> {
 181             navigableSet.first();
 182         }, NoSuchElementException.class, description);





 183     }
 184 
 185     /**
 186      * Tests the headSet() method.
 187      */
 188     @Test(dataProvider = "NavigableSet<?>", dataProviderClass = EmptyNavigableSet.class)
 189     public void testHeadSet(String description, NavigableSet navigableSet) {
 190         SortedSet ss;
 191 
 192         try {
 193             ss = navigableSet.headSet(null);
 194             fail(description + ": Must throw NullPointerException for null element");
 195         } catch (NullPointerException npe) {

 196             // Do nothing
 197         }
 198 
 199         try {
 200             ss = navigableSet.headSet(new Object());
 201             fail(description + ": Must throw ClassCastException for non-Comparable element");
 202         } catch (ClassCastException cce) {

 203             // Do nothing.
 204         }
 205 
 206         ss = navigableSet.headSet("1", false);
 207 
 208         assertEmptyNavigableSet(ss, description + ": Returned value is not empty navigable set.");



 209     }
 210 
 211     /**
 212      * Tests that the last() method throws NoSuchElementException
 213      */
 214     @Test(dataProvider = "NavigableSet<?>", dataProviderClass = EmptyNavigableSet.class)
 215     public void testLast(String description, NavigableSet<?> navigableSet) {
 216         assertThrows(() -> {
 217             navigableSet.last();
 218         }, NoSuchElementException.class, description);





 219     }
 220 
 221     /**
 222      * Tests that the size is 0.
 223      */
 224     @Test(dataProvider = "NavigableSet<?>", dataProviderClass = EmptyNavigableSet.class)
 225     public void testSizeIsZero(String description, NavigableSet<?> navigableSet) {
 226         assertTrue(0 == navigableSet.size(), "The size of the set is not 0.");





 227     }
 228 
 229     /**
 230      * Tests the subSet() method.
 231      */
 232     @Test(dataProvider = "NavigableSet<?>", dataProviderClass = EmptyNavigableSet.class)
 233     public void testSubSet(String description, NavigableSet navigableSet) {
 234         assertThrows(
 235             () -> {
 236                 SortedSet ss = navigableSet.subSet(null, BigInteger.TEN);
 237             },
 238             NullPointerException.class,
 239             description + ": Must throw NullPointerException for null element");
 240 
 241         assertThrows(
 242             () -> {
 243                 SortedSet ss = navigableSet.subSet(BigInteger.ZERO, null);
 244             },
 245             NullPointerException.class,
 246             description + ": Must throw NullPointerException for null element");
 247 
 248         assertThrows(
 249             () -> {
 250                 SortedSet ss = navigableSet.subSet(null, null);
 251             },
 252             NullPointerException.class,
 253             description + ": Must throw NullPointerException for null element");
 254 











 255         Object obj1 = new Object();
 256         Object obj2 = new Object();



















 257 
 258         assertThrows(
 259             () -> {
 260                 SortedSet ss = navigableSet.subSet(obj1, BigInteger.TEN);
 261             },
 262             ClassCastException.class, description
 263             + ": Must throw ClassCastException for parameter which is not Comparable.");
 264 
 265         assertThrows(
 266             () -> {
 267                 SortedSet ss = navigableSet.subSet(BigInteger.ZERO, obj2);
 268             },
 269             ClassCastException.class, description
 270             + ": Must throw ClassCastException for parameter which is not Comparable.");
 271 
 272         assertThrows(
 273             () -> {
 274                 SortedSet ss = navigableSet.subSet(obj1, obj2);
 275             },
 276             ClassCastException.class, description
 277             + ": Must throw ClassCastException for parameter which is not Comparable.");
 278 
 279         // minimal range
 280         navigableSet.subSet(BigInteger.ZERO, false, BigInteger.ZERO, false);
 281         navigableSet.subSet(BigInteger.ZERO, false, BigInteger.ZERO, true);
 282         navigableSet.subSet(BigInteger.ZERO, true, BigInteger.ZERO, false);
 283         navigableSet.subSet(BigInteger.ZERO, true, BigInteger.ZERO, true);
 284 
 285         Object first = isDescending(navigableSet) ? BigInteger.TEN : BigInteger.ZERO;
 286         Object last = (BigInteger.ZERO == first) ? BigInteger.TEN : BigInteger.ZERO;
 287 
 288             assertThrows(
 289                 () -> {
 290                     navigableSet.subSet(last, true, first, false);
 291                 },
 292                 IllegalArgumentException.class, description
 293                 + ": Must throw IllegalArgumentException when fromElement is not less then then toElement.");
 294 
 295         navigableSet.subSet(first, true, last, false);
 296     }
 297 
 298     @Test(dataProvider = "NavigableSet<?>", dataProviderClass = EmptyNavigableSet.class)
 299     public void testSubSetRanges(String description, NavigableSet navigableSet) {
 300         Object first = isDescending(navigableSet) ? BigInteger.TEN : BigInteger.ZERO;
 301         Object last = (BigInteger.ZERO == first) ? BigInteger.TEN : BigInteger.ZERO;
 302 
 303         NavigableSet subSet = navigableSet.subSet(first, true, last, true);
 304 
 305         // same subset
 306         subSet.subSet(first, true, last, true);
 307 
 308         // slightly smaller
 309         NavigableSet ns = subSet.subSet(first, false, last, false);
 310         // slight exapansion
 311         assertThrows(() -> {
 312             ns.subSet(first, true, last, true);
 313         },
 314             IllegalArgumentException.class,
 315             description + ": Expansion should not be allowed");
 316 
 317         // much smaller
 318         subSet.subSet(first, false, BigInteger.ONE, false);
 319     }
 320 
 321     @Test(dataProvider = "NavigableSet<?>", dataProviderClass = EmptyNavigableSet.class)
 322     public void testheadSetRanges(String description, NavigableSet navigableSet) {
 323         NavigableSet subSet = navigableSet.headSet(BigInteger.ONE, true);
 324 
 325         // same subset
 326         subSet.headSet(BigInteger.ONE, true);
 327 
 328         // slightly smaller
 329         NavigableSet ns = subSet.headSet(BigInteger.ONE, false);
 330         // slight exapansion
 331         assertThrows(() -> {
 332             ns.headSet(BigInteger.ONE, true);
 333         },
 334             IllegalArgumentException.class,
 335             description + ": Expansion should not be allowed");
 336 
 337         // much smaller
 338         subSet.headSet(isDescending(subSet) ? BigInteger.TEN : BigInteger.ZERO, true);
 339     }
 340 
 341     @Test(dataProvider = "NavigableSet<?>", dataProviderClass = EmptyNavigableSet.class)
 342     public void testTailSetRanges(String description, NavigableSet navigableSet) {
 343         NavigableSet subSet = navigableSet.tailSet(BigInteger.ONE, true);
 344 
 345         // same subset
 346         subSet.tailSet(BigInteger.ONE, true);
 347 
 348         // slightly smaller
 349         NavigableSet ns = subSet.tailSet(BigInteger.ONE, false);
 350         // slight exapansion
 351         assertThrows(() -> {
 352             ns.tailSet(BigInteger.ONE, true);
 353         },
 354             IllegalArgumentException.class,
 355             description + ": Expansion should not be allowed");
 356 
 357         // much smaller
 358         subSet.tailSet(isDescending(subSet) ? BigInteger.ZERO : BigInteger.TEN, false);

 359     }
 360 
 361     /**
 362      * Tests the tailSet() method.
 363      */
 364     @Test(dataProvider = "NavigableSet<?>", dataProviderClass = EmptyNavigableSet.class)
 365     public void testTailSet(String description, NavigableSet navigableSet) {
 366         assertThrows(() -> {
 367             navigableSet.tailSet(null);
 368         },
 369             NullPointerException.class,
 370             description + ": Must throw NullPointerException for null element");
 371 
 372         assertThrows(() -> {
 373             navigableSet.tailSet(new Object());
 374         }, ClassCastException.class);
 375 
 376         NavigableSet ss = navigableSet.tailSet("1", true);














 377 
 378         assertEmptyNavigableSet(ss, description + ": Returned value is not empty navigable set.");





 379     }
 380 
 381     /**
 382      * Tests that the array has a size of 0.
 383      */
 384     @Test(dataProvider = "NavigableSet<?>", dataProviderClass = EmptyNavigableSet.class)
 385     public void testToArray(String description, NavigableSet<?> navigableSet) {
 386         Object[] emptyNavigableSetArray = navigableSet.toArray();
 387 
 388         assertTrue(emptyNavigableSetArray.length == 0, "Returned non-empty Array.");
 389 
 390         emptyNavigableSetArray = new Object[20];
 391 
 392         Object[] result = navigableSet.toArray(emptyNavigableSetArray);
 393 
 394         assertSame(emptyNavigableSetArray, result);
 395 
 396         assertTrue(result[0] == null);
 397     }
 398 
 399     @DataProvider(name = "NavigableSet<?>", parallel = true)
 400     public static Iterator<Object[]> navigableSetsProvider() {
 401         return makeNavigableSets().iterator();
 402     }
 403 
 404     public static Collection<Object[]> makeNavigableSets() {
 405         return Arrays.asList(
 406             new Object[]{"UnmodifiableNavigableSet(TreeSet)", Collections.unmodifiableNavigableSet(new TreeSet())},
 407             new Object[]{"UnmodifiableNavigableSet(TreeSet.descendingSet()", Collections.unmodifiableNavigableSet(new TreeSet().descendingSet())},
 408             new Object[]{"UnmodifiableNavigableSet(TreeSet.descendingSet().descendingSet()", Collections.unmodifiableNavigableSet(new TreeSet().descendingSet().descendingSet())},
 409             new Object[]{"emptyNavigableSet()", Collections.emptyNavigableSet()},
 410             new Object[]{"emptyNavigableSet().descendingSet()", Collections.emptyNavigableSet().descendingSet()},
 411             new Object[]{"emptyNavigableSet().descendingSet().descendingSet()", Collections.emptyNavigableSet().descendingSet().descendingSet()}
 412         );
 413     }
 414 }