@Test public void getIfAbsentPut_Function() { MutableObjectBooleanMap<Integer> map1 = this.getEmptyMap(); Assert.assertTrue(map1.getIfAbsentPut(0, () -> true)); BooleanFunction0 factoryThrows = () -> { throw new AssertionError(); }; Assert.assertTrue(map1.getIfAbsentPut(0, factoryThrows)); Assert.assertEquals(this.newWithKeysValues(0, true), map1); Assert.assertTrue(map1.getIfAbsentPut(1, () -> true)); Assert.assertTrue(map1.getIfAbsentPut(1, factoryThrows)); Assert.assertEquals(this.newWithKeysValues(0, true, 1, true), map1); MutableObjectBooleanMap<Integer> map2 = this.getEmptyMap(); Assert.assertFalse(map2.getIfAbsentPut(1, () -> false)); Assert.assertFalse(map2.getIfAbsentPut(1, factoryThrows)); Assert.assertEquals(this.newWithKeysValues(1, false), map2); Assert.assertFalse(map2.getIfAbsentPut(0, () -> false)); Assert.assertFalse(map2.getIfAbsentPut(0, factoryThrows)); Assert.assertEquals(this.newWithKeysValues(0, false, 1, false), map2); MutableObjectBooleanMap<Integer> map3 = this.getEmptyMap(); Assert.assertTrue(map3.getIfAbsentPut(null, () -> true)); Assert.assertTrue(map3.getIfAbsentPut(null, factoryThrows)); Assert.assertEquals(this.newWithKeysValues(null, true), map3); }
@Test public void getIfAbsentPut_Function() { BooleanFunction0 factory = new BooleanFunction0() { public boolean value() { return true; } }; MutableObjectBooleanMap<Integer> map1 = this.getEmptyMap(); Assert.assertTrue(map1.getIfAbsentPut(0, factory)); BooleanFunction0 factoryThrows = new BooleanFunction0() { public boolean value() { throw new AssertionError(); } }; Assert.assertTrue(map1.getIfAbsentPut(0, factoryThrows)); Assert.assertEquals(this.newWithKeysValues(0, true), map1); Assert.assertTrue(map1.getIfAbsentPut(1, factory)); Assert.assertTrue(map1.getIfAbsentPut(1, factoryThrows)); Assert.assertEquals(this.newWithKeysValues(0, true, 1, true), map1); MutableObjectBooleanMap<Integer> map2 = this.getEmptyMap(); BooleanFunction0 factoryFalse = new BooleanFunction0() { public boolean value() { return false; } }; Assert.assertFalse(map2.getIfAbsentPut(1, factoryFalse)); Assert.assertFalse(map2.getIfAbsentPut(1, factoryThrows)); Assert.assertEquals(this.newWithKeysValues(1, false), map2); Assert.assertFalse(map2.getIfAbsentPut(0, factoryFalse)); Assert.assertFalse(map2.getIfAbsentPut(0, factoryThrows)); Assert.assertEquals(this.newWithKeysValues(0, false, 1, false), map2); MutableObjectBooleanMap<Integer> map3 = this.getEmptyMap(); Assert.assertTrue(map3.getIfAbsentPut(null, factory)); Assert.assertTrue(map3.getIfAbsentPut(null, factoryThrows)); Assert.assertEquals(this.newWithKeysValues(null, true), map3); }