guava
111 строк · 3.8 Кб
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@ElementTypesAreNonnullByDefault
40public class ConcurrentMapRemoveTester<K, V> extends AbstractMapTester<K, V> {
41@Override
42protected ConcurrentMap<K, V> getMap() {
43return (ConcurrentMap<K, V>) super.getMap();
44}
45
46@MapFeature.Require(SUPPORTS_REMOVE)
47@CollectionSize.Require(absent = ZERO)
48public void testRemove_supportedPresent() {
49assertTrue(getMap().remove(k0(), v0()));
50expectMissing(e0());
51}
52
53@MapFeature.Require(SUPPORTS_REMOVE)
54public void testRemove_supportedPresentKeyWrongValue() {
55assertFalse(getMap().remove(k0(), v3()));
56expectUnchanged();
57}
58
59@MapFeature.Require(SUPPORTS_REMOVE)
60public void testRemove_supportedWrongKeyPresentValue() {
61assertFalse(getMap().remove(k3(), v0()));
62expectUnchanged();
63}
64
65@MapFeature.Require(SUPPORTS_REMOVE)
66public void testRemove_supportedAbsentKeyAbsentValue() {
67assertFalse(getMap().remove(k3(), v3()));
68expectUnchanged();
69}
70
71@MapFeature.Require(value = SUPPORTS_REMOVE, absent = ALLOWS_NULL_KEY_QUERIES)
72public void testRemove_nullKeyQueriesUnsupported() {
73try {
74assertFalse(getMap().remove(null, v3()));
75} catch (NullPointerException tolerated) {
76// since the operation would be a no-op, the exception is not required
77}
78expectUnchanged();
79}
80
81@MapFeature.Require(value = SUPPORTS_REMOVE, absent = ALLOWS_NULL_VALUE_QUERIES)
82public void testRemove_nullValueQueriesUnsupported() {
83try {
84assertFalse(getMap().remove(k3(), null));
85} catch (NullPointerException tolerated) {
86// since the operation would be a no-op, the exception is not required
87}
88expectUnchanged();
89}
90
91@MapFeature.Require(absent = SUPPORTS_REMOVE)
92@CollectionSize.Require(absent = ZERO)
93public void testRemove_unsupportedPresent() {
94try {
95getMap().remove(k0(), v0());
96fail("Expected UnsupportedOperationException");
97} catch (UnsupportedOperationException expected) {
98}
99expectUnchanged();
100}
101
102@MapFeature.Require(absent = SUPPORTS_REMOVE)
103public void testRemove_unsupportedAbsent() {
104try {
105assertFalse(getMap().remove(k0(), v3()));
106} catch (UnsupportedOperationException tolerated) {
107// since the operation would be a no-op, the exception is not required
108}
109expectUnchanged();
110}
111}
112