|
@@ -1,7 +1,121 @@
|
1
|
1
|
package com.zipcodewilmington.phonebook;
|
2
|
2
|
|
|
3
|
+import org.junit.After;
|
|
4
|
+import org.junit.Assert;
|
|
5
|
+import org.junit.Before;
|
|
6
|
+import org.junit.Test;
|
|
7
|
+
|
|
8
|
+
|
3
|
9
|
/**
|
4
|
10
|
* Created by leon on 1/23/18.
|
5
|
11
|
*/
|
|
12
|
+
|
|
13
|
+
|
6
|
14
|
public class PhoneBookTest {
|
|
15
|
+
|
|
16
|
+ @Before
|
|
17
|
+ public void setUp() {
|
|
18
|
+
|
|
19
|
+ }
|
|
20
|
+
|
|
21
|
+ @After
|
|
22
|
+ public void tearDown() {
|
|
23
|
+ }
|
|
24
|
+
|
|
25
|
+ @Test
|
|
26
|
+ public void testLookup() {
|
|
27
|
+ PhoneBook phoneBookTest = new PhoneBook();
|
|
28
|
+ phoneBookTest.add("James", "555555555");
|
|
29
|
+ phoneBookTest.add("Charles", "2026783422");
|
|
30
|
+
|
|
31
|
+ String actual = phoneBookTest.lookup("Charles");
|
|
32
|
+ Assert.assertEquals("2026783422 ", actual);
|
|
33
|
+ }
|
|
34
|
+
|
|
35
|
+ @Test
|
|
36
|
+ public void testListNames() {
|
|
37
|
+ PhoneBook phoneBookTest = new PhoneBook();
|
|
38
|
+ phoneBookTest.add("John", "1234567890");
|
|
39
|
+ phoneBookTest.add("James", "555555555");
|
|
40
|
+ String expected = "James\n" +
|
|
41
|
+ "John\n";
|
|
42
|
+ String actual = phoneBookTest.listNames();
|
|
43
|
+ Assert.assertEquals(expected, actual);
|
|
44
|
+
|
|
45
|
+ }
|
|
46
|
+
|
|
47
|
+ @Test
|
|
48
|
+ public void testListNumbersAndNumbers() {
|
|
49
|
+ PhoneBook phoneBookTest = new PhoneBook();
|
|
50
|
+ phoneBookTest.add("John", "1234567890");
|
|
51
|
+ phoneBookTest.add("James", "5555555555");
|
|
52
|
+ phoneBookTest.add("James", "6666666666");
|
|
53
|
+ phoneBookTest.add("Mike", "5678901234");
|
|
54
|
+ String expected = "James==>" + "5555555555,6666666666,\n" +
|
|
55
|
+ "John==>" + "1234567890,\n" +
|
|
56
|
+ "Mike==>" + "5678901234,\n";
|
|
57
|
+ String actual = phoneBookTest.listNamesAndNumbers();
|
|
58
|
+ Assert.assertEquals(expected, actual);
|
|
59
|
+ }
|
|
60
|
+
|
|
61
|
+ @Test
|
|
62
|
+ public void testAdd() {
|
|
63
|
+ PhoneBook phoneBookTest = new PhoneBook();
|
|
64
|
+ boolean expected = true;
|
|
65
|
+ boolean actual = phoneBookTest.add("Peter", "7777777777");
|
|
66
|
+ Assert.assertEquals(expected, actual);
|
|
67
|
+
|
|
68
|
+ }
|
|
69
|
+
|
|
70
|
+ @Test
|
|
71
|
+ public void testRemove() {
|
|
72
|
+ PhoneBook phoneBookTest = new PhoneBook();
|
|
73
|
+ phoneBookTest.add("John", "1234567890");
|
|
74
|
+ phoneBookTest.add("Peter", "7777777777");
|
|
75
|
+ String ListPreRemoving = "John==>1234567890,\n" +
|
|
76
|
+ "Peter==>7777777777,\n";
|
|
77
|
+ phoneBookTest.remove("John");
|
|
78
|
+ String postRemoving = "Peter==>7777777777,\n";
|
|
79
|
+ String expected = postRemoving;
|
|
80
|
+ String actual = phoneBookTest.listNamesAndNumbers();
|
|
81
|
+ Assert.assertEquals(expected, actual);
|
|
82
|
+ }
|
|
83
|
+
|
|
84
|
+ @Test
|
|
85
|
+ public void testReverseLookup() {
|
|
86
|
+ PhoneBook phoneBookTest = new PhoneBook();
|
|
87
|
+ phoneBookTest.add("James", "555555555");
|
|
88
|
+
|
|
89
|
+ String actual = phoneBookTest.reverseLookUp("555555555");
|
|
90
|
+ Assert.assertEquals("James", actual);
|
|
91
|
+ }
|
|
92
|
+
|
|
93
|
+ @Test
|
|
94
|
+ public void testRemoveIndividualNumbers() {
|
|
95
|
+ PhoneBook phonebookeTest = new PhoneBook();
|
|
96
|
+ phonebookeTest.add("James", "2222222222");
|
|
97
|
+ phonebookeTest.add("James", "3333333333");
|
|
98
|
+
|
|
99
|
+ String expected = "James==>3333333333,\n";
|
|
100
|
+ phonebookeTest.removeIndividualNumbers("James", "2222222222");
|
|
101
|
+
|
|
102
|
+ String actual = phonebookeTest.listNamesAndNumbers();
|
|
103
|
+ Assert.assertEquals(expected, actual);
|
|
104
|
+ }
|
|
105
|
+
|
|
106
|
+ @Test
|
|
107
|
+ public void testRemoveRecord() {
|
|
108
|
+ PhoneBook phoneBookTest = new PhoneBook();
|
|
109
|
+ phoneBookTest.add("Efrem", "1234567890");
|
|
110
|
+ phoneBookTest.add("Brhane", "1010101010");
|
|
111
|
+
|
|
112
|
+ phoneBookTest.removeRecord();
|
|
113
|
+
|
|
114
|
+ String expected = "";
|
|
115
|
+ String actual = phoneBookTest.listNamesAndNumbers();
|
|
116
|
+
|
|
117
|
+ Assert.assertEquals(expected, actual);
|
|
118
|
+ }
|
|
119
|
+
|
|
120
|
+
|
7
|
121
|
}
|