|
@@ -1,7 +1,81 @@
|
1
|
1
|
package com.zipcodewilmington.phonebook;
|
2
|
2
|
|
|
3
|
+import org.junit.Assert;
|
|
4
|
+import org.junit.Before;
|
|
5
|
+import org.junit.Test;
|
|
6
|
+
|
|
7
|
+import java.util.TreeMap;
|
3
|
8
|
/**
|
4
|
9
|
* Created by leon on 1/23/18.
|
5
|
10
|
*/
|
|
11
|
+
|
6
|
12
|
public class PhoneBookTest {
|
|
13
|
+
|
|
14
|
+ PhoneBook testbook;
|
|
15
|
+ @Before
|
|
16
|
+ public void setUp(){
|
|
17
|
+ testbook = new PhoneBook();
|
|
18
|
+ }
|
|
19
|
+
|
|
20
|
+ @Test
|
|
21
|
+ public void testPhoneBookAddName() {
|
|
22
|
+ // Given
|
|
23
|
+ PhoneBook testbook = new PhoneBook();
|
|
24
|
+ testbook.add("Keith", "555-666-7777");
|
|
25
|
+
|
|
26
|
+ String testNumber = testbook.lookup("Keith");
|
|
27
|
+ Assert.assertTrue(testNumber.equals("555-666-7777"));
|
|
28
|
+
|
|
29
|
+ }
|
|
30
|
+@Test
|
|
31
|
+ public void testPhoneBookDelete(){
|
|
32
|
+ PhoneBook testbook = new PhoneBook();
|
|
33
|
+ testbook.add("Keith", "555-666-7777");
|
|
34
|
+ testbook.deleter("Keith");
|
|
35
|
+ String testnumber = testbook.lookup("Keith");
|
|
36
|
+ Assert.assertEquals(null, testnumber);
|
|
37
|
+ }
|
|
38
|
+@Test
|
|
39
|
+ public void testPhoneBookLookUp(){
|
|
40
|
+ PhoneBook testbook = new PhoneBook();
|
|
41
|
+ testbook.add("Keith", "555-666-7777");
|
|
42
|
+ String testnumber = testbook.lookup("Keith");
|
|
43
|
+ Assert.assertEquals("555-666-7777", testnumber);
|
|
44
|
+ }
|
|
45
|
+
|
|
46
|
+ @Test
|
|
47
|
+ public void testPhoneBookList(){
|
|
48
|
+
|
|
49
|
+ PhoneBook testbook = new PhoneBook();
|
|
50
|
+ testbook.add("Keith", "555-666-7777");
|
|
51
|
+ testbook.add("John", "555-612-7777");
|
|
52
|
+ testbook.add("Mike", "555-623-7777");
|
|
53
|
+ testbook.add("Steve", "555-645-7777");
|
|
54
|
+
|
|
55
|
+ String expected = "John 555-612-7777\n" +
|
|
56
|
+ "Keith 555-666-7777\n" +
|
|
57
|
+ "Mike 555-623-7777\n" +
|
|
58
|
+ "Steve 555-645-7777\n";
|
|
59
|
+ String actual = testbook.listNamesAndNumbers();
|
|
60
|
+ Assert.assertEquals(expected, actual);
|
|
61
|
+ }
|
|
62
|
+
|
|
63
|
+ @Test
|
|
64
|
+ public void testPhoneBookNames(){
|
|
65
|
+
|
|
66
|
+ PhoneBook testbook = new PhoneBook();
|
|
67
|
+ testbook.add("Keith", "555-666-7777");
|
|
68
|
+ testbook.add("John", "555-612-7777");
|
|
69
|
+ testbook.add("Mike", "555-623-7777");
|
|
70
|
+ testbook.add("Steve", "555-645-7777");
|
|
71
|
+
|
|
72
|
+ String expected = "John\n" +
|
|
73
|
+ "Keith\n" +
|
|
74
|
+ "Mike\n" +
|
|
75
|
+ "Steve\n";
|
|
76
|
+ String actual = testbook.listNames();
|
|
77
|
+ Assert.assertEquals(expected, actual);
|
|
78
|
+ }
|
|
79
|
+
|
|
80
|
+
|
7
|
81
|
}
|