Selaa lähdekoodia

close to being finished?

April Rivera 6 vuotta sitten
vanhempi
commit
8921904c4c

+ 12
- 0
pom.xml Näytä tiedosto

@@ -7,6 +7,18 @@
7 7
     <groupId>com.zipcodewilmington</groupId>
8 8
     <artifactId>phonebok</artifactId>
9 9
     <version>1.0-SNAPSHOT</version>
10
+    <dependencies>
11
+        <dependency>
12
+            <groupId>junit</groupId>
13
+            <artifactId>junit</artifactId>
14
+            <version>RELEASE</version>
15
+        </dependency>
16
+        <dependency>
17
+            <groupId>junit</groupId>
18
+            <artifactId>junit</artifactId>
19
+            <version>RELEASE</version>
20
+        </dependency>
21
+    </dependencies>
10 22
 
11 23
 
12 24
 </project>

+ 17
- 11
src/main/java/com/zipcodewilmington/phonebook/PhoneBook.java Näytä tiedosto

@@ -1,7 +1,8 @@
1 1
 package com.zipcodewilmington.phonebook;
2 2
 import java.util.Map;
3 3
 import java.util.Set;
4
-import java.util.HashMap;
4
+import java.util.SortedMap;
5
+import java.util.TreeMap;
5 6
 
6 7
 /**
7 8
  * Created by leon on 1/23/18.
@@ -15,7 +16,7 @@ public class PhoneBook {
15 16
     private Map<String, String> contactsList;
16 17
 
17 18
     public PhoneBook(){
18
-        this.contactsList = new HashMap<String, String>();
19
+        this.contactsList = new TreeMap<String, String>();
19 20
         contactsList.put("Pete Jones", "2678849087");
20 21
         contactsList.put("Ron Burgundy", "5604329932");
21 22
         contactsList.put("Nala Bits", "2345578122");
@@ -23,6 +24,7 @@ public class PhoneBook {
23 24
     }
24 25
     public Map<String, String> getContactsList(){
25 26
         return contactsList;
27
+
26 28
     }
27 29
 
28 30
     public void addContact(String name, String number) {
@@ -47,17 +49,21 @@ public class PhoneBook {
47 49
         return contactsList.get(name) == null ? "Sorry name not found" : contactsList.get(name);
48 50
     }
49 51
 
50
-    public void listAllByName(String name){
51
-        for(String ContactsByName : contactsList.keySet()){
52
-            System.out.println(contactsList.get(name));
52
+    public String listAllByName(String strings) {
53
+        Set nameSet = contactsList.keySet();
54
+        for (Object names : nameSet) {
55
+            return names.toString();
53 56
         }
54 57
 
55
-    }
56
-    public void listAllNamesAndNumbers(){
57
-        Set<Map.Entry<String, String>>listingAll = contactsList.entrySet();
58
-        System.out.println(contactsList);
59
-    }
60 58
 
61
-}
59
+    public String listAllNamesAndNumbers(){
60
+            Set listingAll = contactsList.entrySet();
61
+            for (Object allEntries : listingAll )
62
+            return allEntries.toString();
62 63
 
64
+        }
65
+    }
63 66
 }
67
+
68
+
69
+

+ 20
- 4
src/test/java/com/zipcodewilmington/phonebook/PhoneBookTest.java Näytä tiedosto

@@ -1,5 +1,12 @@
1 1
 package com.zipcodewilmington.phonebook;
2 2
 
3
+import org.junit.Assert;
4
+import org.junit.Before;
5
+import org.junit.Test;
6
+
7
+
8
+
9
+
3 10
 /**
4 11
  * Created by leon on 1/23/18.
5 12
  */
@@ -17,14 +24,14 @@ public class PhoneBookTest {
17 24
     public void testAddContact(){
18 25
         phoneBook.addContact("Genya", "6578356767");
19 26
         boolean genyaIsInPhoneBook = phoneBook.getContactsList().keySet().contains("Genya");
20
-        assertTrue(genyaIsInPhoneBook);
27
+        Assert.assertTrue(genyaIsInPhoneBook);
21 28
 
22 29
     }
23 30
     @Test
24 31
     public void testRemoveContact(){
25 32
         phoneBook.removeContact("Pete Jones");
26 33
         boolean peteJonesHasBeenRemoved = !phoneBook.getContactsList().containsKey("Pete Jones");
27
-        assertTrue(peteJonesHasBeenRemoved);
34
+        Assert.assertTrue(peteJonesHasBeenRemoved);
28 35
     }
29 36
     @Test
30 37
     public void testLookUpContactByName(){
@@ -35,9 +42,18 @@ public class PhoneBookTest {
35 42
     }
36 43
     @Test
37 44
     public void testListAllByName(){
38
-
45
+        phoneBook.listAllByName(phoneBook.getContactsList().keySet().toString());
46
+        String expected = ;
47
+        String actual = phoneBook.getContactsList().keySet().toString();
48
+        Assert.assertEquals(expected, actual);
39 49
     }
40 50
 
51
+    @Test
52
+    public void testListAllNamesAndNumbers(){
53
+        phoneBook.listAllNamesAndNumber();
54
+        String expected = ;
55
+        String actual = phoneBook.getContactsList().entrySet();
56
+        Assert.assertEquals(expected, actual);
57
+    }
41 58
 }
42 59
 
43
-}