|
@@ -1,7 +1,183 @@
|
1
|
1
|
package com.zipcodewilmington.phonebook;
|
2
|
2
|
|
|
3
|
+import org.junit.Assert;
|
|
4
|
+import org.junit.Test;
|
|
5
|
+
|
|
6
|
+import java.util.ArrayList;
|
|
7
|
+
|
3
|
8
|
/**
|
4
|
9
|
* Created by leon on 1/23/18.
|
5
|
10
|
*/
|
6
|
11
|
public class PhoneBookTest {
|
|
12
|
+
|
|
13
|
+ @Test
|
|
14
|
+ public void testHasEntry() {
|
|
15
|
+ // Given
|
|
16
|
+ PhoneBook book = new PhoneBook();
|
|
17
|
+ String name = "Dan";
|
|
18
|
+ ArrayList<String> phoneNumber = new ArrayList<>();
|
|
19
|
+ phoneNumber.add("300-111-1222");
|
|
20
|
+
|
|
21
|
+ book.add(name, phoneNumber);
|
|
22
|
+
|
|
23
|
+ //When
|
|
24
|
+ boolean actualOutput = book.hasEntry(name);
|
|
25
|
+
|
|
26
|
+ //Then
|
|
27
|
+ Assert.assertTrue(actualOutput);
|
|
28
|
+
|
|
29
|
+ }
|
|
30
|
+
|
|
31
|
+ @Test
|
|
32
|
+ public void testAdd() {
|
|
33
|
+ //Given
|
|
34
|
+ PhoneBook book = new PhoneBook();
|
|
35
|
+ String name = "Ravi";
|
|
36
|
+ ArrayList<String> phoneNumber = new ArrayList<>();
|
|
37
|
+ phoneNumber.add("300-111-1222");
|
|
38
|
+ phoneNumber.add("300-111-1223");
|
|
39
|
+
|
|
40
|
+ //When
|
|
41
|
+ book.add(name, phoneNumber);
|
|
42
|
+
|
|
43
|
+ //Then
|
|
44
|
+ Assert.assertEquals(1, book.size());
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+ }
|
|
48
|
+
|
|
49
|
+ @Test
|
|
50
|
+ public void testAddIndvNum() {
|
|
51
|
+ //Given
|
|
52
|
+ PhoneBook book = new PhoneBook();
|
|
53
|
+ String name = "Ravi";
|
|
54
|
+ ArrayList<String> phoneNumber = new ArrayList<>();
|
|
55
|
+ phoneNumber.add("300-111-1222");
|
|
56
|
+ phoneNumber.add("300-111-1223");
|
|
57
|
+ //When
|
|
58
|
+ book.addIndvNum(name, "300-111-1224");
|
|
59
|
+ String expOut = "300-111-1224";
|
|
60
|
+ ArrayList<String> list = book.lookup(name);
|
|
61
|
+ String actOut = list.get(2);
|
|
62
|
+
|
|
63
|
+ //Then
|
|
64
|
+ Assert.assertEquals(expOut, actOut);
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+ }
|
|
68
|
+
|
|
69
|
+ @Test
|
|
70
|
+ public void testLookup() {
|
|
71
|
+ //Given
|
|
72
|
+ PhoneBook book = new PhoneBook();
|
|
73
|
+ String name = "John";
|
|
74
|
+ ArrayList<String> phoneNumber = new ArrayList<>();
|
|
75
|
+ phoneNumber.add("300-111-2222");
|
|
76
|
+ phoneNumber.add("300-111-2223");
|
|
77
|
+ book.add(name, phoneNumber);
|
|
78
|
+ String expNum1 = "300-111-2222";
|
|
79
|
+ String expNum2 = "300-111-2223";
|
|
80
|
+
|
|
81
|
+ //When
|
|
82
|
+ ArrayList<String> actNumList = book.lookup(name);
|
|
83
|
+ String actNum1 = actNumList.get(0);
|
|
84
|
+ String actNum2 = actNumList.get(1);
|
|
85
|
+
|
|
86
|
+ //Then
|
|
87
|
+ Assert.assertEquals(expNum1, actNum1);
|
|
88
|
+ Assert.assertEquals(expNum2, actNum2);
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+ }
|
|
92
|
+
|
|
93
|
+ @Test
|
|
94
|
+ public void testRemove() {
|
|
95
|
+ //Given
|
|
96
|
+ PhoneBook book = new PhoneBook();
|
|
97
|
+ String name = "Jane";
|
|
98
|
+ ArrayList<String> phoneNumber = new ArrayList<>();
|
|
99
|
+ phoneNumber.add("300-111-1222");
|
|
100
|
+ phoneNumber.add("300-111-1223");
|
|
101
|
+ book.add(name, phoneNumber);
|
|
102
|
+ String remNum = "300-111-1223";
|
|
103
|
+
|
|
104
|
+ //When
|
|
105
|
+ book.remove(name, remNum);
|
|
106
|
+ ArrayList<String> actNumList = book.lookup(name);
|
|
107
|
+
|
|
108
|
+ //Then
|
|
109
|
+ Assert.assertEquals(1, actNumList.size());
|
|
110
|
+
|
|
111
|
+ }
|
|
112
|
+
|
|
113
|
+ @Test
|
|
114
|
+ public void testRemoveRecord() {
|
|
115
|
+ //Given
|
|
116
|
+ PhoneBook book = new PhoneBook();
|
|
117
|
+ String name1 = "Jimmy";
|
|
118
|
+ String name2 = "Jimmys";
|
|
119
|
+ ArrayList<String> phoneNumber1 = new ArrayList<>();
|
|
120
|
+ phoneNumber1.add("300-111-1222");
|
|
121
|
+ phoneNumber1.add("300-111-1223");
|
|
122
|
+ book.add(name1, phoneNumber1);
|
|
123
|
+ ArrayList<String> phoneNumber2 = new ArrayList<>();
|
|
124
|
+ phoneNumber2.add("300-111-2223");
|
|
125
|
+ phoneNumber2.add("300-111-2224");
|
|
126
|
+ book.add(name2, phoneNumber2);
|
|
127
|
+
|
|
128
|
+ //When
|
|
129
|
+ book.removeRecord(name2, phoneNumber2);
|
|
130
|
+
|
|
131
|
+ //Then
|
|
132
|
+ Assert.assertEquals(1, book.size());
|
|
133
|
+
|
|
134
|
+ }
|
|
135
|
+
|
|
136
|
+ @Test
|
|
137
|
+ public void testReverseLookup() {
|
|
138
|
+ //Given
|
|
139
|
+ PhoneBook book = new PhoneBook();
|
|
140
|
+ String name = "Franny";
|
|
141
|
+ ArrayList<String> phoneNumber = new ArrayList<>();
|
|
142
|
+ phoneNumber.add("300-111-1222");
|
|
143
|
+ phoneNumber.add("300-111-1223");
|
|
144
|
+ book.add(name, phoneNumber);
|
|
145
|
+
|
|
146
|
+ //When
|
|
147
|
+ String actName = book.reverseLookup(phoneNumber);
|
|
148
|
+
|
|
149
|
+ //Then
|
|
150
|
+ Assert.assertEquals("Franny", actName);
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+ }
|
|
154
|
+
|
|
155
|
+ @Test
|
|
156
|
+ public void testListNmAndNums() {
|
|
157
|
+ //Given
|
|
158
|
+ PhoneBook book = new PhoneBook();
|
|
159
|
+ String name1 = "GG";
|
|
160
|
+ String name2 = "HH";
|
|
161
|
+ ArrayList<String> phoneNumber1 = new ArrayList<>();
|
|
162
|
+ phoneNumber1.add("300-111-1222");
|
|
163
|
+ phoneNumber1.add("300-111-1223");
|
|
164
|
+ book.add(name1, phoneNumber1);
|
|
165
|
+ ArrayList<String> phoneNumber2 = new ArrayList<>();
|
|
166
|
+ phoneNumber2.add("300-111-1333");
|
|
167
|
+ phoneNumber2.add("300-111-1334");
|
|
168
|
+ book.add(name2, phoneNumber2);
|
|
169
|
+
|
|
170
|
+ String expOut = "\nName: GG Number : [300-111-1222, 300-111-1223]" + "\nName: HH Number : [300-111-1333, 300-111-1334]";
|
|
171
|
+
|
|
172
|
+ //When
|
|
173
|
+ String actOut = book.listNameAndNumbers();
|
|
174
|
+
|
|
175
|
+ //Then
|
|
176
|
+ Assert.assertEquals(expOut, actOut);
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+ }
|
7
|
180
|
}
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+
|