guava

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

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
@ElementTypesAreNonnullByDefault
40
public class ConcurrentMapRemoveTester<K, V> extends AbstractMapTester<K, V> {
41
  @Override
42
  protected ConcurrentMap<K, V> getMap() {
43
    return (ConcurrentMap<K, V>) super.getMap();
44
  }
45

46
  @MapFeature.Require(SUPPORTS_REMOVE)
47
  @CollectionSize.Require(absent = ZERO)
48
  public void testRemove_supportedPresent() {
49
    assertTrue(getMap().remove(k0(), v0()));
50
    expectMissing(e0());
51
  }
52

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

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

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

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

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

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

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

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

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

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

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