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,14 +24,17 @@ public class Person {
24 24
     }
25 25
 
26 26
     public String getNumbers(){
27
+
27 28
         return phoneNumber.toString();
28 29
     }
29 30
 
30 31
     public void removeSingleNumber (String number){
32
+
31 33
         phoneNumber.remove(number);
32 34
     }
33 35
 
34 36
     public void addAdditionalNumber(String number){
37
+
35 38
         phoneNumber.add(number);
36 39
     }
37 40
 }

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

@@ -13,9 +13,12 @@ public class PhoneBook {
13 13
     public static void main(String[] args) {
14 14
 
15 15
         PhoneBook myPhoneBookActualObjectInstance= new PhoneBook();
16
+        //adding two people:
16 17
         myPhoneBookActualObjectInstance.add("vince", "1123456789");
17 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 22
         System.out.println(myPhoneBookActualObjectInstance.displayEntirePhoneBookContents());
20 23
     }
21 24
 
@@ -40,6 +43,12 @@ public class PhoneBook {
40 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 52
     public String lookup(String name) {
44 53
 
45 54
         return personTreeMap.get(name).getNumbers();

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

@@ -0,0 +1,20 @@
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,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
 }