|
@@ -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,6 +12,7 @@ import org.junit.Test;
|
13
|
12
|
*/
|
14
|
13
|
public class PhoneBookTest
|
15
|
14
|
{
|
|
15
|
+ private PhoneBook phoneBook;
|
16
|
16
|
/**
|
17
|
17
|
* Default constructor for test class PhoneBookTest
|
18
|
18
|
*/
|
|
@@ -28,15 +28,81 @@ public class PhoneBookTest
|
28
|
28
|
@Before
|
29
|
29
|
public void setUp()
|
30
|
30
|
{
|
|
31
|
+ phoneBook = new PhoneBook();
|
|
32
|
+ }
|
|
33
|
+
|
|
34
|
+ @Test
|
|
35
|
+ public void testAdd() {
|
|
36
|
+ //Given
|
|
37
|
+ String name = "J";
|
|
38
|
+ String phoneNumber = "2121112222";
|
|
39
|
+
|
|
40
|
+ //Then
|
|
41
|
+ phoneBook.addListings(name, phoneNumber);
|
|
42
|
+ int expectedSize = 1;
|
|
43
|
+ int actualSize = phoneBook.size();
|
|
44
|
+
|
|
45
|
+ //
|
|
46
|
+ assertEquals(expectedSize, actualSize);
|
|
47
|
+ }
|
|
48
|
+
|
|
49
|
+ @Test
|
|
50
|
+ public void testRemove() {
|
|
51
|
+ //Given
|
|
52
|
+ String name = "J";
|
|
53
|
+ String phoneNumber = "2121112222";
|
|
54
|
+
|
|
55
|
+ //Then
|
|
56
|
+ phoneBook.addListings(name, phoneNumber);
|
|
57
|
+ int expectedSize = 1;
|
|
58
|
+ int actualSize = phoneBook.size();
|
|
59
|
+
|
|
60
|
+ //
|
|
61
|
+ assertEquals(expectedSize, actualSize);
|
31
|
62
|
}
|
32
|
63
|
|
33
|
|
- /**
|
34
|
|
- * Tears down the test fixture.
|
35
|
|
- *
|
36
|
|
- * Called after every test case method.
|
37
|
|
- */
|
38
|
|
- @After
|
39
|
|
- public void tearDown()
|
40
|
|
- {
|
|
64
|
+ @Test
|
|
65
|
+ public void testLookup() {
|
|
66
|
+ //Given
|
|
67
|
+ String name = "J";
|
|
68
|
+ String phoneNumber = "2121112222";
|
|
69
|
+
|
|
70
|
+ //Then
|
|
71
|
+ phoneBook.addListings(name, phoneNumber);
|
|
72
|
+ int expectedSize = 1;
|
|
73
|
+ int actualSize = phoneBook.size();
|
|
74
|
+
|
|
75
|
+ //
|
|
76
|
+ assertEquals(expectedSize, actualSize);
|
|
77
|
+ }
|
|
78
|
+
|
|
79
|
+ @Test
|
|
80
|
+ public void testReverseLookup() {
|
|
81
|
+ //Given
|
|
82
|
+ String name = "J";
|
|
83
|
+ String phoneNumber = "2121112222";
|
|
84
|
+
|
|
85
|
+ //Then
|
|
86
|
+ phoneBook.addListings(name, phoneNumber);
|
|
87
|
+ int expectedSize = 1;
|
|
88
|
+ int actualSize = phoneBook.size();
|
|
89
|
+
|
|
90
|
+ //
|
|
91
|
+ assertEquals(expectedSize, actualSize);
|
|
92
|
+ }
|
|
93
|
+
|
|
94
|
+ @Test
|
|
95
|
+ public void testReverseLookupWhenNotFound() {
|
|
96
|
+ //Given
|
|
97
|
+ String name = "J";
|
|
98
|
+ String phoneNumber = "2121112222";
|
|
99
|
+
|
|
100
|
+ //Then
|
|
101
|
+ phoneBook.addListings(name, phoneNumber);
|
|
102
|
+ int expectedSize = 1;
|
|
103
|
+ int actualSize = phoneBook.size();
|
|
104
|
+
|
|
105
|
+ //
|
|
106
|
+ assertEquals(expectedSize, actualSize);
|
41
|
107
|
}
|
42
|
108
|
}
|