|
@@ -1,7 +1,90 @@
|
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
|
+import java.util.Arrays;
|
|
8
|
+
|
3
|
9
|
/**
|
4
|
10
|
* Created by leon on 1/23/18.
|
5
|
11
|
*/
|
6
|
12
|
public class PhoneBookTest {
|
|
13
|
+
|
|
14
|
+ private static PhoneBook phonebook;
|
|
15
|
+
|
|
16
|
+ @Before
|
|
17
|
+ public void setup() {
|
|
18
|
+ this.phonebook = new PhoneBook() ;
|
|
19
|
+ }
|
|
20
|
+
|
|
21
|
+ @Test
|
|
22
|
+ public void testDefaultConstructor() {
|
|
23
|
+ Assert.assertNotNull(this.phonebook);
|
|
24
|
+ }
|
|
25
|
+
|
|
26
|
+ @Test
|
|
27
|
+ public void testLookup() {
|
|
28
|
+ Person expectedPerson = new Person("Jane", "(111) 222-3333");
|
|
29
|
+ this.phonebook.addEntry("Jane", "(111) 222-3333");
|
|
30
|
+
|
|
31
|
+ String expectedPersonName = expectedPerson.getName();
|
|
32
|
+ String expectedPersonPhoneNumber = expectedPerson.getPhoneNumber();
|
|
33
|
+
|
|
34
|
+ boolean actualPersonName = this.phonebook.hashMap.containsKey("Jane");
|
|
35
|
+ boolean actualPhoneNumber = this.phonebook.hashMap.containsValue(this.phonebook.hashMap.get("Jane"));
|
|
36
|
+
|
|
37
|
+ Assert.assertTrue(actualPersonName);
|
|
38
|
+ Assert.assertTrue(actualPhoneNumber);
|
|
39
|
+ }
|
|
40
|
+
|
|
41
|
+ @Test
|
|
42
|
+ public void testAddEntry() {
|
|
43
|
+ this.phonebook.addEntry("Adam", "(222) 333-4444");
|
|
44
|
+
|
|
45
|
+ boolean actualPersonName = this.phonebook.hashMap.containsKey("Adam");
|
|
46
|
+ boolean actualPhoneNumber = this.phonebook.hashMap.containsValue(this.phonebook.hashMap.get("Adam"));
|
|
47
|
+
|
|
48
|
+ Assert.assertTrue(actualPersonName);
|
|
49
|
+ Assert.assertTrue(actualPhoneNumber);
|
|
50
|
+ }
|
|
51
|
+
|
|
52
|
+ @Test
|
|
53
|
+ public void testRemoveEntry() {
|
|
54
|
+ this.phonebook.addEntry("Bob", "(333) 444-5555");
|
|
55
|
+ this.phonebook.removeEntry("Bob");
|
|
56
|
+
|
|
57
|
+ boolean actualPersonName = this.phonebook.hashMap.containsKey("Bob");
|
|
58
|
+ boolean actualPersonObject = this.phonebook.hashMap.containsValue(this.phonebook.hashMap.get("Bob"));
|
|
59
|
+
|
|
60
|
+ Assert.assertFalse(actualPersonName);
|
|
61
|
+ Assert.assertFalse(actualPersonObject);
|
|
62
|
+ }
|
|
63
|
+
|
|
64
|
+ @Test
|
|
65
|
+ public void testGetEntryList() {
|
|
66
|
+ this.phonebook.addEntry("Ava", "(000) 111-2222");
|
|
67
|
+ this.phonebook.addEntry("Brian", "(222) 333-4444");
|
|
68
|
+ this.phonebook.addEntry("Charlie", "(444) 555-6666");
|
|
69
|
+ this.phonebook.addEntry("David", "(666) 777-8888");
|
|
70
|
+ this.phonebook.addEntry("Edward", "(777) 888-9999");
|
|
71
|
+ this.phonebook.addEntry("Frank", "(888) 999-0000");
|
|
72
|
+
|
|
73
|
+ Assert.assertNotNull(this.phonebook.getEntryList());
|
|
74
|
+
|
|
75
|
+ /*
|
|
76
|
+ this.phonebook.removeEntry("Bob");
|
|
77
|
+
|
|
78
|
+ boolean actualPersonName = this.phonebook.hashMap.containsKey("Bob");
|
|
79
|
+ boolean actualPersonObject = this.phonebook.hashMap.containsValue(this.phonebook.hashMap.get("Bob"));
|
|
80
|
+
|
|
81
|
+ Assert.assertFalse(actualPersonName);
|
|
82
|
+ Assert.assertFalse(actualPersonObject);
|
|
83
|
+ */
|
|
84
|
+ }
|
|
85
|
+
|
7
|
86
|
}
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
|