|
@@ -1,7 +1,126 @@
|
1
|
1
|
package com.zipcodewilmington.phonebook;
|
2
|
2
|
|
3
|
|
-/**
|
4
|
|
- * Created by leon on 1/23/18.
|
5
|
|
- */
|
|
3
|
+import org.junit.Assert;
|
|
4
|
+import org.junit.Before;
|
|
5
|
+import org.junit.Test;
|
|
6
|
+
|
6
|
7
|
public class PhoneBookTest {
|
|
8
|
+
|
|
9
|
+ private static PhoneBook phoneBookTest;
|
|
10
|
+
|
|
11
|
+ @Before
|
|
12
|
+ public void createPhoneBook() {
|
|
13
|
+ this.phoneBookTest = new PhoneBook();
|
|
14
|
+ }
|
|
15
|
+
|
|
16
|
+ @Test
|
|
17
|
+ public void testAddEntry() {
|
|
18
|
+ String name = "Person 1";
|
|
19
|
+ String number = "1234567";
|
|
20
|
+ phoneBookTest.addEntry(name, number);
|
|
21
|
+ String expected = "[1234567]";
|
|
22
|
+ String actual = phoneBookTest.lookUp(name);
|
|
23
|
+ Assert.assertEquals(expected, actual);
|
|
24
|
+
|
|
25
|
+ }
|
|
26
|
+
|
|
27
|
+ @Test
|
|
28
|
+ public void testAddEntry2() {
|
|
29
|
+ String name = "Person 2";
|
|
30
|
+ String number = "87654321";
|
|
31
|
+ phoneBookTest.addEntry(name, number);
|
|
32
|
+ String expected = "[87654321]";
|
|
33
|
+ String actual = phoneBookTest.lookUp(name);
|
|
34
|
+ Assert.assertEquals(expected, actual);
|
|
35
|
+ }
|
|
36
|
+
|
|
37
|
+ @Test(expected = NullPointerException.class)
|
|
38
|
+ public void removeEntryTest() {
|
|
39
|
+ String name = "Person 1";
|
|
40
|
+ String number = "8942418";
|
|
41
|
+ phoneBookTest.addEntry(name, number);
|
|
42
|
+ phoneBookTest.removeEntry(name);
|
|
43
|
+ phoneBookTest.lookUp(name);
|
|
44
|
+
|
|
45
|
+ }
|
|
46
|
+
|
|
47
|
+ @Test(expected = NullPointerException.class)
|
|
48
|
+ public void removeEntryTest2() {
|
|
49
|
+ String name = "Person 2";
|
|
50
|
+ String number = "12387874";
|
|
51
|
+ phoneBookTest.addEntry(name, number);
|
|
52
|
+ phoneBookTest.removeEntry(name);
|
|
53
|
+ phoneBookTest.lookUp(name);
|
|
54
|
+ }
|
|
55
|
+
|
|
56
|
+ @Test
|
|
57
|
+ public void listNamesTest() {
|
|
58
|
+ String name = "Person 1";
|
|
59
|
+ String number = "1234567";
|
|
60
|
+ phoneBookTest.addEntry(name, number);
|
|
61
|
+ String name2 = "Person 2";
|
|
62
|
+ String number2 = "2345678";
|
|
63
|
+ phoneBookTest.addEntry(name2, number2);
|
|
64
|
+ String name3 = "Person 3";
|
|
65
|
+ String number3 = "34567898";
|
|
66
|
+ phoneBookTest.addEntry(name3, number3);
|
|
67
|
+ String expected = "[Person 1, Person 2, Person 3]";
|
|
68
|
+ String actual = phoneBookTest.listNames();
|
|
69
|
+ Assert.assertEquals(expected, actual);
|
|
70
|
+
|
|
71
|
+ }
|
|
72
|
+
|
|
73
|
+ @Test
|
|
74
|
+ public void listAllTest() {
|
|
75
|
+ String name = "Person 1";
|
|
76
|
+ String number = "1234567";
|
|
77
|
+ String name2 = "Person 2";
|
|
78
|
+ String number2 = "2345678";
|
|
79
|
+ String name3 = "Person 3";
|
|
80
|
+ String number3 = "34567898";
|
|
81
|
+ String number4 = "5343677";
|
|
82
|
+ phoneBookTest.addEntry(name, number);
|
|
83
|
+ phoneBookTest.addEntry(name2, number2);
|
|
84
|
+ phoneBookTest.addEntry(name3, number3, number4);
|
|
85
|
+ String expected = "Person 1[1234567]\nPerson 2[2345678]\nPerson 3[34567898, 5343677]\n";
|
|
86
|
+ System.out.println(expected);
|
|
87
|
+ String actual = phoneBookTest.listAll();
|
|
88
|
+ Assert.assertEquals(expected, actual);
|
|
89
|
+ }
|
|
90
|
+
|
|
91
|
+ @Test
|
|
92
|
+ public void reverseLookUpTest() {
|
|
93
|
+ String name = "Person 1";
|
|
94
|
+ String number = "1234567";
|
|
95
|
+ phoneBookTest.addEntry(name, number);
|
|
96
|
+ String expected = "Person 1";
|
|
97
|
+ String actual = phoneBookTest.reverseLookUp(number);
|
|
98
|
+ Assert.assertEquals(expected, actual);
|
|
99
|
+ }
|
|
100
|
+
|
|
101
|
+ @Test
|
|
102
|
+ public void reverseLookUpTest2() {
|
|
103
|
+ String name = null;
|
|
104
|
+ String number = null;
|
|
105
|
+ String expected = "That number is not in the phone book";
|
|
106
|
+ String actual = phoneBookTest.reverseLookUp(number);
|
|
107
|
+ Assert.assertEquals(expected, actual);
|
|
108
|
+
|
|
109
|
+ }
|
|
110
|
+
|
|
111
|
+ @Test
|
|
112
|
+ public void removeOneNumberTest() {
|
|
113
|
+ String name = "Brian";
|
|
114
|
+ String number = "1234567";
|
|
115
|
+ String number2 = "2345678";
|
|
116
|
+ String number3 = "3456789";
|
|
117
|
+ phoneBookTest.addEntry(name, number, number2, number3);
|
|
118
|
+ phoneBookTest.removeOneNumber(name, number2);
|
|
119
|
+ String expected = "[1234567, 3456789]";
|
|
120
|
+ String actual = phoneBookTest.lookUp(name);
|
|
121
|
+ Assert.assertEquals(expected, actual);
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+ }
|
|
125
|
+
|
7
|
126
|
}
|