forked from mockito/mockito
/
IdentitySetTest.java
49 lines (37 loc) · 1020 Bytes
/
IdentitySetTest.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
/*
* Copyright (c) 2007 Mockito contributors
* This program is made available under the terms of the MIT License.
*/
package org.mockito.internal.util.collections;
import static org.junit.Assert.*;
import org.junit.Test;
public class IdentitySetTest {
IdentitySet set = new IdentitySet();
@Test
public void shouldWork() throws Exception {
//when
Object o = new Object();
set.add(o);
//then
assertTrue(set.contains(o));
assertFalse(set.contains(new Object()));
}
@SuppressWarnings("EqualsHashCode")
class Fake {
@Override
public boolean equals(Object obj) {
return true;
}
}
@Test
public void shouldWorkEvenIfEqualsTheSame() throws Exception {
//given
assertEquals(new Fake(), new Fake());
Fake fake = new Fake();
//when
set.add(fake);
//then
assertTrue(set.contains(fake));
assertFalse(set.contains(new Fake()));
}
}