|
@@ -23,9 +23,20 @@ public class PhoneBookTest {
|
23
|
23
|
|
24
|
24
|
@Test
|
25
|
25
|
public void addEntryTestCase1(){
|
|
26
|
+ //Given
|
|
27
|
+ //a person object
|
|
28
|
+ // a name and a number object
|
26
|
29
|
new Person("Addison", "1234");
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+ //When
|
|
33
|
+ //we add the person to the phonebook
|
27
|
34
|
testPhonebook.add("Addison", "1234");
|
28
|
35
|
String testNumber = testPhonebook.lookup("Addison");
|
|
36
|
+
|
|
37
|
+ //Then
|
|
38
|
+ //we expect to see that person object with assigned name and number
|
|
39
|
+
|
29
|
40
|
Assert.assertTrue(testNumber.equals("[1234]"));
|
30
|
41
|
}
|
31
|
42
|
|
|
@@ -48,66 +59,135 @@ public class PhoneBookTest {
|
48
|
59
|
|
49
|
60
|
@Test
|
50
|
61
|
public void removeEntireEntryTest2(){
|
|
62
|
+ //Given
|
|
63
|
+ //2 person objects
|
|
64
|
+ // 2 names and 2 phone numbers
|
|
65
|
+
|
51
|
66
|
testPhonebook.add("Andrea", "8888");
|
52
|
67
|
testPhonebook.add("Alexei", "8877");
|
|
68
|
+
|
|
69
|
+ //When
|
|
70
|
+ //a user/dev removes one entry from the phonebook
|
53
|
71
|
testPhonebook.removeEntireEntry("Alexei");
|
54
|
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.
|
55
|
76
|
Assert.assertTrue(testList.equals("Andrea\n"));
|
56
|
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");
|
57
|
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);
|
58
|
98
|
}
|
59
|
99
|
|
60
|
100
|
@Test
|
61
|
101
|
public void testLookup() {
|
62
|
102
|
|
|
103
|
+ //Given
|
|
104
|
+ //a person object with name and number
|
|
105
|
+
|
63
|
106
|
testPhonebook.add("JohnDoe", "1123");
|
64
|
107
|
|
|
108
|
+ //When
|
|
109
|
+ //we try and look up a person's phone number by using their name as the search thing
|
65
|
110
|
String expected = "[1123]";
|
66
|
111
|
String actual = testPhonebook.lookup("JohnDoe");
|
67
|
112
|
|
|
113
|
+ //Then
|
|
114
|
+ //we expect to see their number
|
|
115
|
+
|
68
|
116
|
Assert.assertEquals(expected, actual);
|
69
|
117
|
|
70
|
118
|
}
|
71
|
119
|
|
72
|
120
|
@Test
|
73
|
121
|
public void testListNamesOnly1 (){
|
|
122
|
+ //Given
|
|
123
|
+ //a bunch of people with names and numbers
|
74
|
124
|
testPhonebook.add("Andrea", "8888");
|
75
|
125
|
testPhonebook.add("Alexei", "8877");
|
76
|
126
|
testPhonebook.add("Addison", "1234");
|
77
|
127
|
testPhonebook.add("AdDy", "1234");
|
|
128
|
+
|
|
129
|
+ //When
|
|
130
|
+ //we ask the program to display just the names
|
78
|
131
|
String actual = testPhonebook.showNamesOnly();
|
79
|
132
|
String expected = "AdDy\nAddison\nAlexei\nAndrea\n";
|
|
133
|
+
|
|
134
|
+ //Then
|
|
135
|
+ //we expect to see just the names
|
80
|
136
|
Assert.assertEquals(expected, actual);
|
81
|
137
|
}
|
82
|
138
|
|
83
|
139
|
@Test
|
84
|
140
|
public void displayEntirePhoneBookContentsTest(){
|
|
141
|
+ //Given
|
|
142
|
+ //a list of peoples name and numbers
|
85
|
143
|
testPhonebook.add("Andrea", "8888");
|
86
|
144
|
testPhonebook.add("Alexei", "8877");
|
|
145
|
+ //When
|
|
146
|
+ //we ask to see all entries with name and numbers
|
87
|
147
|
String actual = testPhonebook.displayEntirePhoneBookContents();
|
88
|
|
- String expected = "Alexei's phone number: [8877]\nAndrea's phone number: [8888]\n";
|
|
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
|
89
|
151
|
Assert.assertEquals(expected, actual);
|
90
|
152
|
}
|
91
|
153
|
|
92
|
154
|
@Test
|
93
|
155
|
public void addAdditionalNumberTest(){
|
|
156
|
+ //Given
|
|
157
|
+ //a person object with an existing number
|
94
|
158
|
testPhonebook.add("Andrea", "8888");
|
|
159
|
+ //When
|
|
160
|
+ // we add an addtional number to that person object
|
95
|
161
|
testPhonebook.personTreeMap.get("Andrea").addAdditionalNumber("1111");
|
|
162
|
+
|
|
163
|
+ //Then
|
|
164
|
+ // we expect to see that number added
|
96
|
165
|
String actual= testPhonebook.displayEntirePhoneBookContents();
|
97
|
166
|
String expected = "Andrea's phone number(s): [8888, 1111]\n";
|
|
167
|
+// String actual = testPhonebook.lookup("Andrea");
|
|
168
|
+// String expected = "[8888, 1111]";
|
98
|
169
|
Assert.assertEquals(expected, actual);
|
99
|
170
|
|
100
|
171
|
}
|
101
|
|
-
|
102
|
172
|
@Test
|
103
|
173
|
public void removeSingleNumberTest(){
|
|
174
|
+ //Given
|
|
175
|
+ //an entry with more than 1 number
|
104
|
176
|
testPhonebook.add("Andrea", "8888");
|
105
|
177
|
testPhonebook.personTreeMap.get("Andrea").addAdditionalNumber("1111");
|
106
|
178
|
testPhonebook.personTreeMap.get("Andrea").addAdditionalNumber("2222");
|
|
179
|
+
|
|
180
|
+ //When
|
|
181
|
+ //we try to remove a number
|
107
|
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
|
108
|
186
|
String actual = testPhonebook.displayEntirePhoneBookContents();
|
109
|
187
|
String expected = "Andrea's phone number(s): [8888, 2222]\n";
|
110
|
188
|
Assert.assertEquals(expected, actual);
|
111
|
189
|
}
|
112
|
190
|
|
|
191
|
+
|
|
192
|
+
|
113
|
193
|
}
|