359
360 @Test(expectedExceptions=NullPointerException.class)
361 public void nullValueDisallowedVarN() {
362 Map.Entry<Integer,String>[] entries = genEntries(MAX_ENTRIES);
363 entries[0] = new AbstractMap.SimpleImmutableEntry<>(0, null);
364 Map<Integer, String> map = Map.ofEntries(entries);
365 }
366
367 @Test(expectedExceptions=NullPointerException.class)
368 public void nullEntryDisallowedVarN() {
369 Map.Entry<Integer,String>[] entries = genEntries(MAX_ENTRIES);
370 entries[5] = null;
371 Map<Integer, String> map = Map.ofEntries(entries);
372 }
373
374 @Test(expectedExceptions=NullPointerException.class)
375 public void nullArrayDisallowed() {
376 Map.ofEntries((Map.Entry<?,?>[])null);
377 }
378
379 @Test(dataProvider="all")
380 public void serialEquality(Map<Integer, String> act, Map<Integer, String> exp) {
381 // assume that act.equals(exp) tested elsewhere
382 Map<Integer, String> copy = serialClone(act);
383 assertEquals(act, copy);
384 assertEquals(copy, exp);
385 }
386
387 @SuppressWarnings("unchecked")
388 static <T> T serialClone(T obj) {
389 try {
390 ByteArrayOutputStream baos = new ByteArrayOutputStream();
391 try (ObjectOutputStream oos = new ObjectOutputStream(baos)) {
392 oos.writeObject(obj);
393 }
394 ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
395 ObjectInputStream ois = new ObjectInputStream(bais);
396 return (T) ois.readObject();
397 } catch (IOException | ClassNotFoundException e) {
398 throw new AssertionError(e);
|
359
360 @Test(expectedExceptions=NullPointerException.class)
361 public void nullValueDisallowedVarN() {
362 Map.Entry<Integer,String>[] entries = genEntries(MAX_ENTRIES);
363 entries[0] = new AbstractMap.SimpleImmutableEntry<>(0, null);
364 Map<Integer, String> map = Map.ofEntries(entries);
365 }
366
367 @Test(expectedExceptions=NullPointerException.class)
368 public void nullEntryDisallowedVarN() {
369 Map.Entry<Integer,String>[] entries = genEntries(MAX_ENTRIES);
370 entries[5] = null;
371 Map<Integer, String> map = Map.ofEntries(entries);
372 }
373
374 @Test(expectedExceptions=NullPointerException.class)
375 public void nullArrayDisallowed() {
376 Map.ofEntries((Map.Entry<?,?>[])null);
377 }
378
379 @Test(dataProvider="all", expectedExceptions=NullPointerException.class)
380 public void containsValueNullShouldThrowNPE(Map<Integer,String> act, Map<Integer,String> exp) {
381 act.containsValue(null);
382 }
383
384 @Test(dataProvider="all", expectedExceptions=NullPointerException.class)
385 public void containsKeyNullShouldThrowNPE(Map<Integer,String> act, Map<Integer,String> exp) {
386 act.containsKey(null);
387 }
388
389 @Test(dataProvider="all")
390 public void serialEquality(Map<Integer, String> act, Map<Integer, String> exp) {
391 // assume that act.equals(exp) tested elsewhere
392 Map<Integer, String> copy = serialClone(act);
393 assertEquals(act, copy);
394 assertEquals(copy, exp);
395 }
396
397 @SuppressWarnings("unchecked")
398 static <T> T serialClone(T obj) {
399 try {
400 ByteArrayOutputStream baos = new ByteArrayOutputStream();
401 try (ObjectOutputStream oos = new ObjectOutputStream(baos)) {
402 oos.writeObject(obj);
403 }
404 ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
405 ObjectInputStream ois = new ObjectInputStream(bais);
406 return (T) ois.readObject();
407 } catch (IOException | ClassNotFoundException e) {
408 throw new AssertionError(e);
|