< prev index next >

test/jdk/java/util/Collection/SetFactories.java

Print this page
rev 48431 : 8193128: Reduce number of implementation classes returned by List/Set/Map.of()
8191418: List.of().indexOf(null) doesn't throw NullPointerException
Reviewed-by: smarks, jrose, martin, plevart


 249         Set.of("a", "b", "c", "d", "e", "f", "g", "h", null);
 250     }
 251 
 252     @Test(expectedExceptions=NullPointerException.class)
 253     public void nullDisallowed10() {
 254         Set.of("a", "b", "c", "d", "e", "f", "g", "h", "i", null);
 255     }
 256 
 257     @Test(expectedExceptions=NullPointerException.class)
 258     public void nullDisallowedN() {
 259         String[] array = stringArray.clone();
 260         array[0] = null;
 261         Set.of(array);
 262     }
 263 
 264     @Test(expectedExceptions=NullPointerException.class)
 265     public void nullArrayDisallowed() {
 266         Set.of((Object[])null);
 267     }
 268 





 269     @Test(dataProvider="all")
 270     public void serialEquality(Set<String> act, Set<String> exp) {
 271         // assume that act.equals(exp) tested elsewhere
 272         Set<String> copy = serialClone(act);
 273         assertEquals(act, copy);
 274         assertEquals(copy, exp);
 275     }
 276 
 277     @SuppressWarnings("unchecked")
 278     static <T> T serialClone(T obj) {
 279         try {
 280             ByteArrayOutputStream baos = new ByteArrayOutputStream();
 281             try (ObjectOutputStream oos = new ObjectOutputStream(baos)) {
 282                 oos.writeObject(obj);
 283             }
 284             ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
 285             ObjectInputStream ois = new ObjectInputStream(bais);
 286             return (T) ois.readObject();
 287         } catch (IOException | ClassNotFoundException e) {
 288             throw new AssertionError(e);




 249         Set.of("a", "b", "c", "d", "e", "f", "g", "h", null);
 250     }
 251 
 252     @Test(expectedExceptions=NullPointerException.class)
 253     public void nullDisallowed10() {
 254         Set.of("a", "b", "c", "d", "e", "f", "g", "h", "i", null);
 255     }
 256 
 257     @Test(expectedExceptions=NullPointerException.class)
 258     public void nullDisallowedN() {
 259         String[] array = stringArray.clone();
 260         array[0] = null;
 261         Set.of(array);
 262     }
 263 
 264     @Test(expectedExceptions=NullPointerException.class)
 265     public void nullArrayDisallowed() {
 266         Set.of((Object[])null);
 267     }
 268 
 269     @Test(dataProvider="all", expectedExceptions=NullPointerException.class)
 270     public void containsNullShouldThrowNPE(Set<String> act, Set<String> exp) {
 271         act.contains(null);
 272     }
 273 
 274     @Test(dataProvider="all")
 275     public void serialEquality(Set<String> act, Set<String> exp) {
 276         // assume that act.equals(exp) tested elsewhere
 277         Set<String> copy = serialClone(act);
 278         assertEquals(act, copy);
 279         assertEquals(copy, exp);
 280     }
 281 
 282     @SuppressWarnings("unchecked")
 283     static <T> T serialClone(T obj) {
 284         try {
 285             ByteArrayOutputStream baos = new ByteArrayOutputStream();
 286             try (ObjectOutputStream oos = new ObjectOutputStream(baos)) {
 287                 oos.writeObject(obj);
 288             }
 289             ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
 290             ObjectInputStream ois = new ObjectInputStream(bais);
 291             return (T) ois.readObject();
 292         } catch (IOException | ClassNotFoundException e) {
 293             throw new AssertionError(e);


< prev index next >