guava
105 строк · 3.7 Кб
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.Map;
29import org.junit.Ignore;
30
31/**
32* Tester for {@link Map#remove(Object, Object)}. Can't be invoked directly; please see {@link
33* com.google.common.collect.testing.MapTestSuiteBuilder}.
34*
35* @author Louis Wasserman
36*/
37@GwtCompatible
38@Ignore // Affects only Android test runner, which respects JUnit 4 annotations on JUnit 3 tests.
39public class MapRemoveEntryTester<K, V> extends AbstractMapTester<K, V> {
40@MapFeature.Require(SUPPORTS_REMOVE)
41@CollectionSize.Require(absent = ZERO)
42public void testRemove_supportedPresent() {
43assertTrue(getMap().remove(k0(), v0()));
44expectMissing(e0());
45}
46
47@MapFeature.Require(SUPPORTS_REMOVE)
48public void testRemove_supportedPresentKeyWrongValue() {
49assertFalse(getMap().remove(k0(), v3()));
50expectUnchanged();
51}
52
53@MapFeature.Require(SUPPORTS_REMOVE)
54public void testRemove_supportedWrongKeyPresentValue() {
55assertFalse(getMap().remove(k3(), v0()));
56expectUnchanged();
57}
58
59@MapFeature.Require(SUPPORTS_REMOVE)
60public void testRemove_supportedAbsentKeyAbsentValue() {
61assertFalse(getMap().remove(k3(), v3()));
62expectUnchanged();
63}
64
65@MapFeature.Require(value = SUPPORTS_REMOVE, absent = ALLOWS_NULL_KEY_QUERIES)
66public void testRemove_nullKeyQueriesUnsupported() {
67try {
68assertFalse(getMap().remove(null, v3()));
69} catch (NullPointerException tolerated) {
70// since the operation would be a no-op, the exception is not required
71}
72expectUnchanged();
73}
74
75@MapFeature.Require(value = SUPPORTS_REMOVE, absent = ALLOWS_NULL_VALUE_QUERIES)
76public void testRemove_nullValueQueriesUnsupported() {
77try {
78assertFalse(getMap().remove(k3(), null));
79} catch (NullPointerException tolerated) {
80// since the operation would be a no-op, the exception is not required
81}
82expectUnchanged();
83}
84
85@MapFeature.Require(absent = SUPPORTS_REMOVE)
86@CollectionSize.Require(absent = ZERO)
87public void testRemove_unsupportedPresent() {
88try {
89getMap().remove(k0(), v0());
90fail("Expected UnsupportedOperationException");
91} catch (UnsupportedOperationException expected) {
92}
93expectUnchanged();
94}
95
96@MapFeature.Require(absent = SUPPORTS_REMOVE)
97public void testRemove_unsupportedAbsent() {
98try {
99assertFalse(getMap().remove(k0(), v3()));
100} catch (UnsupportedOperationException tolerated) {
101// since the operation would be a no-op, the exception is not required
102}
103expectUnchanged();
104}
105}
106