Java
112 строк · 3.9 Кб
1/*
2* Copyright (C) 2015 The Guava Authors
3*
4* Licensed under the Apache License, Version 2.0 (the "License");
5* you may not use this file except in compliance with the License.
6* You may obtain a copy of the License at
7*
8* http://www.apache.org/licenses/LICENSE-2.0
9*
10* Unless required by applicable law or agreed to in writing, software
11* distributed under the License is distributed on an "AS IS" BASIS,
12* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13* See the License for the specific language governing permissions and
14* limitations under the License.
15*/
16
17package com.google.common.collect.testing.testers;
18
19import static com.google.common.collect.testing.features.CollectionSize.ZERO;
20import static com.google.common.collect.testing.features.MapFeature.ALLOWS_NULL_KEY_QUERIES;
21import static com.google.common.collect.testing.features.MapFeature.ALLOWS_NULL_VALUE_QUERIES;
22import static com.google.common.collect.testing.features.MapFeature.SUPPORTS_REMOVE;
23
24import com.google.common.annotations.GwtCompatible;
25import com.google.common.collect.testing.AbstractMapTester;
26import com.google.common.collect.testing.features.CollectionSize;
27import com.google.common.collect.testing.features.MapFeature;
28import java.util.concurrent.ConcurrentMap;
29import org.junit.Ignore;
30
31/**
32* Tester for {@link ConcurrentMap#remove}. Can't be invoked directly; please see {@link
33* com.google.common.collect.testing.ConcurrentMapTestSuiteBuilder}.
34*
35* @author Louis Wasserman
36*/
37@GwtCompatible
38@Ignore // Affects only Android test runner, which respects JUnit 4 annotations on JUnit 3 tests.
39@SuppressWarnings("JUnit4ClassUsedInJUnit3")
40@ElementTypesAreNonnullByDefault
41public class ConcurrentMapRemoveTester<K, V> extends AbstractMapTester<K, V> {
42@Override
43protected ConcurrentMap<K, V> getMap() {
44return (ConcurrentMap<K, V>) super.getMap();
45}
46
47@MapFeature.Require(SUPPORTS_REMOVE)
48@CollectionSize.Require(absent = ZERO)
49public void testRemove_supportedPresent() {
50assertTrue(getMap().remove(k0(), v0()));
51expectMissing(e0());
52}
53
54@MapFeature.Require(SUPPORTS_REMOVE)
55public void testRemove_supportedPresentKeyWrongValue() {
56assertFalse(getMap().remove(k0(), v3()));
57expectUnchanged();
58}
59
60@MapFeature.Require(SUPPORTS_REMOVE)
61public void testRemove_supportedWrongKeyPresentValue() {
62assertFalse(getMap().remove(k3(), v0()));
63expectUnchanged();
64}
65
66@MapFeature.Require(SUPPORTS_REMOVE)
67public void testRemove_supportedAbsentKeyAbsentValue() {
68assertFalse(getMap().remove(k3(), v3()));
69expectUnchanged();
70}
71
72@MapFeature.Require(value = SUPPORTS_REMOVE, absent = ALLOWS_NULL_KEY_QUERIES)
73public void testRemove_nullKeyQueriesUnsupported() {
74try {
75assertFalse(getMap().remove(null, v3()));
76} catch (NullPointerException tolerated) {
77// since the operation would be a no-op, the exception is not required
78}
79expectUnchanged();
80}
81
82@MapFeature.Require(value = SUPPORTS_REMOVE, absent = ALLOWS_NULL_VALUE_QUERIES)
83public void testRemove_nullValueQueriesUnsupported() {
84try {
85assertFalse(getMap().remove(k3(), null));
86} catch (NullPointerException tolerated) {
87// since the operation would be a no-op, the exception is not required
88}
89expectUnchanged();
90}
91
92@MapFeature.Require(absent = SUPPORTS_REMOVE)
93@CollectionSize.Require(absent = ZERO)
94public void testRemove_unsupportedPresent() {
95try {
96getMap().remove(k0(), v0());
97fail("Expected UnsupportedOperationException");
98} catch (UnsupportedOperationException expected) {
99}
100expectUnchanged();
101}
102
103@MapFeature.Require(absent = SUPPORTS_REMOVE)
104public void testRemove_unsupportedAbsent() {
105try {
106assertFalse(getMap().remove(k0(), v3()));
107} catch (UnsupportedOperationException tolerated) {
108// since the operation would be a no-op, the exception is not required
109}
110expectUnchanged();
111}
112}
113