Browse Source

Part 2 finished and testing

Luis Romero 6 years ago
parent
commit
19d376e1a6

+ 8
- 2
src/main/java/com/zipcodewilmington/phonebook/PhoneBook.java View File

@@ -41,8 +41,14 @@ public class PhoneBook {
41 41
     }
42 42
 
43 43
     //PART II
44
-    public String reverseLookup() { //lookup names from phone numbers
45
-        return "null";
44
+    public String reverseLookup(String phoneNumber) { //lookup names from phone numbers
45
+        for (String name : hashMap.keySet()) {
46
+            if (hashMap.get(name).getPhoneNumber() == phoneNumber) {
47
+                return name;
48
+                //break;
49
+            }
50
+        }
51
+        return "No_name";
46 52
     }
47 53
 
48 54
     //PART III

+ 33
- 5
src/test/java/com/zipcodewilmington/phonebook/PhoneBookTest.java View File

@@ -19,12 +19,12 @@ public class PhoneBookTest {
19 19
     }
20 20
 
21 21
     @Test
22
-    public void testDefaultConstructor() {
22
+    public void defaultConstructorTest() {
23 23
         Assert.assertNotNull(this.phonebook);
24 24
     }
25 25
 
26 26
     @Test
27
-    public void testLookup() {
27
+    public void lookupTest() {
28 28
         Person expectedPerson = new Person("Jane", "(111) 222-3333");
29 29
         this.phonebook.addEntry("Jane", "(111) 222-3333");
30 30
 
@@ -39,7 +39,7 @@ public class PhoneBookTest {
39 39
     }
40 40
 
41 41
     @Test
42
-    public void testAddEntry() {
42
+    public void addEntryTest() {
43 43
         this.phonebook.addEntry("Adam", "(222) 333-4444");
44 44
 
45 45
         boolean actualPersonName = this.phonebook.hashMap.containsKey("Adam");
@@ -50,7 +50,7 @@ public class PhoneBookTest {
50 50
     }
51 51
 
52 52
     @Test
53
-    public void testRemoveEntry() {
53
+    public void removeEntryTest() {
54 54
         this.phonebook.addEntry("Bob", "(333) 444-5555");
55 55
         this.phonebook.removeEntry("Bob");
56 56
 
@@ -62,7 +62,7 @@ public class PhoneBookTest {
62 62
     }
63 63
 
64 64
     @Test
65
-    public void testGetEntryList() {
65
+    public void getEntryListTest() {
66 66
         this.phonebook.addEntry("Ava", "(000) 111-2222");
67 67
         this.phonebook.addEntry("Brian", "(222) 333-4444");
68 68
         this.phonebook.addEntry("Charlie", "(444) 555-6666");
@@ -83,6 +83,34 @@ public class PhoneBookTest {
83 83
         */
84 84
     }
85 85
 
86
+    @Test
87
+    public void reverseLookupTest() {
88
+
89
+        // This method should allow you to look up names by the phone number associated with them.
90
+
91
+        // Given
92
+        String givenPhoneNumber = "(000) 111-2222";
93
+
94
+        // When
95
+        this.phonebook.addEntry("Ava", "(000) 111-2222");
96
+        Person expectedPerson = new Person("Ava", "(000) 111-2222");
97
+
98
+        String expectedName = "Ava";
99
+        String expectedPhoneNumber = "(000) 111-2222";
100
+
101
+        String actualNameFromPerson = expectedPerson.getName();
102
+        String actualPhoneNumberFromPerson = expectedPerson.getPhoneNumber();
103
+
104
+        String actualNameFromPhoneBook = "Ava";
105
+        String actualPhoneNumberFromPhoneBook = this.phonebook.hashMap.get(actualNameFromPhoneBook).getPhoneNumber();
106
+
107
+        Assert.assertEquals(expectedName, this.phonebook.reverseLookup(givenPhoneNumber));
108
+        // Then
109
+
110
+
111
+
112
+    }
113
+
86 114
 }
87 115
 
88 116