guava

Форк
0
96 строк · 3.5 Кб
1
/*
2
 * Copyright (C) 2008 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_VALUES;
20

21
import com.google.common.annotations.GwtCompatible;
22
import com.google.common.collect.testing.Helpers;
23
import com.google.common.collect.testing.MinimalSet;
24
import com.google.common.collect.testing.features.CollectionFeature;
25
import com.google.common.collect.testing.features.CollectionSize;
26
import java.util.Collection;
27
import java.util.Set;
28
import org.junit.Ignore;
29

30
/**
31
 * Tests {@link java.util.Set#equals}.
32
 *
33
 * @author George van den Driessche
34
 */
35
@GwtCompatible
36
@Ignore // Affects only Android test runner, which respects JUnit 4 annotations on JUnit 3 tests.
37
public class SetEqualsTester<E> extends AbstractSetTester<E> {
38
  public void testEquals_otherSetWithSameElements() {
39
    assertTrue(
40
        "A Set should equal any other Set containing the same elements.",
41
        getSet().equals(MinimalSet.from(getSampleElements())));
42
  }
43

44
  @CollectionSize.Require(absent = CollectionSize.ZERO)
45
  public void testEquals_otherSetWithDifferentElements() {
46
    Collection<E> elements = getSampleElements(getNumElements() - 1);
47
    elements.add(getSubjectGenerator().samples().e3());
48

49
    assertFalse(
50
        "A Set should not equal another Set containing different elements.",
51
        getSet().equals(MinimalSet.from(elements)));
52
  }
53

54
  @CollectionSize.Require(absent = CollectionSize.ZERO)
55
  @CollectionFeature.Require(ALLOWS_NULL_VALUES)
56
  public void testEquals_containingNull() {
57
    Collection<E> elements = getSampleElements(getNumElements() - 1);
58
    elements.add(null);
59

60
    collection = getSubjectGenerator().create(elements.toArray());
61
    assertTrue(
62
        "A Set should equal any other Set containing the same elements,"
63
            + " even if some elements are null.",
64
        getSet().equals(MinimalSet.from(elements)));
65
  }
66

67
  @CollectionSize.Require(absent = CollectionSize.ZERO)
68
  public void testEquals_otherContainsNull() {
69
    Collection<E> elements = getSampleElements(getNumElements() - 1);
70
    elements.add(null);
71
    Set<E> other = MinimalSet.from(elements);
72

73
    assertFalse(
74
        "Two Sets should not be equal if exactly one of them contains null.",
75
        getSet().equals(other));
76
  }
77

78
  @CollectionSize.Require(absent = CollectionSize.ZERO)
79
  public void testEquals_smallerSet() {
80
    Collection<E> fewerElements = getSampleElements(getNumElements() - 1);
81
    assertFalse(
82
        "Sets of different sizes should not be equal.",
83
        getSet().equals(MinimalSet.from(fewerElements)));
84
  }
85

86
  public void testEquals_largerSet() {
87
    Collection<E> moreElements = getSampleElements(getNumElements() + 1);
88
    assertFalse(
89
        "Sets of different sizes should not be equal.",
90
        getSet().equals(MinimalSet.from(moreElements)));
91
  }
92

93
  public void testEquals_list() {
94
    assertFalse("A List should never equal a Set.", getSet().equals(Helpers.copyToList(getSet())));
95
  }
96
}
97

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

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

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

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