@Override public void withKeyValue() { MutableMap<Integer, String> map1 = new SingletonMap<Integer, String>(1, "A").withKeyValue(2, "B"); Verify.assertMapsEqual(UnifiedMap.newWithKeysValues(1, "A", 2, "B"), map1); Verify.assertInstanceOf(DoubletonMap.class, map1); MutableMap<Integer, String> map2 = new SingletonMap<Integer, String>(1, "A"); MutableMap<Integer, String> map2with = map2.withKeyValue(1, "AA"); Verify.assertMapsEqual(UnifiedMap.newWithKeysValues(1, "AA"), map2with); Assert.assertSame(map2, map2with); }
@Override @Test public void getIfAbsentWith() { MutableMap<Integer, String> map = new SingletonMap<Integer, String>(1, "1"); Assert.assertNull(map.get(4)); Assert.assertEquals("4", map.getIfAbsentWith(4, Functions.getToString(), 4)); Assert.assertEquals("1", map.getIfAbsentWith(1, Functions.getToString(), 1)); Assert.assertEquals(UnifiedMap.newWithKeysValues(1, "1"), map); }
@Override @Test public void getIfAbsent() { MutableMap<Integer, String> map = new SingletonMap<Integer, String>(1, "1"); Assert.assertNull(map.get(4)); Assert.assertEquals("4", map.getIfAbsent(4, new Constant<String>("4"))); Assert.assertEquals("1", map.getIfAbsent(1, new Constant<String>("1"))); Assert.assertEquals(UnifiedMap.newWithKeysValues(1, "1"), map); }
@Override public void withoutAllKeys() { MutableMap<Integer, String> map = new SingletonMap<Integer, String>(1, "A"); MutableMap<Integer, String> mapWithout = map.withoutAllKeys(FastList.newListWith(2, 3)); Assert.assertSame(map, mapWithout); mapWithout = map.withoutAllKeys(FastList.newListWith(1, 2)); Verify.assertMapsEqual(UnifiedMap.newMap(), mapWithout); Verify.assertInstanceOf(EmptyMap.class, mapWithout); }
@Override public void withoutKey() { MutableMap<Integer, String> map = new SingletonMap<Integer, String>(1, "A"); MutableMap<Integer, String> mapWithout = map.withoutKey(2); Assert.assertSame(map, mapWithout); mapWithout = map.withoutKey(1); Verify.assertMapsEqual(UnifiedMap.newMap(), mapWithout); Verify.assertInstanceOf(EmptyMap.class, mapWithout); }
@Test public void codeBlockSuccess() { Generator<Object> function = new CheckedGenerator<Object>() { @Override public Object safeValue() { return null; } }; MutableMap<String, Object> values = UnifiedMap.newMap(); MapIterate.getIfAbsentPut(values, "test", function); }
@Test(expected = RuntimeException.class) public void codeBlockRuntimeException() { Generator<Object> function = new CheckedGenerator<Object>() { @Override public Object safeValue() { throw new RuntimeException(); } }; MutableMap<String, Object> values = UnifiedMap.newMap(); MapIterate.getIfAbsentPut(values, "test", function); }
@Override @Test public void testEqualsAndHashCode() { Verify.assertEqualsAndHashCode(UnifiedMap.newWithKeysValues("1", "One"), this.classUnderTest()); }