@Test(expectedExceptions = IllegalArgumentException.class) public void dupKeysDisallowedN() { Map.Entry<Integer, String>[] entries = genEntries(MAX_ENTRIES); entries[MAX_ENTRIES - 1] = Maps2.entry(0, "xxx"); @SuppressWarnings("unused") Map<Integer, String> map = Maps2.ofEntries(entries); }
// compile-time test of wildcards @Test public void entryWildcardTests() { Map.Entry<Integer, Double> e1 = Maps2.entry(1, 2.0); Map.Entry<Float, Long> e2 = Maps2.entry(3.0f, 4L); @SuppressWarnings("unchecked") Map<Number, Number> map = Maps2.ofEntries(e1, e2); assertEquals(map.size(), 2); }
@Test public void entryBasicTests() { Map.Entry<String, String> kvh1 = Maps2.entry("xyzzy", "plugh"); Map.Entry<String, String> kvh2 = Maps2.entry("foobar", "blurfl"); @SuppressWarnings({"unchecked", "rawtypes"}) Map.Entry<String, String> sie = new AbstractMap.SimpleImmutableEntry("xyzzy", "plugh"); assertTrue(kvh1.equals(sie)); assertTrue(sie.equals(kvh1)); assertFalse(kvh2.equals(sie)); assertFalse(sie.equals(kvh2)); assertEquals(sie.hashCode(), kvh1.hashCode()); assertEquals(sie.toString(), kvh1.toString()); }
@Test(expectedExceptions = NullPointerException.class) public void nullEntryDisallowedN() { Map.Entry<Integer, String>[] entries = genEntries(MAX_ENTRIES); entries[5] = null; @SuppressWarnings("unused") Map<Integer, String> map = Maps2.ofEntries(entries); }
@SuppressWarnings({"unchecked", "rawtypes"}) @Test(expectedExceptions = NullPointerException.class) public void nullValueDisallowedN() { Map.Entry<Integer, String>[] entries = genEntries(MAX_ENTRIES); entries[0] = new AbstractMap.SimpleImmutableEntry(0, null); @SuppressWarnings("unused") Map<Integer, String> map = Maps2.ofEntries(entries); }
@DataProvider(name = "nonempty") public Iterator<Object[]> nonempty() { return Arrays.asList( a(Maps2.of(0, "a"), genMap(1)), a(Maps2.of(0, "a", 1, "b"), genMap(2)), a(Maps2.of(0, "a", 1, "b", 2, "c"), genMap(3)), a(Maps2.of(0, "a", 1, "b", 2, "c", 3, "d"), genMap(4)), a(Maps2.of(0, "a", 1, "b", 2, "c", 3, "d", 4, "e"), genMap(5)), a(Maps2.of(0, "a", 1, "b", 2, "c", 3, "d", 4, "e", 5, "f"), genMap(6)), a(Maps2.of(0, "a", 1, "b", 2, "c", 3, "d", 4, "e", 5, "f", 6, "g"), genMap(7)), a(Maps2.of(0, "a", 1, "b", 2, "c", 3, "d", 4, "e", 5, "f", 6, "g", 7, "h"), genMap(8)), a( Maps2.of(0, "a", 1, "b", 2, "c", 3, "d", 4, "e", 5, "f", 6, "g", 7, "h", 8, "i"), genMap(9)), a( Maps2.of( 0, "a", 1, "b", 2, "c", 3, "d", 4, "e", 5, "f", 6, "g", 7, "h", 8, "i", 9, "j"), genMap(10)), a(Maps2.ofEntries(genEntries(MAX_ENTRIES)), genMap(MAX_ENTRIES))) .iterator(); }
@DataProvider(name = "empty") public Iterator<Object[]> empty() { return Collections.singletonList(a(Maps2.of(), genMap(0))).iterator(); }
// for varargs Map.Entry methods @SuppressWarnings("unchecked") Map.Entry<Integer, String>[] genEntries(int n) { return IntStreams.range(0, n) .mapToObj(i -> Maps2.entry(i, valueFor(i))) .toArray(Map.Entry[]::new); }
@Test(expectedExceptions = NullPointerException.class) public void entryWithNullValueDisallowed() { @SuppressWarnings("unused") Map.Entry<Integer, String> e = Maps2.entry(0, null); }
@Test(expectedExceptions = NullPointerException.class) public void nullArrayDisallowed() { Maps2.ofEntries((Map.Entry<Object, Object>[]) null); }
@Test(expectedExceptions = NullPointerException.class) public void nullValueDisallowed10() { @SuppressWarnings("unused") Map<Integer, String> map = Maps2.of(0, "a", 1, "b", 2, "c", 3, "d", 4, "e", 5, "f", 6, "g", 7, "h", 8, "i", 9, null); }
@Test(expectedExceptions = NullPointerException.class) public void nullKeyDisallowed7() { @SuppressWarnings("unused") Map<Integer, String> map = Maps2.of(0, "a", 1, "b", 2, "c", 3, "d", 4, "e", 5, "f", null, "g"); }
@Test(expectedExceptions = NullPointerException.class) public void nullValueDisallowed4() { @SuppressWarnings("unused") Map<Integer, String> map = Maps2.of(0, "a", 1, "b", 2, "c", 3, null); }
@Test(expectedExceptions = NullPointerException.class) public void nullKeyDisallowed2() { @SuppressWarnings("unused") Map<Integer, String> map = Maps2.of(0, "a", null, "b"); }
@Test(expectedExceptions = IllegalArgumentException.class) public void dupKeysDisallowed10() { @SuppressWarnings("unused") Map<Integer, String> map = Maps2.of(0, "a", 1, "b", 2, "c", 3, "d", 4, "e", 5, "f", 6, "g", 7, "h", 8, "i", 0, "j"); }
@Test(expectedExceptions = IllegalArgumentException.class) public void dupKeysDisallowed4() { @SuppressWarnings("unused") Map<Integer, String> map = Maps2.of(0, "a", 1, "b", 2, "c", 0, "d"); }