|
@@ -1,7 +1,134 @@
|
1
|
1
|
package com.zipcodewilmington.phonebook;
|
2
|
2
|
|
|
3
|
+import org.junit.Assert;
|
|
4
|
+import org.junit.Before;
|
|
5
|
+import org.junit.Test;
|
|
6
|
+
|
|
7
|
+import java.util.Arrays;
|
|
8
|
+
|
3
|
9
|
/**
|
4
|
10
|
* Created by leon on 1/23/18.
|
5
|
11
|
*/
|
6
|
12
|
public class PhoneBookTest {
|
|
13
|
+
|
|
14
|
+ private static PhoneBook phonebook;
|
|
15
|
+
|
|
16
|
+ @Before
|
|
17
|
+ public void setup() {
|
|
18
|
+ this.phonebook = new PhoneBook() ;
|
|
19
|
+ }
|
|
20
|
+
|
|
21
|
+ @Test
|
|
22
|
+ public void defaultConstructorTest() {
|
|
23
|
+ Assert.assertNotNull(this.phonebook);
|
|
24
|
+ }
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+ @Test
|
|
28
|
+ public void lookupTest() {
|
|
29
|
+ Person expectedPerson = new Person("Jane", "(111) 222-3333");
|
|
30
|
+ this.phonebook.addEntry("Jane", "(111) 222-3333");
|
|
31
|
+
|
|
32
|
+ String actualPersonName = expectedPerson.getName();
|
|
33
|
+ String actualPersonPhoneNumber = expectedPerson.phoneNumberList.get(0);
|
|
34
|
+
|
|
35
|
+ boolean actualPersonNameExists = this.phonebook.treeMap.containsKey("Jane");
|
|
36
|
+
|
|
37
|
+ Assert.assertTrue(actualPersonNameExists);
|
|
38
|
+ }
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+ @Test
|
|
42
|
+ public void addEntryTest() {
|
|
43
|
+ this.phonebook.addEntry("Adam", "(000) 000-0000", "(111) 111-1111");
|
|
44
|
+
|
|
45
|
+ boolean actualPersonName = this.phonebook.treeMap.containsKey("Adam");
|
|
46
|
+ boolean actualPhoneNumber = this.phonebook.treeMap.containsValue(this.phonebook.treeMap.get("Adam"));
|
|
47
|
+ Assert.assertTrue(actualPersonName);
|
|
48
|
+ Assert.assertTrue(actualPhoneNumber);
|
|
49
|
+
|
|
50
|
+ String expectedPhoneNumber1 = "(000) 000-0000";
|
|
51
|
+ String expectedPhoneNumber2 = "(111) 111-1111";
|
|
52
|
+
|
|
53
|
+ String actualPhoneNumber1 = this.phonebook.treeMap.get("Adam").phoneNumberList.get(0);
|
|
54
|
+ String actualPhoneNumber2 = this.phonebook.treeMap.get("Adam").phoneNumberList.get(1);
|
|
55
|
+
|
|
56
|
+ Assert.assertEquals(expectedPhoneNumber1, actualPhoneNumber1);
|
|
57
|
+ Assert.assertEquals(expectedPhoneNumber2, actualPhoneNumber2);
|
|
58
|
+
|
|
59
|
+ }
|
|
60
|
+
|
|
61
|
+ @Test
|
|
62
|
+ public void removeRecordTest() {
|
|
63
|
+ this.phonebook.addEntry("Bob", "(333) 444-5555");
|
|
64
|
+ this.phonebook.removeRecord("Bob");
|
|
65
|
+
|
|
66
|
+ boolean actualPersonName = this.phonebook.treeMap.containsKey("Bob");
|
|
67
|
+ boolean actualPersonObject = this.phonebook.treeMap.containsValue(this.phonebook.treeMap.get("Bob"));
|
|
68
|
+
|
|
69
|
+ Assert.assertFalse(actualPersonName);
|
|
70
|
+ Assert.assertFalse(actualPersonObject);
|
|
71
|
+ }
|
|
72
|
+
|
|
73
|
+ @Test
|
|
74
|
+ public void getKeySetTest() {
|
|
75
|
+ this.phonebook.addEntry("Frank", "(000) 000-0000", "(100) 000-0000");
|
|
76
|
+ this.phonebook.addEntry("Gabriel", "(100) 000-0000", "(110) 000-0000");
|
|
77
|
+
|
|
78
|
+ System.out.println("getAllEntriesTest:");
|
|
79
|
+ String expectedKeySet = "[Frank, Gabriel]";
|
|
80
|
+ String actualKeySet = this.phonebook.getKeySet().toString();
|
|
81
|
+
|
|
82
|
+ Assert.assertEquals(expectedKeySet, actualKeySet);
|
|
83
|
+ }
|
|
84
|
+
|
|
85
|
+ @Test
|
|
86
|
+ public void displayAllEntriesTest() {
|
|
87
|
+ this.phonebook.addEntry("Herbert", "(200) 000-0000", "(210) 000-0000");
|
|
88
|
+ this.phonebook.addEntry("Isabel", "(300) 000-0000", "(310) 000-0000");
|
|
89
|
+
|
|
90
|
+ String expectedEntries = "Herbert" + "\n" +
|
|
91
|
+ "\t" + "(200) 000-0000" + "\n" +
|
|
92
|
+ "\t" + "(210) 000-0000" + "\n" +
|
|
93
|
+ "Isabel" + "\n" +
|
|
94
|
+ "\t" + "(300) 000-0000" + "\n" +
|
|
95
|
+ "\t" + "(310) 000-0000" + "\n";
|
|
96
|
+ String actualEntries = this.phonebook.displayAllEntries().toString();
|
|
97
|
+
|
|
98
|
+// System.out.println("displayAllEntriesTest:");
|
|
99
|
+// System.out.println(expectedEntries);
|
|
100
|
+// System.out.println(actualEntries);
|
|
101
|
+
|
|
102
|
+ Assert.assertEquals(expectedEntries, actualEntries);
|
|
103
|
+ }
|
|
104
|
+
|
|
105
|
+ @Test
|
|
106
|
+ public void reverseLookupTest() {
|
|
107
|
+
|
|
108
|
+ // This method should allow you to look up names by the phone number associated with them.
|
|
109
|
+
|
|
110
|
+ // Given
|
|
111
|
+ String givenPhoneNumber = "(000) 111-2222";
|
|
112
|
+
|
|
113
|
+ // When
|
|
114
|
+ this.phonebook.addEntry("Ava", "(000) 111-2222");
|
|
115
|
+ Person expectedPerson = new Person("Ava", "(000) 111-2222");
|
|
116
|
+
|
|
117
|
+ String expectedName = "Ava";
|
|
118
|
+ String expectedPhoneNumber = "(000) 111-2222";
|
|
119
|
+
|
|
120
|
+ String actualNameFromPhoneBook = "Ava";
|
|
121
|
+ boolean actualPhoneNumberFromPhoneBook = this.phonebook.treeMap.get(actualNameFromPhoneBook).phoneNumberList.contains(expectedPhoneNumber);
|
|
122
|
+
|
|
123
|
+ Assert.assertEquals(expectedName, this.phonebook.reverseLookup(givenPhoneNumber));
|
|
124
|
+ // Then
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+ }
|
|
129
|
+
|
7
|
130
|
}
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
|