|
@@ -5,24 +5,16 @@ import org.junit.Assert;
|
5
|
5
|
import org.junit.Before;
|
6
|
6
|
import org.junit.Test;
|
7
|
7
|
|
8
|
|
-import java.util.List;
|
9
|
|
-import java.util.Map;
|
10
|
|
-import java.util.TreeMap;
|
11
|
8
|
|
12
|
9
|
/**
|
13
|
10
|
* Created by leon on 1/23/18.
|
14
|
11
|
*/
|
15
|
12
|
|
16
|
13
|
|
17
|
|
-
|
18
|
|
-
|
19
|
14
|
public class PhoneBookTest {
|
20
|
|
- private static PhoneBook phoneBookTest;
|
21
|
15
|
|
22
|
|
- @Before
|
23
|
|
- public void setUp() {
|
24
|
|
- PhoneBook phoneBookTest = new PhoneBook();
|
25
|
|
- phoneBookTest.add("John","1234567890");
|
|
16
|
+ @Before
|
|
17
|
+ public void setUp() {
|
26
|
18
|
|
27
|
19
|
}
|
28
|
20
|
|
|
@@ -31,62 +23,99 @@ public class PhoneBookTest {
|
31
|
23
|
}
|
32
|
24
|
|
33
|
25
|
@Test
|
34
|
|
- public void testLookup() {
|
|
26
|
+ public void testLookup() {
|
35
|
27
|
PhoneBook phoneBookTest = new PhoneBook();
|
36
|
|
- phoneBookTest.add("James","555555555");
|
|
28
|
+ phoneBookTest.add("James", "555555555");
|
|
29
|
+ phoneBookTest.add("Charles", "2026783422");
|
37
|
30
|
|
38
|
|
- String actual = phoneBookTest.lookup("John");
|
39
|
|
- Assert.assertEquals("555555555 ",actual);
|
|
31
|
+ String actual = phoneBookTest.lookup("Charles");
|
|
32
|
+ Assert.assertEquals("2026783422 ", actual);
|
40
|
33
|
}
|
|
34
|
+
|
41
|
35
|
@Test
|
42
|
|
- public void testListNames(){
|
|
36
|
+ public void testListNames() {
|
43
|
37
|
PhoneBook phoneBookTest = new PhoneBook();
|
44
|
|
- phoneBookTest.add("John","1234567890");
|
45
|
|
- phoneBookTest.add("James","555555555");
|
|
38
|
+ phoneBookTest.add("John", "1234567890");
|
|
39
|
+ phoneBookTest.add("James", "555555555");
|
46
|
40
|
String expected = "James\n" +
|
47
|
|
- "John\n";
|
|
41
|
+ "John\n";
|
48
|
42
|
String actual = phoneBookTest.listNames();
|
49
|
43
|
Assert.assertEquals(expected, actual);
|
50
|
44
|
|
51
|
45
|
}
|
|
46
|
+
|
52
|
47
|
@Test
|
53
|
|
- public void testListNumbersAndNumbers(){
|
|
48
|
+ public void testListNumbersAndNumbers() {
|
54
|
49
|
PhoneBook phoneBookTest = new PhoneBook();
|
55
|
|
- phoneBookTest.add("John","1234567890");
|
56
|
|
- phoneBookTest.add("James","555555555");
|
57
|
|
- phoneBookTest.add("Micheal","5678901234");
|
58
|
|
- String expected = "James "+ "555555555\n"+
|
59
|
|
- "John "+"1234567890\n"+
|
60
|
|
- "Micheal "+"5678901234\n";
|
61
|
|
- String actual =phoneBookTest.listNamesAndNumbers();
|
|
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();
|
62
|
58
|
Assert.assertEquals(expected, actual);
|
63
|
59
|
}
|
64
|
60
|
|
65
|
61
|
@Test
|
66
|
|
- public void testAdd(){
|
|
62
|
+ public void testAdd() {
|
67
|
63
|
PhoneBook phoneBookTest = new PhoneBook();
|
68
|
64
|
boolean expected = true;
|
69
|
|
- boolean actual = phoneBookTest.add("Peter","7777777777");
|
|
65
|
+ boolean actual = phoneBookTest.add("Peter", "7777777777");
|
70
|
66
|
Assert.assertEquals(expected, actual);
|
71
|
67
|
|
72
|
68
|
}
|
|
69
|
+
|
73
|
70
|
@Test
|
74
|
|
- public void testRemove(){
|
|
71
|
+ public void testRemove() {
|
75
|
72
|
PhoneBook phoneBookTest = new PhoneBook();
|
76
|
|
- phoneBookTest.add("John","1234567890");
|
77
|
|
- boolean expected =true;
|
78
|
|
- boolean actual = phoneBookTest.remove("John");
|
|
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();
|
79
|
81
|
Assert.assertEquals(expected, actual);
|
80
|
82
|
}
|
|
83
|
+
|
81
|
84
|
@Test
|
82
|
85
|
public void testReverseLookup() {
|
83
|
86
|
PhoneBook phoneBookTest = new PhoneBook();
|
84
|
|
- phoneBookTest.add("James","555555555");
|
|
87
|
+ phoneBookTest.add("James", "555555555");
|
85
|
88
|
|
86
|
89
|
String actual = phoneBookTest.reverseLookUp("555555555");
|
87
|
|
- Assert.assertEquals("James",actual);
|
|
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);
|
88
|
104
|
}
|
89
|
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
|
+ }
|
90
|
119
|
|
91
|
120
|
|
92
|
121
|
}
|