|
@@ -1,7 +1,193 @@
|
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.Map;
|
|
8
|
+import java.util.TreeMap;
|
|
9
|
+
|
3
|
10
|
/**
|
4
|
11
|
* Created by leon on 1/23/18.
|
5
|
12
|
*/
|
6
|
13
|
public class PhoneBookTest {
|
|
14
|
+
|
|
15
|
+//Start off here. google "how to write a test for a map"
|
|
16
|
+// PhoneBook testPhonebook = new PhoneBook(); <=why didn't this work?
|
|
17
|
+ PhoneBook testPhonebook;
|
|
18
|
+
|
|
19
|
+ @Before
|
|
20
|
+ public void setup() {
|
|
21
|
+ testPhonebook = new PhoneBook();
|
|
22
|
+ }
|
|
23
|
+
|
|
24
|
+ @Test
|
|
25
|
+ public void addEntryTestCase1(){
|
|
26
|
+ //Given
|
|
27
|
+ //a person object
|
|
28
|
+ // a name and a number object
|
|
29
|
+ new Person("Addison", "1234");
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+ //When
|
|
33
|
+ //we add the person to the phonebook
|
|
34
|
+ testPhonebook.add("Addison", "1234");
|
|
35
|
+ String testNumber = testPhonebook.lookup("Addison");
|
|
36
|
+
|
|
37
|
+ //Then
|
|
38
|
+ //we expect to see that person object with assigned name and number
|
|
39
|
+
|
|
40
|
+ Assert.assertTrue(testNumber.equals("[1234]"));
|
|
41
|
+ }
|
|
42
|
+
|
|
43
|
+ @Test
|
|
44
|
+ public void addEntryTestCase2(){
|
|
45
|
+ new Person("AdDy", "123.4");
|
|
46
|
+ testPhonebook.add("AdDy", "123.4");
|
|
47
|
+ String testNumber = testPhonebook.lookup("AdDy");
|
|
48
|
+ Assert.assertTrue(testNumber.equals("[123.4]"));
|
|
49
|
+ }
|
|
50
|
+
|
|
51
|
+// @Test
|
|
52
|
+// public void removeEntireEntryTest1(){
|
|
53
|
+// testPhonebook.add("Allessandra", "4321");
|
|
54
|
+// testPhonebook.add("Essarella", "4421");
|
|
55
|
+// testPhonebook.removeEntireEntry("Allessandra");
|
|
56
|
+// String testNumber = testPhonebook.lookup("Essarella");
|
|
57
|
+// Assert.assertNotEquals(null, testNumber);
|
|
58
|
+// }
|
|
59
|
+
|
|
60
|
+ @Test
|
|
61
|
+ public void removeEntireEntryTest2(){
|
|
62
|
+ //Given
|
|
63
|
+ //2 person objects
|
|
64
|
+ // 2 names and 2 phone numbers
|
|
65
|
+
|
|
66
|
+ testPhonebook.add("Andrea", "8888");
|
|
67
|
+ testPhonebook.add("Alexei", "8877");
|
|
68
|
+
|
|
69
|
+ //When
|
|
70
|
+ //a user/dev removes one entry from the phonebook
|
|
71
|
+ testPhonebook.removeEntireEntry("Alexei");
|
|
72
|
+ String testList = testPhonebook.showNamesOnly();
|
|
73
|
+
|
|
74
|
+ //Then
|
|
75
|
+ //we expect to see that entry gone. we expect only to see all the other entries.
|
|
76
|
+ Assert.assertTrue(testList.equals("Andrea\n"));
|
|
77
|
+
|
|
78
|
+ }
|
|
79
|
+
|
|
80
|
+ //newly added thanks to "the falcon"
|
|
81
|
+ @Test
|
|
82
|
+ public void addAddtionalNumberToEntryTest() {
|
|
83
|
+ //Given
|
|
84
|
+ //A name and a number
|
|
85
|
+ testPhonebook.add("test", "123");
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+ //When
|
|
89
|
+ //we add additional number
|
|
90
|
+ testPhonebook.addAdditionalNumberToEntry("test", "200");
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+ //Then
|
|
94
|
+ //we expect expect to see that additional number added to the entry
|
|
95
|
+ String expected = "[123, 200]";
|
|
96
|
+ String actual = testPhonebook.lookup("test");
|
|
97
|
+ Assert.assertEquals(expected,actual);
|
|
98
|
+ }
|
|
99
|
+
|
|
100
|
+ @Test
|
|
101
|
+ public void testLookup() {
|
|
102
|
+
|
|
103
|
+ //Given
|
|
104
|
+ //a person object with name and number
|
|
105
|
+
|
|
106
|
+ testPhonebook.add("JohnDoe", "1123");
|
|
107
|
+
|
|
108
|
+ //When
|
|
109
|
+ //we try and look up a person's phone number by using their name as the search thing
|
|
110
|
+ String expected = "[1123]";
|
|
111
|
+ String actual = testPhonebook.lookup("JohnDoe");
|
|
112
|
+
|
|
113
|
+ //Then
|
|
114
|
+ //we expect to see their number
|
|
115
|
+
|
|
116
|
+ Assert.assertEquals(expected, actual);
|
|
117
|
+
|
|
118
|
+ }
|
|
119
|
+
|
|
120
|
+ @Test
|
|
121
|
+ public void testListNamesOnly1 (){
|
|
122
|
+ //Given
|
|
123
|
+ //a bunch of people with names and numbers
|
|
124
|
+ testPhonebook.add("Andrea", "8888");
|
|
125
|
+ testPhonebook.add("Alexei", "8877");
|
|
126
|
+ testPhonebook.add("Addison", "1234");
|
|
127
|
+ testPhonebook.add("AdDy", "1234");
|
|
128
|
+
|
|
129
|
+ //When
|
|
130
|
+ //we ask the program to display just the names
|
|
131
|
+ String actual = testPhonebook.showNamesOnly();
|
|
132
|
+ String expected = "AdDy\nAddison\nAlexei\nAndrea\n";
|
|
133
|
+
|
|
134
|
+ //Then
|
|
135
|
+ //we expect to see just the names
|
|
136
|
+ Assert.assertEquals(expected, actual);
|
|
137
|
+ }
|
|
138
|
+
|
|
139
|
+ @Test
|
|
140
|
+ public void displayEntirePhoneBookContentsTest(){
|
|
141
|
+ //Given
|
|
142
|
+ //a list of peoples name and numbers
|
|
143
|
+ testPhonebook.add("Andrea", "8888");
|
|
144
|
+ testPhonebook.add("Alexei", "8877");
|
|
145
|
+ //When
|
|
146
|
+ //we ask to see all entries with name and numbers
|
|
147
|
+ String actual = testPhonebook.displayEntirePhoneBookContents();
|
|
148
|
+ String expected = "Alexei's phone number(s): [8877]\nAndrea's phone number(s): [8888]\n";
|
|
149
|
+ //Then
|
|
150
|
+ //we expect to see all entries with name and numbers
|
|
151
|
+ Assert.assertEquals(expected, actual);
|
|
152
|
+ }
|
|
153
|
+
|
|
154
|
+ @Test
|
|
155
|
+ public void addAdditionalNumberTest(){
|
|
156
|
+ //Given
|
|
157
|
+ //a person object with an existing number
|
|
158
|
+ testPhonebook.add("Andrea", "8888");
|
|
159
|
+ //When
|
|
160
|
+ // we add an addtional number to that person object
|
|
161
|
+ testPhonebook.personTreeMap.get("Andrea").addAdditionalNumber("1111");
|
|
162
|
+
|
|
163
|
+ //Then
|
|
164
|
+ // we expect to see that number added
|
|
165
|
+ String actual= testPhonebook.displayEntirePhoneBookContents();
|
|
166
|
+ String expected = "Andrea's phone number(s): [8888, 1111]\n";
|
|
167
|
+// String actual = testPhonebook.lookup("Andrea");
|
|
168
|
+// String expected = "[8888, 1111]";
|
|
169
|
+ Assert.assertEquals(expected, actual);
|
|
170
|
+
|
|
171
|
+ }
|
|
172
|
+ @Test
|
|
173
|
+ public void removeSingleNumberTest(){
|
|
174
|
+ //Given
|
|
175
|
+ //an entry with more than 1 number
|
|
176
|
+ testPhonebook.add("Andrea", "8888");
|
|
177
|
+ testPhonebook.personTreeMap.get("Andrea").addAdditionalNumber("1111");
|
|
178
|
+ testPhonebook.personTreeMap.get("Andrea").addAdditionalNumber("2222");
|
|
179
|
+
|
|
180
|
+ //When
|
|
181
|
+ //we try to remove a number
|
|
182
|
+ testPhonebook.personTreeMap.get("Andrea").removeSingleNumber("1111");
|
|
183
|
+
|
|
184
|
+ //Then
|
|
185
|
+ //we expect to see the original entry with all of its numbers except the one we removed
|
|
186
|
+ String actual = testPhonebook.displayEntirePhoneBookContents();
|
|
187
|
+ String expected = "Andrea's phone number(s): [8888, 2222]\n";
|
|
188
|
+ Assert.assertEquals(expected, actual);
|
|
189
|
+ }
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
|
7
|
193
|
}
|