|
@@ -1,7 +1,77 @@
|
1
|
1
|
package com.zipcodewilmington.phonebook;
|
2
|
2
|
|
|
3
|
+import com.sun.xml.internal.ws.policy.AssertionSet;
|
|
4
|
+import org.junit.*;
|
|
5
|
+
|
|
6
|
+import java.util.ArrayList;
|
|
7
|
+import java.util.TreeMap;
|
|
8
|
+
|
3
|
9
|
/**
|
4
|
10
|
* Created by leon on 1/23/18.
|
5
|
11
|
*/
|
6
|
12
|
public class PhoneBookTest {
|
|
13
|
+ PhoneBook testPhoneBook;
|
|
14
|
+ @Before
|
|
15
|
+ public void setup (){
|
|
16
|
+ testPhoneBook = new PhoneBook();
|
|
17
|
+ }
|
|
18
|
+
|
|
19
|
+ private TreeMap<String, String> phoneBook = new TreeMap<String, String>();
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+ @Test
|
|
23
|
+ public void testlookUpNameToGetAccompanyingPhoneNumber() {
|
|
24
|
+ testPhoneBook.addEntry("Rodrigo", "233-123-3445");
|
|
25
|
+ testPhoneBook.addEntry("Elena", "234-123-3344");
|
|
26
|
+ testPhoneBook.addEntry("Robert", "332-233-7821");
|
|
27
|
+ String expected = "332-233-7821";
|
|
28
|
+ String actual = testPhoneBook.lookupNameToGetAccompanyingPhoneNumber("Robert").get(0);
|
|
29
|
+ Assert.assertEquals("should return Robert's phone number", expected, actual);
|
|
30
|
+
|
|
31
|
+ }
|
|
32
|
+ @Test
|
|
33
|
+ public void testAddEntry() {
|
|
34
|
+ testPhoneBook.addEntry("Rodrigo", "233-123-3445");
|
|
35
|
+ String expected = "233-123-3445";
|
|
36
|
+ String actual = testPhoneBook.lookupNameToGetAccompanyingPhoneNumber("Rodrigo").get(0);
|
|
37
|
+ Assert.assertEquals(actual, expected);
|
|
38
|
+ }
|
|
39
|
+ @Test
|
|
40
|
+ public void testRemoveEntry(){
|
|
41
|
+ testPhoneBook.addEntry("Rodrigo", "233-123-3445");
|
|
42
|
+ testPhoneBook.addEntry("Elena", "234-123-3344");
|
|
43
|
+ testPhoneBook.addEntry("Robert", "332-233-7821");
|
|
44
|
+ String actual =testPhoneBook.removeEntry("Robert");
|
|
45
|
+ String name = "Robert";
|
|
46
|
+ String expected = null;
|
|
47
|
+ Assert.assertEquals(expected, actual);
|
|
48
|
+
|
|
49
|
+ }
|
|
50
|
+ @Test
|
|
51
|
+ public void testListNames() {
|
|
52
|
+ testPhoneBook.addEntry("Rodrigo", "233-123-3445");
|
|
53
|
+ testPhoneBook.addEntry("Elena", "234-123-3344");
|
|
54
|
+ testPhoneBook.addEntry("Robert", "332-233-7821");
|
|
55
|
+ System.out.println(testPhoneBook.listNames());
|
|
56
|
+ }
|
|
57
|
+
|
|
58
|
+ @Test
|
|
59
|
+ public void testListNamesandNumbers() {
|
|
60
|
+ testPhoneBook.addEntry("Rodrigo", "233-123-3445");
|
|
61
|
+ testPhoneBook.addEntry("Elena", "234-123-3344");
|
|
62
|
+ testPhoneBook.addEntry("Robert", "332-233-7821");
|
|
63
|
+ System.out.println(testPhoneBook.listNamesAndNumbers());
|
|
64
|
+ }
|
|
65
|
+
|
|
66
|
+ @Test
|
|
67
|
+ public void testReverseLookup() {
|
|
68
|
+ testPhoneBook.addEntry("Rodrigo", "233-123-3445");
|
|
69
|
+ testPhoneBook.addEntry("Elena", "234-123-3344");
|
|
70
|
+ testPhoneBook.addEntry("Robert", "332-233-7821");
|
|
71
|
+ String actual= testPhoneBook.reverseLookup("234-123-3344");
|
|
72
|
+ String expected = "Elena";
|
|
73
|
+ Assert.assertEquals("should return who the phone number is assigned to ", expected, actual);
|
|
74
|
+ }
|
7
|
75
|
}
|
|
76
|
+
|
|
77
|
+
|