|
@@ -1,7 +1,136 @@
|
1
|
1
|
package com.zipcodewilmington.phonebook;
|
2
|
2
|
|
|
3
|
+import org.junit.Assert;
|
|
4
|
+import org.junit.Before;
|
|
5
|
+import org.junit.Test;
|
|
6
|
+
|
3
|
7
|
/**
|
4
|
8
|
* Created by leon on 1/23/18.
|
5
|
9
|
*/
|
6
|
10
|
public class PhoneBookTest {
|
|
11
|
+
|
|
12
|
+ private PhoneBook testPhoneBook;
|
|
13
|
+
|
|
14
|
+ @Before
|
|
15
|
+ public void createPhone(){
|
|
16
|
+ this.testPhoneBook = new PhoneBook();
|
|
17
|
+ }
|
|
18
|
+
|
|
19
|
+ @Test
|
|
20
|
+ public void testAddEntry(){
|
|
21
|
+ String number = "111111111";
|
|
22
|
+ String name = "Albert";
|
|
23
|
+ testPhoneBook.addEntry(name, number);
|
|
24
|
+ String actual = testPhoneBook.entryLookup(name);
|
|
25
|
+ String expected = "[111111111]";
|
|
26
|
+ Assert.assertEquals(expected, actual);
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+ }
|
|
30
|
+
|
|
31
|
+ @Test
|
|
32
|
+ public void testAddEntry1(){
|
|
33
|
+ String expected = null;
|
|
34
|
+ String name = "Albert";
|
|
35
|
+ testPhoneBook.addEntry(name, expected);
|
|
36
|
+ String actual = testPhoneBook.entryLookup(name);
|
|
37
|
+ Assert.assertFalse("You did not enter a number", false);
|
|
38
|
+ }
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+ @Test (expected = NullPointerException.class)
|
|
42
|
+ public void testRemoveEntry(){
|
|
43
|
+ String name = "Albert";
|
|
44
|
+ String number = "111111111";
|
|
45
|
+ testPhoneBook.removeEntry(name, number);
|
|
46
|
+ String actual = testPhoneBook.entryLookup(name);
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+ }
|
|
50
|
+
|
|
51
|
+ @Test (expected = NullPointerException.class)
|
|
52
|
+ public void testRemoveEntry1(){
|
|
53
|
+ String expected = "Albert";
|
|
54
|
+ String name = "Albert";
|
|
55
|
+ String number = "111111111";
|
|
56
|
+ testPhoneBook.removeEntry(name, number);
|
|
57
|
+ String actual = testPhoneBook.entryLookup(name);
|
|
58
|
+ }
|
|
59
|
+
|
|
60
|
+ @Test
|
|
61
|
+ public void testEntryLookup(){
|
|
62
|
+ String name = "Albert";
|
|
63
|
+ String number = "111111111";
|
|
64
|
+ testPhoneBook.addEntry("Albert", "111111111");
|
|
65
|
+ testPhoneBook.entryLookup(name);
|
|
66
|
+ String expected = "[111111111]";
|
|
67
|
+ String actual = testPhoneBook.entryLookup(name);
|
|
68
|
+ Assert.assertEquals(expected, actual);
|
|
69
|
+
|
|
70
|
+ }
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+ @Test
|
|
74
|
+ public void testEntryListNames(){
|
|
75
|
+ String name = "Albert";
|
|
76
|
+ String number = "111111111";
|
|
77
|
+ testPhoneBook.addEntry(name, number);
|
|
78
|
+ String name1 = "Bobby";
|
|
79
|
+ String number1 = "222222222";
|
|
80
|
+ testPhoneBook.addEntry(name1, number1);
|
|
81
|
+ String name2 = "Catherine";
|
|
82
|
+ String number2 = "333333333";
|
|
83
|
+ testPhoneBook.addEntry(name2, number2);
|
|
84
|
+
|
|
85
|
+ String expected = "[Albert, Bobby, Catherine]";
|
|
86
|
+ String actual = testPhoneBook.entryListNames();
|
|
87
|
+ Assert.assertEquals(expected, actual);
|
|
88
|
+
|
|
89
|
+ }
|
|
90
|
+
|
|
91
|
+// @Test
|
|
92
|
+// public void testEntryListNumbers(){
|
|
93
|
+//
|
|
94
|
+// }
|
|
95
|
+
|
|
96
|
+ @Test
|
|
97
|
+ public void testEntryListAll(){
|
|
98
|
+ String name = "Albert";
|
|
99
|
+ String number = "111111111";
|
|
100
|
+ testPhoneBook.addEntry(name, number);
|
|
101
|
+ String name1 = "Bobby";
|
|
102
|
+ String number1 = "222222222";
|
|
103
|
+ testPhoneBook.addEntry(name1, number1);
|
|
104
|
+ String name2 = "Catherine";
|
|
105
|
+ String number2 = "333333333";
|
|
106
|
+ testPhoneBook.addEntry(name2, number2);
|
|
107
|
+
|
|
108
|
+ String expected = "Albert : [111111111]\nBobby : [222222222]\nCatherine : [333333333]\n";
|
|
109
|
+ String actual = testPhoneBook.entryListAll();
|
|
110
|
+ Assert.assertEquals(expected, actual);
|
|
111
|
+ }
|
|
112
|
+
|
|
113
|
+ @Test
|
|
114
|
+ public void testReverseEntry(){
|
|
115
|
+ String name = "Albert";
|
|
116
|
+ String number = "111111111";
|
|
117
|
+ testPhoneBook.addEntry(name, number);
|
|
118
|
+ String expected = "Albert";
|
|
119
|
+ String actual = testPhoneBook.reverseLookup(number);
|
|
120
|
+ Assert.assertEquals(expected, actual);
|
|
121
|
+ }
|
|
122
|
+
|
|
123
|
+ @Test
|
|
124
|
+ public void testremoveOnePhoneNum(){
|
|
125
|
+ String name = "Albert";
|
|
126
|
+ String number = "111111111";
|
|
127
|
+ String number1 = "222222222";
|
|
128
|
+ testPhoneBook.addEntry(name, number, number1);
|
|
129
|
+ testPhoneBook.removeOneNumberfromEntry("Albert", "111111111");
|
|
130
|
+ String expected = "[222222222]";
|
|
131
|
+ String actual = testPhoneBook.entryLookup("Albert");
|
|
132
|
+ Assert.assertEquals(expected, actual);
|
|
133
|
+
|
|
134
|
+ }
|
|
135
|
+
|
7
|
136
|
}
|