-
Notifications
You must be signed in to change notification settings - Fork 587
/
SetTestCase.java
115 lines (97 loc) · 3.56 KB
/
SetTestCase.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/*
* Copyright (c) 2022 Goldman Sachs and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* and Eclipse Distribution License v. 1.0 which accompany this distribution.
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
* and the Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*/
package org.eclipse.collections.test.set;
import java.util.Collection;
import java.util.Iterator;
import java.util.Set;
import org.eclipse.collections.api.set.MutableSet;
import org.eclipse.collections.impl.factory.Sets;
import org.eclipse.collections.impl.test.SerializeTestHelper;
import org.eclipse.collections.test.CollectionTestCase;
import org.junit.Assert;
import org.junit.Test;
import static org.eclipse.collections.impl.test.Verify.assertPostSerializedEqualsAndHashCode;
import static org.eclipse.collections.test.IterableTestCase.assertEquals;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.isOneOf;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
public interface SetTestCase extends CollectionTestCase
{
@Override
<T> Set<T> newWith(T... elements);
@Override
@Test
default void Object_PostSerializedEqualsAndHashCode()
{
Iterable<Integer> iterable = this.newWith(3, 2, 1);
Object deserialized = SerializeTestHelper.serializeDeserialize(iterable);
Assert.assertNotSame(iterable, deserialized);
}
@Override
@Test
default void Object_equalsAndHashCode()
{
assertPostSerializedEqualsAndHashCode(this.newWith(3, 2, 1));
assertNotEquals(this.newWith(4, 3, 2, 1), this.newWith(3, 2, 1));
assertNotEquals(this.newWith(3, 2, 1), this.newWith(4, 3, 2, 1));
assertNotEquals(this.newWith(2, 1), this.newWith(3, 2, 1));
assertNotEquals(this.newWith(3, 2, 1), this.newWith(2, 1));
assertNotEquals(this.newWith(4, 2, 1), this.newWith(3, 2, 1));
assertNotEquals(this.newWith(3, 2, 1), this.newWith(4, 2, 1));
}
@Override
@Test
default void Iterable_next()
{
CollectionTestCase.super.Iterable_next();
Set<Integer> iterable = this.newWith(3, 2, 1);
MutableSet<Integer> mutableSet = Sets.mutable.with();
Iterator<Integer> iterator = iterable.iterator();
while (iterator.hasNext())
{
Integer integer = iterator.next();
assertTrue(mutableSet.add(integer));
}
assertEquals(iterable, mutableSet);
assertFalse(iterator.hasNext());
}
@Override
@Test
default void Iterable_remove()
{
Set<Integer> set = this.newWith(3, 2, 1);
Iterator<Integer> iterator = set.iterator();
iterator.next();
iterator.remove();
assertThat(set, isOneOf(
this.newWith(1, 2),
this.newWith(1, 3),
this.newWith(2, 3)));
}
@Override
@Test
default void Collection_add()
{
CollectionTestCase.super.Collection_add();
Collection<Integer> collection = this.newWith(1, 2, 3);
assertFalse(collection.add(3));
}
@Override
@Test
default void Collection_size()
{
CollectionTestCase.super.Collection_size();
assertThat(this.newWith(3, 2, 1), hasSize(3));
assertThat(this.newWith(), hasSize(0));
}
}