|
@@ -1,10 +1,12 @@
|
1
|
1
|
|
2
|
2
|
|
3
|
|
-import static org.junit.Assert.*;
|
|
3
|
+import org.junit.Assert;
|
4
|
4
|
import org.junit.After;
|
5
|
5
|
import org.junit.Before;
|
6
|
6
|
import org.junit.Test;
|
7
|
7
|
|
|
8
|
+import java.util.*;
|
|
9
|
+
|
8
|
10
|
/**
|
9
|
11
|
* The test class PhoneBookTest.
|
10
|
12
|
*
|
|
@@ -13,6 +15,8 @@ import org.junit.Test;
|
13
|
15
|
*/
|
14
|
16
|
public class PhoneBookTest
|
15
|
17
|
{
|
|
18
|
+
|
|
19
|
+ TreeMap<String, String> phoneBook = new TreeMap<>();
|
16
|
20
|
/**
|
17
|
21
|
* Default constructor for test class PhoneBookTest
|
18
|
22
|
*/
|
|
@@ -28,6 +32,7 @@ public class PhoneBookTest
|
28
|
32
|
@Before
|
29
|
33
|
public void setUp()
|
30
|
34
|
{
|
|
35
|
+ PhoneBook pb = new PhoneBook(phoneBook);
|
31
|
36
|
}
|
32
|
37
|
|
33
|
38
|
/**
|
|
@@ -38,5 +43,56 @@ public class PhoneBookTest
|
38
|
43
|
@After
|
39
|
44
|
public void tearDown()
|
40
|
45
|
{
|
|
46
|
+
|
|
47
|
+ }
|
|
48
|
+
|
|
49
|
+ // add entries
|
|
50
|
+ @Test
|
|
51
|
+ public void testOne() {
|
|
52
|
+ String expected = "Dog 222-444-5555\nZebra 111-222-3333\n";
|
|
53
|
+
|
|
54
|
+ PhoneBook pb = new PhoneBook(phoneBook);
|
|
55
|
+ pb.add("Zebra", "111-222-3333");
|
|
56
|
+ pb.add("Dog", "222-444-5555");
|
|
57
|
+
|
|
58
|
+ String actual = pb.display();
|
|
59
|
+
|
|
60
|
+ Assert.assertEquals(expected, actual);
|
|
61
|
+ }
|
|
62
|
+ @Test
|
|
63
|
+ public void testTwo() {
|
|
64
|
+ String expected = "Dog 222-444-5555\n";
|
|
65
|
+ PhoneBook pb = new PhoneBook(phoneBook);
|
|
66
|
+
|
|
67
|
+ pb.add("Zebra", "111-222-3333");
|
|
68
|
+ pb.add("Dog", "222-444-5555");
|
|
69
|
+ pb.remove("Zebra");
|
|
70
|
+
|
|
71
|
+ String actual = pb.display();
|
|
72
|
+
|
|
73
|
+ Assert.assertEquals(expected, actual);
|
|
74
|
+ }
|
|
75
|
+ @Test
|
|
76
|
+ public void TestThree() {
|
|
77
|
+ String expected = "222-444-5555";
|
|
78
|
+ PhoneBook pb = new PhoneBook(phoneBook);
|
|
79
|
+
|
|
80
|
+ pb.add("Zebra", "111-222-3333");
|
|
81
|
+ pb.add("Dog", "222-444-5555");
|
|
82
|
+
|
|
83
|
+ String actual = pb.lookup("Dog");
|
|
84
|
+
|
|
85
|
+ Assert.assertEquals(expected, actual);
|
|
86
|
+ }
|
|
87
|
+ @Test
|
|
88
|
+ public void TestFour() {
|
|
89
|
+ String expected = "Dog";
|
|
90
|
+ PhoneBook pb = new PhoneBook(phoneBook);
|
|
91
|
+
|
|
92
|
+ pb.add("Zebra", "111-222-3333");
|
|
93
|
+ pb.add("Dog", "222-444-5555");
|
|
94
|
+
|
|
95
|
+ String actual = pb.reverseLookup("222-444-5555");
|
|
96
|
+ Assert.assertEquals(expected, actual);
|
41
|
97
|
}
|
42
|
98
|
}
|