guava

Форк
0
/
CollectionContainsAllTester.java 
106 строк · 3.8 Кб
1
/*
2
 * Copyright (C) 2007 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.CollectionFeature.ALLOWS_NULL_QUERIES;
20
import static com.google.common.collect.testing.features.CollectionFeature.ALLOWS_NULL_VALUES;
21
import static com.google.common.collect.testing.features.CollectionSize.ZERO;
22

23
import com.google.common.annotations.GwtCompatible;
24
import com.google.common.collect.testing.AbstractCollectionTester;
25
import com.google.common.collect.testing.MinimalCollection;
26
import com.google.common.collect.testing.WrongType;
27
import com.google.common.collect.testing.features.CollectionFeature;
28
import com.google.common.collect.testing.features.CollectionSize;
29
import java.util.Collection;
30
import org.junit.Ignore;
31

32
/**
33
 * A generic JUnit test which tests {@code containsAll()} operations on a collection. Can't be
34
 * invoked directly; please see {@link
35
 * com.google.common.collect.testing.CollectionTestSuiteBuilder}.
36
 *
37
 * @author Kevin Bourrillion
38
 * @author Chris Povirk
39
 */
40
@GwtCompatible
41
@Ignore // Affects only Android test runner, which respects JUnit 4 annotations on JUnit 3 tests.
42
public class CollectionContainsAllTester<E> extends AbstractCollectionTester<E> {
43
  public void testContainsAll_empty() {
44
    assertTrue(
45
        "containsAll(empty) should return true", collection.containsAll(MinimalCollection.of()));
46
  }
47

48
  @CollectionSize.Require(absent = ZERO)
49
  public void testContainsAll_subset() {
50
    assertTrue(
51
        "containsAll(subset) should return true",
52
        collection.containsAll(MinimalCollection.of(e0())));
53
  }
54

55
  public void testContainsAll_sameElements() {
56
    assertTrue(
57
        "containsAll(sameElements) should return true",
58
        collection.containsAll(MinimalCollection.of(createSamplesArray())));
59
  }
60

61
  @SuppressWarnings("ModifyingCollectionWithItself")
62
  public void testContainsAll_self() {
63
    assertTrue("containsAll(this) should return true", collection.containsAll(collection));
64
  }
65

66
  public void testContainsAll_partialOverlap() {
67
    assertFalse(
68
        "containsAll(partialOverlap) should return false",
69
        collection.containsAll(MinimalCollection.of(e0(), e3())));
70
  }
71

72
  public void testContainsAll_disjoint() {
73
    assertFalse(
74
        "containsAll(disjoint) should return false",
75
        collection.containsAll(MinimalCollection.of(e3())));
76
  }
77

78
  @CollectionFeature.Require(absent = ALLOWS_NULL_QUERIES)
79
  public void testContainsAll_nullNotAllowed() {
80
    try {
81
      assertFalse(collection.containsAll(MinimalCollection.of((E) null)));
82
    } catch (NullPointerException tolerated) {
83
    }
84
  }
85

86
  @CollectionFeature.Require(ALLOWS_NULL_QUERIES)
87
  public void testContainsAll_nullAllowed() {
88
    assertFalse(collection.containsAll(MinimalCollection.of((E) null)));
89
  }
90

91
  @CollectionFeature.Require(ALLOWS_NULL_VALUES)
92
  @CollectionSize.Require(absent = ZERO)
93
  public void testContainsAll_nullPresent() {
94
    initCollectionWithNullElement();
95
    assertTrue(collection.containsAll(MinimalCollection.of((E) null)));
96
  }
97

98
  public void testContainsAll_wrongType() {
99
    Collection<WrongType> wrong = MinimalCollection.of(WrongType.VALUE);
100
    try {
101
      assertFalse(
102
          "containsAll(wrongType) should return false or throw", collection.containsAll(wrong));
103
    } catch (ClassCastException tolerated) {
104
    }
105
  }
106
}
107

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

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

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

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