Java

Форк
0
/
ConcurrentMapRemoveTester.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

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_VALUE_QUERIES;
22
import static com.google.common.collect.testing.features.MapFeature.SUPPORTS_REMOVE;
23

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;
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
41
public class ConcurrentMapRemoveTester<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_REMOVE)
48
  @CollectionSize.Require(absent = ZERO)
49
  public void testRemove_supportedPresent() {
50
    assertTrue(getMap().remove(k0(), v0()));
51
    expectMissing(e0());
52
  }
53

54
  @MapFeature.Require(SUPPORTS_REMOVE)
55
  public void testRemove_supportedPresentKeyWrongValue() {
56
    assertFalse(getMap().remove(k0(), v3()));
57
    expectUnchanged();
58
  }
59

60
  @MapFeature.Require(SUPPORTS_REMOVE)
61
  public void testRemove_supportedWrongKeyPresentValue() {
62
    assertFalse(getMap().remove(k3(), v0()));
63
    expectUnchanged();
64
  }
65

66
  @MapFeature.Require(SUPPORTS_REMOVE)
67
  public void testRemove_supportedAbsentKeyAbsentValue() {
68
    assertFalse(getMap().remove(k3(), v3()));
69
    expectUnchanged();
70
  }
71

72
  @MapFeature.Require(value = SUPPORTS_REMOVE, absent = ALLOWS_NULL_KEY_QUERIES)
73
  public void testRemove_nullKeyQueriesUnsupported() {
74
    try {
75
      assertFalse(getMap().remove(null, v3()));
76
    } catch (NullPointerException tolerated) {
77
      // since the operation would be a no-op, the exception is not required
78
    }
79
    expectUnchanged();
80
  }
81

82
  @MapFeature.Require(value = SUPPORTS_REMOVE, absent = ALLOWS_NULL_VALUE_QUERIES)
83
  public void testRemove_nullValueQueriesUnsupported() {
84
    try {
85
      assertFalse(getMap().remove(k3(), null));
86
    } catch (NullPointerException tolerated) {
87
      // since the operation would be a no-op, the exception is not required
88
    }
89
    expectUnchanged();
90
  }
91

92
  @MapFeature.Require(absent = SUPPORTS_REMOVE)
93
  @CollectionSize.Require(absent = ZERO)
94
  public void testRemove_unsupportedPresent() {
95
    try {
96
      getMap().remove(k0(), v0());
97
      fail("Expected UnsupportedOperationException");
98
    } catch (UnsupportedOperationException expected) {
99
    }
100
    expectUnchanged();
101
  }
102

103
  @MapFeature.Require(absent = SUPPORTS_REMOVE)
104
  public void testRemove_unsupportedAbsent() {
105
    try {
106
      assertFalse(getMap().remove(k0(), v3()));
107
    } catch (UnsupportedOperationException tolerated) {
108
      // since the operation would be a no-op, the exception is not required
109
    }
110
    expectUnchanged();
111
  }
112
}
113

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.