|
@@ -9,48 +9,68 @@ import java.util.TreeMap;
|
9
|
9
|
* Created by leon on 1/23/18.
|
10
|
10
|
*/
|
11
|
11
|
public class PhoneBookTest {
|
12
|
|
-
|
|
12
|
+ @Test
|
13
|
13
|
public void testDefaultConstructor() {
|
14
|
14
|
|
15
|
15
|
PhoneBook book = new PhoneBook();
|
|
16
|
+ book.add("Robert", "302-555-1234");
|
|
17
|
+ Assert.assertNotNull(book);
|
16
|
18
|
|
17
|
19
|
|
18
|
20
|
|
19
|
21
|
}
|
20
|
|
-
|
|
22
|
+ @Test
|
21
|
23
|
public void testConstructorWithArgument() {
|
22
|
24
|
|
23
|
25
|
}
|
24
|
26
|
|
|
27
|
+ @Test
|
25
|
28
|
public void testAdd() {
|
26
|
29
|
PhoneBook book = new PhoneBook();
|
27
|
30
|
book.add("Bob", "302-555-1234");
|
28
|
|
- Assert.assertNotNull(book);
|
|
31
|
+
|
|
32
|
+
|
29
|
33
|
}
|
30
|
34
|
|
|
35
|
+ @Test
|
31
|
36
|
public void testRemove() {
|
32
|
37
|
|
|
38
|
+ //Given
|
|
39
|
+ PhoneBook book = new PhoneBook();
|
|
40
|
+ book.add("Robert", "302-555-1234");
|
|
41
|
+ String expectedValue = "Robert " + book.lookup("Robert") + " has been removed";
|
|
42
|
+ book.add("Robert", expectedValue);
|
|
43
|
+
|
|
44
|
+ //When
|
|
45
|
+ String actualNumber = book.remove("Robert");
|
|
46
|
+
|
|
47
|
+ //Then
|
|
48
|
+ Assert.assertEquals(expectedValue, actualNumber );
|
|
49
|
+
|
|
50
|
+
|
33
|
51
|
}
|
34
|
52
|
|
|
53
|
+ @Test
|
35
|
54
|
public void testLookup(){
|
36
|
55
|
|
37
|
56
|
//Given
|
38
|
|
- String expectedNumber = "302-555-1234";
|
39
|
57
|
PhoneBook book = new PhoneBook();
|
40
|
|
- book.add("Bob", "302-555-1234");
|
|
58
|
+ String expectedNumber = "302-555-1234";
|
|
59
|
+ book.add("Bob", expectedNumber);
|
41
|
60
|
|
42
|
61
|
//When
|
43
|
|
- book.lookup("Bob");
|
|
62
|
+ String actualNumber = book.lookup("Bob");
|
44
|
63
|
|
45
|
64
|
//Then
|
46
|
|
- Assert.assertEquals(expectedNumber, "302-555-1234");
|
|
65
|
+ Assert.assertEquals(expectedNumber, actualNumber);
|
47
|
66
|
}
|
48
|
|
-
|
|
67
|
+ @Test
|
49
|
68
|
public void testDisplay() {
|
50
|
|
- //Given
|
51
|
|
- String expectedNameNumber = "Bob 302-555-1234 \n";
|
|
69
|
+ //Given: need help from instructor
|
|
70
|
+ String expectedNameNumber = "Bob 302-555-1234\nFrank 777-555-1111\n";
|
52
|
71
|
PhoneBook book = new PhoneBook();
|
53
|
72
|
book.add("Bob", "302-555-1234");
|
|
73
|
+ book.add("Frank", "777-555-1111");
|
54
|
74
|
//When
|
55
|
75
|
String actualNameNumber = book.display();
|
56
|
76
|
//Then
|