|
@@ -1,5 +1,4 @@
|
1
|
1
|
|
2
|
|
-
|
3
|
2
|
import static org.junit.Assert.*;
|
4
|
3
|
import org.junit.After;
|
5
|
4
|
import org.junit.Before;
|
|
@@ -13,30 +12,110 @@ import org.junit.Test;
|
13
|
12
|
*/
|
14
|
13
|
public class PhoneBookTest
|
15
|
14
|
{
|
16
|
|
- /**
|
17
|
|
- * Default constructor for test class PhoneBookTest
|
18
|
|
- */
|
19
|
|
- public PhoneBookTest()
|
20
|
|
- {
|
|
15
|
+ @Test
|
|
16
|
+ public void testAdd(){
|
|
17
|
+ //given
|
|
18
|
+ PhoneBook phoneBook = new PhoneBook();
|
|
19
|
+
|
|
20
|
+ //actual
|
|
21
|
+ phoneBook.add("eric", "3025884804");
|
|
22
|
+ String actual = phoneBook.lookup("eric");
|
|
23
|
+
|
|
24
|
+ //expected
|
|
25
|
+ String expected = "3025884804";
|
|
26
|
+
|
|
27
|
+ //test
|
|
28
|
+ assertEquals(expected, actual);
|
|
29
|
+ }
|
|
30
|
+
|
|
31
|
+ @Test
|
|
32
|
+ public void testAddMultiple(){
|
|
33
|
+ //given
|
|
34
|
+ PhoneBook phoneBook = new PhoneBook();
|
|
35
|
+
|
|
36
|
+ //actual
|
|
37
|
+ phoneBook.add("eric", "3025884804");
|
|
38
|
+ phoneBook.add("john", "3025844804");
|
|
39
|
+ phoneBook.add("jane", "3025884704");
|
|
40
|
+ String actual = phoneBook.lookup("eric");
|
|
41
|
+ String actual1 = phoneBook.lookup("john");
|
|
42
|
+ String actual2 = phoneBook.lookup("jane");
|
|
43
|
+
|
|
44
|
+ //expected
|
|
45
|
+ String expected = "3025884804";
|
|
46
|
+ String expected1 = "3025844804";
|
|
47
|
+ String expected2 = "3025884704";
|
|
48
|
+
|
|
49
|
+ //test
|
|
50
|
+ assertEquals(expected, actual);
|
|
51
|
+ }
|
|
52
|
+
|
|
53
|
+ @Test
|
|
54
|
+ public void testRemove(){
|
|
55
|
+ //given
|
|
56
|
+ PhoneBook phoneBook = new PhoneBook();
|
|
57
|
+
|
|
58
|
+ //actual
|
|
59
|
+ phoneBook.add("eric", "3025884804");
|
|
60
|
+ phoneBook.remove("eric");
|
|
61
|
+ String actual = phoneBook.lookup("eric");
|
|
62
|
+
|
|
63
|
+ //expected
|
|
64
|
+ String expected = null;
|
|
65
|
+
|
|
66
|
+ //test
|
|
67
|
+ assertEquals(expected, actual);
|
21
|
68
|
}
|
22
|
69
|
|
23
|
|
- /**
|
24
|
|
- * Sets up the test fixture.
|
25
|
|
- *
|
26
|
|
- * Called before every test case method.
|
27
|
|
- */
|
28
|
|
- @Before
|
29
|
|
- public void setUp()
|
30
|
|
- {
|
|
70
|
+ @Test
|
|
71
|
+ public void testRemoveMultiple(){
|
|
72
|
+ //given
|
|
73
|
+ PhoneBook phoneBook = new PhoneBook();
|
|
74
|
+
|
|
75
|
+ //actual
|
|
76
|
+ phoneBook.add("eric", "3025884804");
|
|
77
|
+ phoneBook.add("john", "3025844804");
|
|
78
|
+ phoneBook.add("jane", "3025884704");
|
|
79
|
+ phoneBook.remove("john");
|
|
80
|
+ phoneBook.remove("eric");
|
|
81
|
+ String actual = phoneBook.lookup("john");
|
|
82
|
+ String actual1 = phoneBook.lookup("eric");
|
|
83
|
+ String actual2 = phoneBook.lookup("jane");
|
|
84
|
+
|
|
85
|
+ //expected
|
|
86
|
+ String expected = null;
|
|
87
|
+ String expected1 = null;
|
|
88
|
+ String expected2 = "3025884704";
|
|
89
|
+
|
|
90
|
+ //test
|
|
91
|
+ assertEquals(expected, actual);
|
|
92
|
+ assertEquals(expected1, actual1);
|
|
93
|
+ assertEquals(expected2, actual2);
|
31
|
94
|
}
|
32
|
95
|
|
33
|
|
- /**
|
34
|
|
- * Tears down the test fixture.
|
35
|
|
- *
|
36
|
|
- * Called after every test case method.
|
37
|
|
- */
|
38
|
|
- @After
|
39
|
|
- public void tearDown()
|
40
|
|
- {
|
|
96
|
+ @Test
|
|
97
|
+ public void testReverseLookup(){
|
|
98
|
+ //given
|
|
99
|
+ PhoneBook phoneBook = new PhoneBook();
|
|
100
|
+
|
|
101
|
+ //actual
|
|
102
|
+ phoneBook.add("eric", "3025884804");
|
|
103
|
+ phoneBook.add("john", "3025844804");
|
|
104
|
+ phoneBook.add("jane", "3025884704");
|
|
105
|
+ String actual = phoneBook.reverseLookup("3025884804");
|
|
106
|
+ String actual1 = phoneBook.reverseLookup("3025844804");
|
|
107
|
+ String actual2 = phoneBook.reverseLookup("3025884704");
|
|
108
|
+ String actual3 = phoneBook.reverseLookup("4025884704");
|
|
109
|
+
|
|
110
|
+ //expected
|
|
111
|
+ String expected = "eric";
|
|
112
|
+ String expected1 = "john";
|
|
113
|
+ String expected2 = "jane";
|
|
114
|
+ String expected3 = null;
|
|
115
|
+
|
|
116
|
+ //test
|
|
117
|
+ assertEquals(expected, actual);
|
|
118
|
+ assertEquals(expected1, actual1);
|
|
119
|
+ assertEquals(expected2, actual2);
|
41
|
120
|
}
|
42
|
121
|
}
|