@Override public boolean update(final Customer customer) { return idToCustomer.replace(customer.getId(), customer) != null; }
@Override public V replace(K key, V value) { synchronized (mutex) { return delegate().replace(key, value); } }
@MapFeature.Require(value = SUPPORTS_PUT, absent = ALLOWS_NULL_VALUE_QUERIES) public void testReplace_absentNullValueUnsupported() { try { getMap().replace(k3(), null); } catch (NullPointerException tolerated) { // permitted not to throw because it would be a no-op } expectUnchanged(); }
@MapFeature.Require(value = SUPPORTS_PUT, absent = ALLOWS_NULL_KEY_QUERIES) public void testReplace_absentNullKeyUnsupported() { try { getMap().replace(null, v3()); } catch (NullPointerException tolerated) { // permitted not to throw because it would be a no-op } expectUnchanged(); }
@MapFeature.Require({SUPPORTS_PUT, ALLOWS_NULL_VALUE_QUERIES}) public void testReplaceEntry_nullDifferentFromAbsent() { assertFalse(getMap().replace(k3(), null, v3())); expectUnchanged(); }
@MapFeature.Require(value = SUPPORTS_PUT, absent = ALLOWS_NULL_VALUE_QUERIES) public void testReplaceEntry_expectNullUnsupported() { try { assertFalse(getMap().replace(k3(), null, v3())); } catch (NullPointerException tolerated) { // the operation would be a no-op, so exceptions are allowed but not required } expectUnchanged(); }
@MapFeature.Require(SUPPORTS_PUT) public void testReplace_supportedAbsent() { assertNull(getMap().replace(k3(), v3())); expectUnchanged(); }
@MapFeature.Require(value = SUPPORTS_PUT, absent = ALLOWS_NULL_VALUES) @CollectionSize.Require(absent = ZERO) public void testReplace_presentNullValueUnsupported() { try { getMap().replace(k0(), null); fail("Expected NullPointerException"); } catch (NullPointerException expected) { } expectUnchanged(); }
@MapFeature.Require(value = SUPPORTS_PUT, absent = ALLOWS_NULL_VALUE_QUERIES) public void testReplaceEntry_absentKeyNullValueUnsupported() { try { assertFalse(getMap().replace(k3(), v3(), null)); } catch (NullPointerException tolerated) { // the operation would be a no-op, so exceptions are allowed but not required } expectUnchanged(); }
@MapFeature.Require(absent = SUPPORTS_PUT) public void testReplaceEntry_unsupportedAbsentKey() { try { getMap().replace(k3(), v3(), v4()); } catch (UnsupportedOperationException tolerated) { // the operation would be a no-op, so exceptions are allowed but not required } expectUnchanged(); } }
@MapFeature.Require(value = SUPPORTS_PUT, absent = ALLOWS_NULL_VALUE_QUERIES) @CollectionSize.Require(absent = ZERO) public void testReplaceEntry_wrongValueNullValueUnsupported() { try { assertFalse(getMap().replace(k0(), v3(), null)); } catch (NullPointerException tolerated) { // the operation would be a no-op, so exceptions are allowed but not required } expectUnchanged(); }
@MapFeature.Require(absent = SUPPORTS_PUT) @CollectionSize.Require(absent = ZERO) public void testReplaceEntry_unsupportedWrongValue() { try { getMap().replace(k0(), v3(), v4()); } catch (UnsupportedOperationException tolerated) { // the operation would be a no-op, so exceptions are allowed but not required } expectUnchanged(); }
@MapFeature.Require(SUPPORTS_PUT) public void testReplaceEntry_supportedAbsentKey() { assertFalse(getMap().replace(k3(), v3(), v4())); expectUnchanged(); }
@MapFeature.Require(value = SUPPORTS_PUT, absent = ALLOWS_NULL_VALUES) @CollectionSize.Require(absent = ZERO) public void testReplaceEntry_presentNullValueUnsupported() { try { getMap().replace(k0(), v0(), null); fail("Expected NullPointerException"); } catch (NullPointerException expected) { } expectUnchanged(); }
@MapFeature.Require(absent = SUPPORTS_PUT) @CollectionSize.Require(absent = ZERO) public void testReplaceEntry_unsupportedPresent() { try { getMap().replace(k0(), v0(), v3()); fail("Expected UnsupportedOperationException"); } catch (UnsupportedOperationException expected) { } expectUnchanged(); }
@MapFeature.Require(SUPPORTS_PUT) @CollectionSize.Require(absent = ZERO) public void testReplaceEntry_supportedPresentUnchanged() { assertTrue(getMap().replace(k0(), v0(), v0())); expectUnchanged(); }
@MapFeature.Require(SUPPORTS_PUT) @CollectionSize.Require(absent = ZERO) public void testReplace_supportedPresentNoChange() { assertEquals(v0(), getMap().replace(k0(), v0())); expectUnchanged(); }
@MapFeature.Require(SUPPORTS_PUT) @CollectionSize.Require(absent = ZERO) public void testReplaceEntry_supportedWrongValue() { assertFalse(getMap().replace(k0(), v3(), v4())); expectUnchanged(); }
@MapFeature.Require(SUPPORTS_PUT) @CollectionSize.Require(absent = ZERO) public void testReplace_supportedPresent() { try { assertEquals(v0(), getMap().replace(k0(), v3())); expectReplacement(entry(k0(), v3())); } catch (ClassCastException tolerated) { // for ClassToInstanceMap expectUnchanged(); } }
@MapFeature.Require(SUPPORTS_PUT) @CollectionSize.Require(absent = ZERO) public void testReplaceEntry_supportedPresent() { try { assertTrue(getMap().replace(k0(), v0(), v3())); expectReplacement(entry(k0(), v3())); } catch (ClassCastException tolerated) { // for ClassToInstanceMap expectUnchanged(); } }