|
@@ -1,7 +1,106 @@
|
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.TreeMap;
|
3
|
8
|
/**
|
4
|
9
|
* Created by leon on 1/23/18.
|
5
|
10
|
*/
|
|
11
|
+
|
6
|
12
|
public class PhoneBookTest {
|
|
13
|
+
|
|
14
|
+ PhoneBook testbook;
|
|
15
|
+ @Before
|
|
16
|
+ public void setUp(){
|
|
17
|
+ testbook = new PhoneBook();
|
|
18
|
+ }
|
|
19
|
+
|
|
20
|
+ @Test
|
|
21
|
+ public void testPhoneBookAddName() {
|
|
22
|
+ // Given
|
|
23
|
+ PhoneBook testbook = new PhoneBook();
|
|
24
|
+ PhoneNumberStorage temp = new PhoneNumberStorage("Keith", "555-666-7777");
|
|
25
|
+ testbook.addName("Keith", temp);
|
|
26
|
+
|
|
27
|
+ PhoneNumberStorage testNumber = testbook.lookup("Keith");
|
|
28
|
+ Assert.assertTrue(testNumber.equals(temp));
|
|
29
|
+
|
|
30
|
+ }
|
|
31
|
+@Test
|
|
32
|
+ public void testPhoneBookDelete(){
|
|
33
|
+ PhoneBook testbook = new PhoneBook();
|
|
34
|
+ testbook.addName("Keith", "555-666-7777");
|
|
35
|
+ testbook.deleter("Keith");
|
|
36
|
+ PhoneNumberStorage temp = testbook.lookup("Keith");
|
|
37
|
+ Assert.assertNull(temp );
|
|
38
|
+ }
|
|
39
|
+@Test
|
|
40
|
+ public void testPhoneBookLookUp(){
|
|
41
|
+ PhoneBook testbook = new PhoneBook();
|
|
42
|
+ PhoneNumberStorage temp = new PhoneNumberStorage("Keith", "555-666-7777");
|
|
43
|
+ testbook.addName("Keith", temp);
|
|
44
|
+ PhoneNumberStorage actual = testbook.lookup("Keith");
|
|
45
|
+ Assert.assertEquals(actual, temp);
|
|
46
|
+ }
|
|
47
|
+
|
|
48
|
+ @Test
|
|
49
|
+ public void testPhoneBookList(){
|
|
50
|
+
|
|
51
|
+ PhoneBook testbook = new PhoneBook();
|
|
52
|
+ testbook.addName("Keith", "555-666-7777");
|
|
53
|
+ testbook.addName("John", "555-612-7777");
|
|
54
|
+ testbook.addName("Mike", "555-623-7777");
|
|
55
|
+ testbook.addName("Steve", "555-645-7777");
|
|
56
|
+
|
|
57
|
+ String expected = "John 555-612-7777\n" +
|
|
58
|
+ "Keith 555-666-7777\n" +
|
|
59
|
+ "Mike 555-623-7777\n" +
|
|
60
|
+ "Steve 555-645-7777\n";
|
|
61
|
+ String actual = testbook.listNamesAndNumbers();
|
|
62
|
+ Assert.assertEquals(expected, actual);
|
|
63
|
+ }
|
|
64
|
+
|
|
65
|
+ @Test
|
|
66
|
+ public void testPhoneBookNames(){
|
|
67
|
+
|
|
68
|
+ PhoneBook testbook = new PhoneBook();
|
|
69
|
+ testbook.addName("Keith", "555-666-7777");
|
|
70
|
+ testbook.addName("John", "555-612-7777");
|
|
71
|
+ testbook.addName("Mike", "555-623-7777");
|
|
72
|
+ testbook.addName("Steve", "555-645-7777");
|
|
73
|
+
|
|
74
|
+ String expected = "John\n" +
|
|
75
|
+ "Keith\n" +
|
|
76
|
+ "Mike\n" +
|
|
77
|
+ "Steve\n";
|
|
78
|
+ String actual = testbook.listNames();
|
|
79
|
+ Assert.assertEquals(expected, actual);
|
|
80
|
+ }
|
|
81
|
+ @Test
|
|
82
|
+ public void testPhoneBookReverseLookUp() {
|
|
83
|
+ PhoneBook testbook = new PhoneBook();
|
|
84
|
+
|
|
85
|
+ testbook.addName("Keith", "555-666-7777");
|
|
86
|
+ testbook.addName("John", "555-612-7777");
|
|
87
|
+ testbook.addName("Mike", "555-623-7777");
|
|
88
|
+ testbook.addName("Steve", "555-645-7777");
|
|
89
|
+ String testnumber = testbook.reverselookup("555-666-7777");
|
|
90
|
+ Assert.assertEquals("Keith", testnumber);
|
|
91
|
+ }
|
|
92
|
+
|
|
93
|
+ @Test
|
|
94
|
+ public void testPhoneBookAddMultiple() {
|
|
95
|
+ // Given
|
|
96
|
+ PhoneBook testbook = new PhoneBook();
|
|
97
|
+ PhoneNumberStorage temp = new PhoneNumberStorage("Keith", "555-666-7777", "555-000-8888");
|
|
98
|
+ testbook.addName("Keith", temp);
|
|
99
|
+
|
|
100
|
+ PhoneNumberStorage testNumber = testbook.lookup("Keith");
|
|
101
|
+ Assert.assertTrue(testNumber.equals(temp));
|
|
102
|
+
|
|
103
|
+ }
|
|
104
|
+
|
|
105
|
+
|
7
|
106
|
}
|