|
@@ -2,6 +2,8 @@ import static org.junit.Assert.*;
|
2
|
2
|
import org.junit.After;
|
3
|
3
|
import org.junit.Before;
|
4
|
4
|
import org.junit.Test;
|
|
5
|
+import java.util.*;
|
|
6
|
+import java.util.stream.Collectors;
|
5
|
7
|
|
6
|
8
|
/**
|
7
|
9
|
* The test class PhoneBookTest.
|
|
@@ -11,45 +13,79 @@ import org.junit.Test;
|
11
|
13
|
*/
|
12
|
14
|
public class PhoneBookTest
|
13
|
15
|
{
|
14
|
|
- /**
|
15
|
|
- * Default constructor for test class PhoneBookTest
|
16
|
|
- */
|
17
|
|
- public PhoneBookTest()
|
|
16
|
+ TreeMap<String, String> phonebook = new TreeMap<>();
|
|
17
|
+ PhoneBook pb = new PhoneBook(phonebook);
|
|
18
|
+
|
|
19
|
+ @Test
|
|
20
|
+ public void testAdd()
|
18
|
21
|
{
|
|
22
|
+ //plug in a String name here using methods from main class
|
|
23
|
+ String name = "Ryan";
|
|
24
|
+ String phoneNumber= "123-456-7890";
|
|
25
|
+ pb.add(name, phoneNumber);
|
|
26
|
+ assertFalse(phonebook.isEmpty());
|
|
27
|
+
|
19
|
28
|
}
|
20
|
|
- private PhoneBook phoneBook;
|
21
|
|
-
|
22
|
|
- /**
|
23
|
|
- * Sets up the test fixture.
|
24
|
|
- *
|
25
|
|
- * Called before every test case method.
|
26
|
|
- */
|
27
|
|
- @Before
|
28
|
|
- public void setUp()
|
29
|
|
- {
|
30
|
|
- phoneBook = new PhoneBook();
|
|
29
|
+
|
|
30
|
+ @Test
|
|
31
|
+ public void testRemove()
|
|
32
|
+ {
|
|
33
|
+ String name = "Ryan";
|
|
34
|
+ String phoneNumber= "123-456-7890";
|
|
35
|
+
|
|
36
|
+ pb.add(name, phoneNumber);
|
|
37
|
+ pb.remove(name);
|
|
38
|
+ assertTrue(phonebook.isEmpty());
|
|
39
|
+
|
|
40
|
+ }
|
|
41
|
+
|
|
42
|
+ @Test
|
|
43
|
+ public void testRemoveRecord()
|
|
44
|
+ {
|
|
45
|
+ String name = "Ryan";
|
|
46
|
+ String phoneNumber= "123-456-7890";
|
|
47
|
+
|
|
48
|
+ pb.add(name, phoneNumber);
|
|
49
|
+ pb.remove(name);
|
|
50
|
+ assertTrue(phonebook.isEmpty());
|
|
51
|
+
|
31
|
52
|
}
|
32
|
53
|
|
33
|
54
|
@Test
|
34
|
|
- public void testAdd()
|
|
55
|
+ public void testLookup()
|
35
|
56
|
{
|
36
|
|
- //plug in a String name here using methods from main class
|
37
|
57
|
String name = "Ryan";
|
38
|
|
- String expectedPhoneNumber= "123-456-7890";
|
39
|
|
- phoneBook.add(name, expectedPhoneNumber);
|
40
|
|
- String actualPhoneNumber = phoneBook.lookUp(name);
|
41
|
|
-
|
42
|
|
- assertEquals(actualPhoneNumber, expectedPhoneNumber);
|
43
|
|
-
|
|
58
|
+ String phoneNumber= "123-456-7890";
|
|
59
|
+ pb.add(name, phoneNumber);
|
|
60
|
+ Collection<String> expected = phonebook.values();
|
|
61
|
+
|
|
62
|
+ assertEquals(expected, pb.lookup(name));
|
44
|
63
|
}
|
45
|
64
|
|
46
|
|
- /**
|
47
|
|
- * Tears down the test fixture.
|
48
|
|
- *
|
49
|
|
- * Called after every test case method.
|
50
|
|
- */
|
51
|
|
- @After
|
52
|
|
- public void tearDown()
|
|
65
|
+ @Test
|
|
66
|
+ public void testReverseLookup() {
|
|
67
|
+ String name = "Ryan";
|
|
68
|
+ String phoneNumber= "123-456-7890";
|
|
69
|
+ pb.add(name, phoneNumber);
|
|
70
|
+ Collection<String> expected = phonebook.keySet();
|
|
71
|
+
|
|
72
|
+ assertEquals(expected, pb.reverseLookup(phoneNumber));
|
|
73
|
+ }
|
|
74
|
+
|
|
75
|
+ @Test
|
|
76
|
+ public void testDisplay()
|
|
77
|
+ {
|
|
78
|
+ String name = "Ryan";
|
|
79
|
+ String phoneNumber= "123-456-7890";
|
|
80
|
+ pb.add(name, phoneNumber);
|
|
81
|
+ TreeMap<String, String> expected = phonebook;
|
|
82
|
+
|
|
83
|
+ assertEquals(expected, pb.display());
|
|
84
|
+ }
|
|
85
|
+
|
|
86
|
+ @Test
|
|
87
|
+ public void testEntries()
|
53
|
88
|
{
|
|
89
|
+ assertEquals(null, 1);
|
54
|
90
|
}
|
55
|
91
|
}
|