@Test public void getIfAbsentPutWith() { MutableMapIterable<Integer, String> map = this.newMapWithKeysValues(1, "1", 2, "2", 3, "3"); Assert.assertNull(map.get(4)); Assert.assertEquals("4", map.getIfAbsentPutWith(4, String::valueOf, 4)); Assert.assertEquals("3", map.getIfAbsentPutWith(3, String::valueOf, 3)); Verify.assertContainsKeyValue(4, "4", map); }
@Test public void getIfAbsentPut() { MutableMapIterable<Integer, String> map = this.newMapWithKeysValues(1, "1", 2, "2", 3, "3"); Assert.assertNull(map.get(4)); Assert.assertEquals("4", map.getIfAbsentPut(4, new PassThruFunction0<>("4"))); Assert.assertEquals("3", map.getIfAbsentPut(3, new PassThruFunction0<>("3"))); Verify.assertContainsKeyValue(4, "4", map); }
@Test public void getIfAbsentPutWithKey() { MutableMapIterable<Integer, Integer> map = this.newMapWithKeysValues(1, 1, 2, 2, 3, 3); Assert.assertNull(map.get(4)); Assert.assertEquals( Integer.valueOf(4), map.getIfAbsentPutWithKey(4, Functions.getIntegerPassThru())); Assert.assertEquals( Integer.valueOf(3), map.getIfAbsentPutWithKey(3, Functions.getIntegerPassThru())); Verify.assertContainsKeyValue(Integer.valueOf(4), Integer.valueOf(4), map); }