| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package com.google.common.collect.testing.testers; |
| 18 |
|
| 19 |
import static com.google.common.collect.testing.features.CollectionSize.ZERO; |
| 20 |
import static com.google.common.collect.testing.features.MapFeature.ALLOWS_NULL_KEY_QUERIES; |
| 21 |
import static com.google.common.collect.testing.features.MapFeature.ALLOWS_NULL_VALUES; |
| 22 |
import static com.google.common.collect.testing.features.MapFeature.ALLOWS_NULL_VALUE_QUERIES; |
| 23 |
import static com.google.common.collect.testing.features.MapFeature.SUPPORTS_PUT; |
| 24 |
|
| 25 |
import com.google.common.annotations.GwtCompatible; |
| 26 |
import com.google.common.collect.testing.AbstractMapTester; |
| 27 |
import com.google.common.collect.testing.features.CollectionSize; |
| 28 |
import com.google.common.collect.testing.features.MapFeature; |
| 29 |
import java.util.concurrent.ConcurrentMap; |
| 30 |
import org.junit.Ignore; |
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
@GwtCompatible |
| 40 |
@Ignore |
| 41 |
public class ConcurrentMapReplaceTester<K, V> extends AbstractMapTester<K, V> { |
| 42 |
@Override |
| 43 |
protected ConcurrentMap<K, V> getMap() { |
| 44 |
return (ConcurrentMap<K, V>) super.getMap(); |
| 45 |
} |
| 46 |
|
| 47 |
@MapFeature.Require(SUPPORTS_PUT) |
| 48 |
@CollectionSize.Require(absent = ZERO) |
| 49 |
public void testReplace_supportedPresent() { |
| 50 |
assertEquals(v0(), getMap().replace(k0(), v3())); |
| 51 |
expectReplacement(entry(k0(), v3())); |
| 52 |
} |
| 53 |
|
| 54 |
@MapFeature.Require(SUPPORTS_PUT) |
| 55 |
@CollectionSize.Require(absent = ZERO) |
| 56 |
public void testReplace_supportedPresentNoChange() { |
| 57 |
assertEquals(v0(), getMap().replace(k0(), v0())); |
| 58 |
expectUnchanged(); |
| 59 |
} |
| 60 |
|
| 61 |
@MapFeature.Require(SUPPORTS_PUT) |
| 62 |
public void testReplace_supportedAbsent() { |
| 63 |
assertNull(getMap().replace(k3(), v3())); |
| 64 |
expectUnchanged(); |
| 65 |
} |
| 66 |
|
| 67 |
@MapFeature.Require(value = SUPPORTS_PUT, absent = ALLOWS_NULL_VALUES) |
| 68 |
@CollectionSize.Require(absent = ZERO) |
| 69 |
public void testReplace_presentNullValueUnsupported() { |
| 70 |
try { |
| 71 |
getMap().replace(k0(), null); |
| 72 |
fail("Expected NullPointerException"); |
| 73 |
} catch (NullPointerException expected) { |
| 74 |
} |
| 75 |
expectUnchanged(); |
| 76 |
} |
| 77 |
|
| 78 |
@MapFeature.Require(value = SUPPORTS_PUT, absent = ALLOWS_NULL_VALUE_QUERIES) |
| 79 |
public void testReplace_absentNullValueUnsupported() { |
| 80 |
try { |
| 81 |
getMap().replace(k3(), null); |
| 82 |
} catch (NullPointerException tolerated) { |
| 83 |
|
| 84 |
} |
| 85 |
expectUnchanged(); |
| 86 |
} |
| 87 |
|
| 88 |
@MapFeature.Require(value = SUPPORTS_PUT, absent = ALLOWS_NULL_KEY_QUERIES) |
| 89 |
public void testReplace_absentNullKeyUnsupported() { |
| 90 |
try { |
| 91 |
getMap().replace(null, v3()); |
| 92 |
} catch (NullPointerException tolerated) { |
| 93 |
|
| 94 |
} |
| 95 |
expectUnchanged(); |
| 96 |
} |
| 97 |
|
| 98 |
@MapFeature.Require(absent = SUPPORTS_PUT) |
| 99 |
@CollectionSize.Require(absent = ZERO) |
| 100 |
public void testReplace_unsupportedPresent() { |
| 101 |
try { |
| 102 |
getMap().replace(k0(), v3()); |
| 103 |
fail("Expected UnsupportedOperationException"); |
| 104 |
} catch (UnsupportedOperationException expected) { |
| 105 |
} |
| 106 |
expectUnchanged(); |
| 107 |
} |
| 108 |
} |