-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPersonSetTest.java
More file actions
63 lines (47 loc) · 1.5 KB
/
Copy pathPersonSetTest.java
File metadata and controls
63 lines (47 loc) · 1.5 KB
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
package collections;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import java.util.Set;
import java.util.TreeSet;
import org.junit.Test;
public class PersonSetTest {
@Test
public void testSetWorks() throws Exception {
SetPerson john = new SetPerson("john", 65);
SetPerson james = new SetPerson("james", 65);
SetPerson kent = new SetPerson("kent", 65);
Set<SetPerson> personsSet = new TreeSet<SetPerson>();
try {
personsSet.add(john);
personsSet.add(james);
personsSet.add(kent);
} catch (ClassCastException e) {
fail("should not throw class cast Exception");
}
assertEquals(3, personsSet.size());
}
@Test
public void testSortingWithName() throws Exception {
SetPerson john = new SetPerson("john", 65);
SetPerson james = new SetPerson("james", 65);
SetPerson kent = new SetPerson("kent", 65);
Set<SetPerson> personsSet = new TreeSet<SetPerson>();
personsSet.add(john);
personsSet.add(james);
personsSet.add(kent);
assertEquals(
"[SetPerson [name=james, age=65], SetPerson [name=john, age=65], SetPerson [name=kent, age=65]]",
personsSet.toString());
}
@Test
public void testDoesNotTakeDuplicates() throws Exception {
SetPerson john = new SetPerson("john", 65);
SetPerson james = new SetPerson("john", 65);
SetPerson kent = new SetPerson("john", 65);
Set<SetPerson> personsSet = new TreeSet<SetPerson>();
personsSet.add(john);
personsSet.add(james);
personsSet.add(kent);
System.out.println(personsSet);
}
}