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