Browse Source

last commit

mbowe4 6 years ago
parent
commit
9939ef1e18

+ 6
- 14
src/main/java/com/zipcodewilmington/phonebook/PhoneBook.java View File

28
         contactsMap.put(contact.getName(), contact);
28
         contactsMap.put(contact.getName(), contact);
29
     }
29
     }
30
 
30
 
31
+    public void addContact(Contact contact) {
32
+        contactsMap.put(contact.getName(), contact);
33
+    }
34
+
31
 
35
 
32
     public int getNumberOfContacts() {
36
     public int getNumberOfContacts() {
33
         return contactsMap.size();
37
         return contactsMap.size();
44
     }
48
     }
45
 
49
 
46
 
50
 
47
-    public Collection listAllContacts() {
51
+    public Collection<Contact> listAllContacts() {
48
         return contactsMap.values();
52
         return contactsMap.values();
49
     }
53
     }
50
 
54
 
62
                 return contact.getName();
66
                 return contact.getName();
63
             }
67
             }
64
         }
68
         }
69
+        return "";
65
     }
70
     }
66
 
71
 
67
-
68
-//
69
-//    public void listNamesAndNums(String name, String phoneNumber) {
70
-//
71
-//        for (String key : contacts.keySet()){
72
-//            String value = contacts.get(key);
73
-//            System.out.println(key + ": " + value);
74
-//        }
75
-//
76
-//    }
77
-//
78
-
79
-
80
 }
72
 }

+ 17
- 3
src/test/java/com/zipcodewilmington/phonebook/ContactTests.java View File

50
     }
50
     }
51
 
51
 
52
     @Test
52
     @Test
53
-    public void removePhoneNumber() {
53
+    public void removePhoneNumberTest() {
54
+    // Actual:
55
+    // Create new contact instance
54
         Contact contact1 = new Contact("Jerry");
56
         Contact contact1 = new Contact("Jerry");
57
+
58
+    // Add phone number to contact
59
+    // Remove number
55
         contact1.addPhoneNumber("89089");
60
         contact1.addPhoneNumber("89089");
61
+        contact1.removePhoneNumber("89089");
62
+
63
+    // Call getPhoneNumber method to check against
64
+        ArrayList actualRemovePhoneNumberTest = contact1.getPhoneNumbers();
65
+
66
+    // Expected:
67
+    // Create ArrayList to test/return empty ArrayList
68
+        ArrayList<String> expectedRemovePhoneNumberTest = new ArrayList<String>();
69
+
70
+
71
+        Assert.assertEquals(expectedRemovePhoneNumberTest, actualRemovePhoneNumberTest );
56
 
72
 
57
-        ArrayList<String> expectedPhoneNumbers = new ArrayList<String>();
58
-        expectedPhoneNumbers.remove("89089");
59
 
73
 
60
     }
74
     }
61
 
75
 

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

36
         testPhoneBook.addContact("Newman", "90980");
36
         testPhoneBook.addContact("Newman", "90980");
37
         testPhoneBook.addContact("Elaine", "432345");
37
         testPhoneBook.addContact("Elaine", "432345");
38
 
38
 
39
+        int actualNumberOfContacts = testPhoneBook.getNumberOfContacts();
39
         int expectedNumberOfContacts = 3;
40
         int expectedNumberOfContacts = 3;
40
-        //int actualNumberOfContacts =
41
+
42
+        Assert.assertEquals(expectedNumberOfContacts, actualNumberOfContacts);
43
+
41
     }
44
     }
42
 
45
 
43
     @Test
46
     @Test
46
         PhoneBook testPhoneBook = new PhoneBook();
49
         PhoneBook testPhoneBook = new PhoneBook();
47
         testPhoneBook.addContact("Madeline", "898098");
50
         testPhoneBook.addContact("Madeline", "898098");
48
 
51
 
49
-
50
-        ArrayList expectedLookupByNameResult = new ArrayList();
52
+        // Actual
51
         ArrayList actualLookupByNameResult = testPhoneBook.lookupByName("Madeline");
53
         ArrayList actualLookupByNameResult = testPhoneBook.lookupByName("Madeline");
52
 
54
 
55
+
56
+        // Expected
57
+        ArrayList<String> expectedLookupByNameResult = new ArrayList<String>();
58
+        expectedLookupByNameResult.add("898098");
59
+
60
+        Assert.assertEquals(expectedLookupByNameResult, actualLookupByNameResult);
61
+
62
+
53
     }
63
     }
54
 
