Browse Source

Testing more methods

Kibret Tecle 6 years ago
parent
commit
6573d6a8ba

+ 7
- 3
src/main/java/com/zipcodewilmington/phonebook/PhoneBook.java View File

59
         }
59
         }
60
 
60
 
61
         public String listNamesAndNumbers(){
61
         public String listNamesAndNumbers(){
62
-        Set<String>PhoneBookList = phoneBook.keySet();
63
-            for (String nameKeys:phoneBookList) {
64
-                namesAndNumbers+=nameKeys + "   "+phoneBook.get(nameKeys)+ "\n";
62
+            if(phoneBook.isEmpty()){
63
+                return null;
64
+            }else {
65
+                Set<String> PhoneBookList = phoneBook.keySet();
66
+                for (String nameKeys : phoneBookList) {
67
+                    namesAndNumbers += nameKeys + "   " + phoneBook.get(nameKeys) + "\n";
68
+                }
65
             }
69
             }
66
 
70
 
67
         return namesAndNumbers;
71
         return namesAndNumbers;

+ 15
- 4
src/test/java/com/zipcodewilmington/phonebook/PhoneBookTest.java View File

37
         String actual = phoneBookRecord.lookup("Micheal");
37
         String actual = phoneBookRecord.lookup("Micheal");
38
         Assert.assertEquals(expected, actual);
38
         Assert.assertEquals(expected, actual);
39
     }
39
     }
40
-    public void testlistNames(){
41
-        String expected = "John\n" +
42
-                            "Micheal\n"+
43
-                            "James\n";
40
+    @Test
41
+    public void testListNames(){
42
+        String expected = "James\n" +
43
+                            "John\n"+
44
+                            "Micheal\n";
44
         String actual = phoneBookRecord.listNames();
45
         String actual = phoneBookRecord.listNames();
45
         Assert.assertEquals(expected, actual);
46
         Assert.assertEquals(expected, actual);
46
 
47
 
47
     }
48
     }
49
+    @Test
50
+    public void testListNumbersAndNumbers(){
51
+        String expected = "James    "+ "1234554321\n"+
52
+                "John   "+"1234567890\n"+
53
+                "Micheal    "+"5678901234";
54
+        String actual =phoneBookRecord.listNamesAndNumbers();
55
+        Assert.assertEquals(expected, actual);
56
+    }
57
+
58
+
48
 }
59
 }