Browse Source

with improved understanding of test cases

Amy Gill 6 years ago
parent
commit
5735e5c4c7

+ 3
- 0
src/main/java/com/zipcodewilmington/phonebook/Person.java View File

24
     }
24
     }
25
 
25
 
26
     public String getNumbers(){
26
     public String getNumbers(){
27
+
27
         return phoneNumber.toString();
28
         return phoneNumber.toString();
28
     }
29
     }
29
 
30
 
30
     public void removeSingleNumber (String number){
31
     public void removeSingleNumber (String number){
32
+
31
         phoneNumber.remove(number);
33
         phoneNumber.remove(number);
32
     }
34
     }
33
 
35
 
34
     public void addAdditionalNumber(String number){
36
     public void addAdditionalNumber(String number){
37
+
35
         phoneNumber.add(number);
38
         phoneNumber.add(number);
36
     }
39
     }
37
 }
40
 }

+ 10
- 1
src/main/java/com/zipcodewilmington/phonebook/PhoneBook.java View File

13
     public static void main(String[] args) {
13
     public static void main(String[] args) {
14
 
14
 
15
         PhoneBook myPhoneBookActualObjectInstance= new PhoneBook();
15
         PhoneBook myPhoneBookActualObjectInstance= new PhoneBook();
16
+        //adding two people:
16
         myPhoneBookActualObjectInstance.add("vince", "1123456789");
17
         myPhoneBookActualObjectInstance.add("vince", "1123456789");
17
         myPhoneBookActualObjectInstance.add("amy", "29387429");
18
         myPhoneBookActualObjectInstance.add("amy", "29387429");
18
-        myPhoneBookActualObjectInstance.personTreeMap.get("amy").addAdditionalNumber("2344");
19
+        //asking the program to get a person using it's name and adding an additional number to it:
20
+        myPhoneBookActualObjectInstance.addAdditionalNumberToEntry("amy", "2344");
21
+        //printing out the entire phonebook
19
         System.out.println(myPhoneBookActualObjectInstance.displayEntirePhoneBookContents());
22
         System.out.println(myPhoneBookActualObjectInstance.displayEntirePhoneBookContents());
20
     }
23
     }
21
 
24
 
40
         personTreeMap.remove(name);
43
         personTreeMap.remove(name);
41
     }
44
     }
42
 
45
 
46
+    //newly added thanks to "the falcon"
47
+    public void addAdditionalNumberToEntry (String name, String number){
48
+        personTreeMap.get(name).addAdditionalNumber(number);
49
+
50
+    }
51
+
43
     public String lookup(String name) {
52
     public String lookup(String name) {
44
 
53
 
45
         return personTreeMap.get(name).getNumbers();
54
         return personTreeMap.get(name).getNumbers();

+ 20
- 0
src/test/java/com/zipcodewilmington/phonebook/PersonTest.java View File

1
+package com.zipcodewilmington.phonebook;
2
+
3
+import org.junit.Test;
4
+
5
+import static org.junit.Assert.*;
6
+
7
+public class PersonTest {
8
+
9
+    @Test
10
+    public void getNumbers() {
11
+    }
12
+
13
+    @Test
14
+    public void removeSingleNumber() {
15
+    }
16
+
17
+    @Test
18
+    public void addAdditionalNumber() {
19
+    }
20
+}

+ 82
- 2
src/test/java/com/zipcodewilmington/phonebook/PhoneBookTest.java View File

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