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
@SuppressWarnings("JUnit4ClassUsedInJUnit3")
41
@ElementTypesAreNonnullByDefault
42
public class ConcurrentMapReplaceEntryTester<K, V> extends AbstractMapTester<K, V> {
44
protected ConcurrentMap<K, V> getMap() {
45
return (ConcurrentMap<K, V>) super.getMap();
48
@MapFeature.Require(SUPPORTS_PUT)
49
@CollectionSize.Require(absent = ZERO)
50
public void testReplaceEntry_supportedPresent() {
51
assertTrue(getMap().replace(k0(), v0(), v3()));
52
expectReplacement(entry(k0(), v3()));
55
@MapFeature.Require(SUPPORTS_PUT)
56
@CollectionSize.Require(absent = ZERO)
57
public void testReplaceEntry_supportedPresentUnchanged() {
58
assertTrue(getMap().replace(k0(), v0(), v0()));
62
@MapFeature.Require(SUPPORTS_PUT)
63
@CollectionSize.Require(absent = ZERO)
64
public void testReplaceEntry_supportedWrongValue() {
65
assertFalse(getMap().replace(k0(), v3(), v4()));
69
@MapFeature.Require(SUPPORTS_PUT)
70
public void testReplaceEntry_supportedAbsentKey() {
71
assertFalse(getMap().replace(k3(), v3(), v4()));
75
@MapFeature.Require(value = SUPPORTS_PUT, absent = ALLOWS_NULL_VALUES)
76
@CollectionSize.Require(absent = ZERO)
77
public void testReplaceEntry_presentNullValueUnsupported() {
79
getMap().replace(k0(), v0(), null);
80
fail("Expected NullPointerException");
81
} catch (NullPointerException expected) {
86
@MapFeature.Require(value = SUPPORTS_PUT, absent = ALLOWS_NULL_VALUE_QUERIES)
87
@CollectionSize.Require(absent = ZERO)
88
public void testReplaceEntry_wrongValueNullValueUnsupported() {
90
assertFalse(getMap().replace(k0(), v3(), null));
91
} catch (NullPointerException tolerated) {
97
@MapFeature.Require(value = SUPPORTS_PUT, absent = ALLOWS_NULL_VALUE_QUERIES)
98
public void testReplaceEntry_absentKeyNullValueUnsupported() {
100
assertFalse(getMap().replace(k3(), v3(), null));
101
} catch (NullPointerException tolerated) {
107
@MapFeature.Require({SUPPORTS_PUT, ALLOWS_NULL_VALUE_QUERIES})
108
public void testReplaceEntry_nullDifferentFromAbsent() {
109
assertFalse(getMap().replace(k3(), null, v3()));
113
@MapFeature.Require(value = SUPPORTS_PUT, absent = ALLOWS_NULL_VALUE_QUERIES)
114
public void testReplaceEntry_expectNullUnsupported() {
116
assertFalse(getMap().replace(k3(), null, v3()));
117
} catch (NullPointerException tolerated) {
123
@MapFeature.Require(absent = SUPPORTS_PUT)
124
@CollectionSize.Require(absent = ZERO)
125
public void testReplaceEntry_unsupportedPresent() {
127
getMap().replace(k0(), v0(), v3());
128
fail("Expected UnsupportedOperationException");
129
} catch (UnsupportedOperationException expected) {
134
@MapFeature.Require(absent = SUPPORTS_PUT)
135
@CollectionSize.Require(absent = ZERO)
136
public void testReplaceEntry_unsupportedWrongValue() {
138
getMap().replace(k0(), v3(), v4());
139
} catch (UnsupportedOperationException tolerated) {
145
@MapFeature.Require(absent = SUPPORTS_PUT)
146
public void testReplaceEntry_unsupportedAbsentKey() {
148
getMap().replace(k3(), v3(), v4());
149
} catch (UnsupportedOperationException tolerated) {