@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 getIfAbsentPut_block_throws() { MutableMapIterable<Integer, String> map = this.newMapWithKeysValues(1, "1", 2, "2", 3, "3"); Verify.assertThrows( RuntimeException.class, () -> map.getIfAbsentPut( 4, () -> { throw new RuntimeException(); })); Assert.assertEquals(UnifiedMap.newWithKeysValues(1, "1", 2, "2", 3, "3"), map); }