|
@@ -1,9 +1,9 @@
|
1
|
1
|
|
2
|
|
-
|
3
|
2
|
import static org.junit.Assert.*;
|
4
|
3
|
import org.junit.After;
|
5
|
4
|
import org.junit.Before;
|
6
|
5
|
import org.junit.Test;
|
|
6
|
+import java.util.*;
|
7
|
7
|
|
8
|
8
|
/**
|
9
|
9
|
* The test class PhoneBookTest.
|
|
@@ -13,6 +13,7 @@ import org.junit.Test;
|
13
|
13
|
*/
|
14
|
14
|
public class PhoneBookTest
|
15
|
15
|
{
|
|
16
|
+ PhoneBook test = new PhoneBook();
|
16
|
17
|
/**
|
17
|
18
|
* Default constructor for test class PhoneBookTest
|
18
|
19
|
*/
|
|
@@ -30,6 +31,116 @@ public class PhoneBookTest
|
30
|
31
|
{
|
31
|
32
|
}
|
32
|
33
|
|
|
34
|
+ @Test
|
|
35
|
+ public void addTest(){
|
|
36
|
+ //Given
|
|
37
|
+ ArrayList<String> list = new ArrayList<String>();
|
|
38
|
+ list.add("5704282076");
|
|
39
|
+ //When
|
|
40
|
+ int expected = 1;
|
|
41
|
+ TreeMap actual = test.add("Chad", list);
|
|
42
|
+
|
|
43
|
+ //Result
|
|
44
|
+ assertEquals(expected, actual.size());
|
|
45
|
+ }
|
|
46
|
+
|
|
47
|
+ @Test
|
|
48
|
+ public void removeRecordTest(){
|
|
49
|
+ //Given
|
|
50
|
+ ArrayList<String> list = new ArrayList<String>();
|
|
51
|
+ list.add("5704282076");
|
|
52
|
+ list.add("5707429337");
|
|
53
|
+ test.add("Chad", list);
|
|
54
|
+ //When
|
|
55
|
+ int expected = 0;
|
|
56
|
+ TreeMap actual = test.removeRecord("Chad");
|
|
57
|
+
|
|
58
|
+ //Result
|
|
59
|
+ assertEquals(expected, actual.size());
|
|
60
|
+ }
|
|
61
|
+
|
|
62
|
+ @Test
|
|
63
|
+ public void lookUpTest(){
|
|
64
|
+ //Given
|
|
65
|
+ ArrayList<String> list = new ArrayList<String>();
|
|
66
|
+ list.add("5704282076");
|
|
67
|
+ test.add("Chad", list);
|
|
68
|
+ //When
|
|
69
|
+ ArrayList<String> expected = list;
|
|
70
|
+ ArrayList<String> actual = test.lookUp("Chad");
|
|
71
|
+
|
|
72
|
+ //Result
|
|
73
|
+ assertEquals(expected, actual);
|
|
74
|
+ }
|
|
75
|
+
|
|
76
|
+ @Test
|
|
77
|
+ public void invertMapTest(){
|
|
78
|
+ //Given
|
|
79
|
+ ArrayList<String> list = new ArrayList<String>();
|
|
80
|
+ list.add("5704282076");
|
|
81
|
+ test.add("Chad", list);
|
|
82
|
+ test.invertMap();
|
|
83
|
+ //When
|
|
84
|
+ String expected = "Chad";
|
|
85
|
+ String actual = test.reverseLookUp("5704282076");
|
|
86
|
+
|
|
87
|
+ //Result
|
|
88
|
+ assertEquals(expected, actual);
|
|
89
|
+ }
|
|
90
|
+
|
|
91
|
+ @Test
|
|
92
|
+ public void displayTest(){
|
|
93
|
+ //Given
|
|
94
|
+ ArrayList<String> list = new ArrayList<String>();
|
|
95
|
+ list.add("5704282076");
|
|
96
|
+ ArrayList<String> list1 = new ArrayList<String>();
|
|
97
|
+ list1.add("111-222-333");
|
|
98
|
+ ArrayList<String> list2 = new ArrayList<String>();
|
|
99
|
+ list2.add("222-444-4444");
|
|
100
|
+ test.add("Chad", list);
|
|
101
|
+ test.add("Zebra", list1);
|
|
102
|
+ test.add("Dog", list2);
|
|
103
|
+
|
|
104
|
+ //When
|
|
105
|
+ String expected = "Chad 5704282076\nDog 222-444-4444\nZebra 111-222-333\n";
|
|
106
|
+ String actual = test.display();
|
|
107
|
+
|
|
108
|
+ //Result
|
|
109
|
+ assertEquals(expected, actual);
|
|
110
|
+ }
|
|
111
|
+
|
|
112
|
+ @Test
|
|
113
|
+ public void arrayContainsTest(){
|
|
114
|
+ //Given
|
|
115
|
+ ArrayList<String> list = new ArrayList<String>();
|
|
116
|
+ list.add("5704282076");
|
|
117
|
+ //When
|
|
118
|
+ boolean actual = test.arrayContains(list,"5704282076");
|
|
119
|
+ //Result
|
|
120
|
+ assertTrue(actual);
|
|
121
|
+ }
|
|
122
|
+
|
|
123
|
+ @Test
|
|
124
|
+ public void removeTest(){
|
|
125
|
+ //Given
|
|
126
|
+ ArrayList<String> list = new ArrayList<String>();
|
|
127
|
+ list.add("5704282076");
|
|
128
|
+ list.add("5707429337");
|
|
129
|
+ ArrayList<String> list1 = new ArrayList<String>();
|
|
130
|
+ list1.add("111-222-333");
|
|
131
|
+ ArrayList<String> list2 = new ArrayList<String>();
|
|
132
|
+ list2.add("222-444-4444");
|
|
133
|
+ test.add("Chad", list);
|
|
134
|
+ test.add("Zebra", list1);
|
|
135
|
+ test.add("Dog", list2);
|
|
136
|
+
|
|
137
|
+ test.remove("Chad","5704282076");
|
|
138
|
+ //When
|
|
139
|
+ boolean actual = test.arrayContains(list,"5704282076");
|
|
140
|
+ //Result
|
|
141
|
+ assertFalse(actual);
|
|
142
|
+ }
|
|
143
|
+
|
33
|
144
|
/**
|
34
|
145
|
* Tears down the test fixture.
|
35
|
146
|
*
|