|
@@ -6,66 +6,68 @@ import org.junit.Before;
|
6
|
6
|
import org.junit.Test;
|
7
|
7
|
|
8
|
8
|
import java.util.ArrayList;
|
|
9
|
+import java.util.Arrays;
|
|
10
|
+import java.util.Collections;
|
|
11
|
+import java.util.Set;
|
9
|
12
|
|
10
|
13
|
/**
|
11
|
14
|
* Created by leon on 1/23/18.
|
12
|
15
|
*/
|
13
|
16
|
public class PhoneBookTest {
|
14
|
|
- PhoneBook phoneBook;
|
|
17
|
+ PhoneBook phoneBook = new PhoneBook();
|
15
|
18
|
|
16
|
19
|
@Before
|
17
|
20
|
public void setUp() {
|
18
|
|
- phoneBook = new PhoneBook();
|
19
|
|
- phoneBook.addEntryToPhoneBook("Eric", "302-123-4567");
|
20
|
|
- phoneBook.addEntryToPhoneBook("Bob", "302-999-9999");
|
|
21
|
+ phoneBook = new PhoneBook(); // automatically goes in each test
|
|
22
|
+// phoneBook.addEntryToPhoneBook("Eric", "302-555-1111");
|
|
23
|
+// phoneBook.addEntryToPhoneBook("Bob", "302-999-9999");
|
21
|
24
|
}
|
22
|
25
|
|
23
|
26
|
|
24
|
27
|
@Test
|
25
|
28
|
public void testAddPhoneBookEntryToPhoneBook() {
|
26
|
|
- String phoneNumber = "302-555-1111";
|
27
|
|
- phoneBook.addEntryToPhoneBook("eric", phoneNumber);
|
28
|
|
- String actual = phoneBook.lookUp("eric");
|
29
|
|
- Assert.assertEquals(phoneNumber, actual);
|
|
29
|
+
|
|
30
|
+ ArrayList<String> addition = new ArrayList<>(Arrays.asList("302-555-1111", "302-222-2222"));
|
|
31
|
+
|
|
32
|
+ phoneBook.addEntryToPhoneBook("Eric", addition);
|
|
33
|
+
|
|
34
|
+ ArrayList<String> actual = new ArrayList<String>(phoneBook.lookUp("Eric"));
|
|
35
|
+ Assert.assertEquals(addition, actual);
|
30
|
36
|
}
|
31
|
37
|
|
32
|
38
|
@Test
|
33
|
39
|
public void testRemoveEntryFromPhoneBook() {
|
34
|
|
- String phoneNumber = "302-555-1111";
|
35
|
|
- String name = "eric";
|
36
|
|
- phoneBook.addEntryToPhoneBook(name, phoneNumber);
|
37
|
|
- phoneBook.removeEntryFromPhoneBook("eric", phoneNumber);
|
|
40
|
+ ArrayList<String> ericsNumbers = new ArrayList<>(Arrays.asList("302-555-1111", "302-222-2222"));
|
38
|
41
|
|
39
|
|
- String actual = phoneBook.lookUp("eric");
|
40
|
|
- Assert.assertEquals(null, actual);
|
41
|
|
- }
|
|
42
|
+ phoneBook.addEntryToPhoneBook("Eric", ericsNumbers);
|
42
|
43
|
|
43
|
|
- @Test
|
44
|
|
- public void testListNames() {
|
45
|
|
- String expected = "Bob\n" +
|
46
|
|
- "Eric\n";
|
47
|
|
- String actual = phoneBook.listNames();
|
|
44
|
+ String expected = "";
|
|
45
|
+ phoneBook.removeEntryFromPhoneBook("Eric");
|
|
46
|
+
|
|
47
|
+ String actual = phoneBook.entryListAll();
|
48
|
48
|
|
49
|
49
|
Assert.assertEquals(expected, actual);
|
50
|
50
|
}
|
51
|
51
|
|
52
|
52
|
@Test
|
53
|
|
- public void testListNumber() {
|
|
53
|
+ public void lookUpTest() {
|
|
54
|
+ ArrayList<String> addition = new ArrayList<>(Arrays.asList("302-555-1111", "302-222-2222"));
|
54
|
55
|
|
|
56
|
+ phoneBook.addEntryToPhoneBook("Eric", addition);
|
55
|
57
|
|
56
|
|
- String expected = "302-999-9999\n" +
|
57
|
|
- "302-123-4567\n";
|
58
|
|
- String actual = phoneBook.listNumbers();
|
59
|
|
-
|
60
|
|
- Assert.assertEquals(expected, actual);
|
|
58
|
+ ArrayList<String> actual = new ArrayList<String>(phoneBook.lookUp("Eric"));
|
|
59
|
+ Assert.assertEquals(addition, actual);
|
61
|
60
|
}
|
62
|
61
|
|
|
62
|
+
|
63
|
63
|
@Test
|
64
|
64
|
public void testEntryListAll() {
|
65
|
65
|
|
|
66
|
+ ArrayList<String> ericsNumbers = new ArrayList<>(Arrays.asList("302-111-1111", "302-222-2222", "302-333-3333"));
|
|
67
|
+ phoneBook.addEntryToPhoneBook("Eric :", ericsNumbers);
|
|
68
|
+
|
|
69
|
+ String expected = "Eric : " + ericsNumbers + "\n";
|
66
|
70
|
|
67
|
|
- String expected = "Bob : 302-999-9999\n" +
|
68
|
|
- "Eric : 302-123-4567\n";
|
69
|
71
|
String actual = phoneBook.entryListAll();
|
70
|
72
|
|
71
|
73
|
Assert.assertEquals(expected, actual);
|
|
@@ -75,9 +77,14 @@ public class PhoneBookTest {
|
75
|
77
|
|
76
|
78
|
@Test
|
77
|
79
|
public void testReverseLookup() {
|
78
|
|
- String expected = "Bob";
|
|
80
|
+ ArrayList<String> ericsNumbers = new ArrayList<>(Arrays.asList("302-555-1111", "302-222-2222"));
|
|
81
|
+
|
|
82
|
+ String expected = "Eric";
|
|
83
|
+
|
|
84
|
+ phoneBook.addEntryToPhoneBook("Eric", ericsNumbers);
|
|
85
|
+
|
|
86
|
+ String actual = phoneBook.reverseLookup("302-555-1111");
|
79
|
87
|
|
80
|
|
- String actual = phoneBook.reverseLookup("302-999-9999");
|
81
|
88
|
Assert.assertEquals(expected,actual);
|
82
|
89
|
}
|
83
|
90
|
|