64
 
55
     @Test
65
     @Test
56
     public void lookupByNumberTest() {
66
     public void lookupByNumberTest() {
57
 
67
 
58
         PhoneBook testPhoneBook = new PhoneBook();
68
         PhoneBook testPhoneBook = new PhoneBook();
69
+        testPhoneBook.addContact("Jerry", "43984029830");
59
 
70
 
71
+        String actualLookupByNumberResult = testPhoneBook.lookupByNumber("43984029830");
72
+        String expectedLookupByNumberResult = "Jerry";
60
 
73
 
61
-
74
+        Assert.assertEquals(expectedLookupByNumberResult, actualLookupByNumberResult);
62
 
75
 
63
     }
76
     }
64
 
77
 
73
         testPhoneBook.addContact(personNameToRemove, "23423");
86
         testPhoneBook.addContact(personNameToRemove, "23423");
74
         testPhoneBook.removeContact(personNameToRemove);
87
         testPhoneBook.removeContact(personNameToRemove);
75
 
88
 
76
-
77
-
78
         Assert.assertEquals(expectedListSize, testPhoneBook.getNumberOfContacts());
89
         Assert.assertEquals(expectedListSize, testPhoneBook.getNumberOfContacts());
79
     }
90
     }
80
 
91
 
81
     @Test
92
     @Test
82
     public void listAllContactsTest() {
93
     public void listAllContactsTest() {
83
-
94
+        // Given
84
         PhoneBook testPhoneBook = new PhoneBook();
95
         PhoneBook testPhoneBook = new PhoneBook();
85
-        testPhoneBook.addContact("Kramer", "23423");
86
-
87
-        Collection actualContactsList = testPhoneBook.listAllContacts();
88
-
89
-
90
-        // Actual
91
-        // Create object
92
-        Collection expectedContactsList = new ArrayList<Contact>();
93
-        Contact contact1 = new Contact("Kramer");
94
-
95
-
96
-        contact1.addPhoneNumber("23423");
97
-
98
-        // add contacts to expectedList
99
-        expectedContactsList.add(contact1);
100
-
101
-
102
-        Assert.assertEquals(expectedContactsList, actualContactsList);
103
-        }
104
-
96
+        Contact testContact = new Contact("Kramer");
97
+        testPhoneBook.addContact(testContact);
105
 
98
 
99
+        // When
100
+        Collection contacts = testPhoneBook.listAllContacts();
101
+        boolean outcome = contacts.contains(testContact);
106
 
102
 
107
 
103
 
104
+        // Then
105
+        Assert.assertTrue(outcome);
108
     }
106
     }
109
 
107
 
108
+}
109
+
110
 
110
 
111
-    //addContact ---- done
112
-    //removeContact ----- done
113
-    //lookupByName ----- done
114
-    //lookupByNumber
115
-    //addPhoneNumber ---- done
116
-    //removePhoneNumber ---- done
117
-    //list all entries (names & phone numbers) ----- done
118
-
119
-
120
-//    @Test
121
-//    public void testGetName() {
122
-//        // Given
123
-//        String expectedName = "Bob";
124
-//
125
-//
126
-//        // When
127
-//        Person person = new Person("Bob", ;
128
-//
129
-//        // Then
130
-//        String actualName = person.getName();
131
-//        Assert.assertEquals(expectedName, actualName);
132
-//
133
-//    }
134
-
135
-
136
-    //    @Test
137
-//    public void testGetPhoneNumber() {
138
-//        // Given
139
-//        String expectedName = "Madeline";
140
-//        String expectedPhoneNumber = "123";
141
-//
142
-//        // When
143
-//        Person person = new Person(expectedName, expectedPhoneNumber);
144
-//
145
-//        // Then
146
-//        String actualPhoneNumber = person.getPhoneNumber();
147
-//        String actualName = person.getName();
148
-//
149
-//        Assert.assertEquals(expectedPhoneNumber, actualPhoneNumber);
150
-//        Assert.assertEquals(expectedName, actualName);
151
-//    }
152
-//
153
-
154
-//
155
-//
156
-//
157
-//    @Test
158
-//    public void testLookup() {
159
-//        PhoneBook testPB = new PhoneBook();
160
-//        testPB.addPerson("bob", "123");
161
-//
162
-//        String actualPhoneNumber = testPB.lookupPhoneNumber("Bob");
163
-//        Assert.assertEquals("123", actualPhoneNumber);
164
-//
165
-//    }
166
 
111
 
167
 
112