17
package com.google.common.collect.testing.testers;
19
import static com.google.common.collect.testing.features.CollectionSize.ZERO;
20
import static com.google.common.collect.testing.features.MapFeature.ALLOWS_NULL_VALUES;
21
import static com.google.common.collect.testing.features.MapFeature.ALLOWS_NULL_VALUE_QUERIES;
22
import static com.google.common.collect.testing.features.MapFeature.SUPPORTS_PUT;
24
import com.google.common.annotations.GwtCompatible;
25
import com.google.common.collect.testing.AbstractMapTester;
26
import com.google.common.collect.testing.features.CollectionSize;
27
import com.google.common.collect.testing.features.MapFeature;
28
import java.util.concurrent.ConcurrentMap;
29
import org.junit.Ignore;
40
@ElementTypesAreNonnullByDefault
41
public class ConcurrentMapReplaceEntryTester<K, V> extends AbstractMapTester<K, V> {
43
protected ConcurrentMap<K, V> getMap() {
44
return (ConcurrentMap<K, V>) super.getMap();
47
@MapFeature.Require(SUPPORTS_PUT)
48
@CollectionSize.Require(absent = ZERO)
49
public void testReplaceEntry_supportedPresent() {
50
assertTrue(getMap().replace(k0(), v0(), v3()));
51
expectReplacement(entry(k0(), v3()));
54
@MapFeature.Require(SUPPORTS_PUT)
55
@CollectionSize.Require(absent = ZERO)
56
public void testReplaceEntry_supportedPresentUnchanged() {
57
assertTrue(getMap().replace(k0(), v0(), v0()));
61
@MapFeature.Require(SUPPORTS_PUT)
62
@CollectionSize.Require(absent = ZERO)
63
public void testReplaceEntry_supportedWrongValue() {
64
assertFalse(getMap().replace(k0(), v3(), v4()));
68
@MapFeature.Require(SUPPORTS_PUT)
69
public void testReplaceEntry_supportedAbsentKey() {
70
assertFalse(getMap().replace(k3(), v3(), v4()));
74
@MapFeature.Require(value = SUPPORTS_PUT, absent = ALLOWS_NULL_VALUES)
75
@CollectionSize.Require(absent = ZERO)
76
public void testReplaceEntry_presentNullValueUnsupported() {
78
getMap().replace(k0(), v0(), null);
79
fail("Expected NullPointerException");
80
} catch (NullPointerException expected) {
85
@MapFeature.Require(value = SUPPORTS_PUT, absent = ALLOWS_NULL_VALUE_QUERIES)
86
@CollectionSize.Require(absent = ZERO)
87
public void testReplaceEntry_wrongValueNullValueUnsupported() {
89
assertFalse(getMap().replace(k0(), v3(), null));
90
} catch (NullPointerException tolerated) {
96
@MapFeature.Require(value = SUPPORTS_PUT, absent = ALLOWS_NULL_VALUE_QUERIES)
97
public void testReplaceEntry_absentKeyNullValueUnsupported() {
99
assertFalse(getMap().replace(k3(), v3(), null));
100
} catch (NullPointerException tolerated) {
106
@MapFeature.Require({SUPPORTS_PUT, ALLOWS_NULL_VALUE_QUERIES})
107
public void testReplaceEntry_nullDifferentFromAbsent() {
108
assertFalse(getMap().replace(k3(), null, v3()));
112
@MapFeature.Require(value = SUPPORTS_PUT, absent = ALLOWS_NULL_VALUE_QUERIES)
113
public void testReplaceEntry_expectNullUnsupported() {
115
assertFalse(getMap().replace(k3(), null, v3()));
116
} catch (NullPointerException tolerated) {
122
@MapFeature.Require(absent = SUPPORTS_PUT)
123
@CollectionSize.Require(absent = ZERO)
124
public void testReplaceEntry_unsupportedPresent() {
126
getMap().replace(k0(), v0(), v3());
127
fail("Expected UnsupportedOperationException");
128
} catch (UnsupportedOperationException expected) {
133
@MapFeature.Require(absent = SUPPORTS_PUT)
134
@CollectionSize.Require(absent = ZERO)
135
public void testReplaceEntry_unsupportedWrongValue() {
137
getMap().replace(k0(), v3(), v4());
138
} catch (UnsupportedOperationException tolerated) {
144
@MapFeature.Require(absent = SUPPORTS_PUT)
145
public void testReplaceEntry_unsupportedAbsentKey() {
147
getMap().replace(k3(), v3(), v4());
148
} catch (UnsupportedOperationException tolerated) {