|
@@ -1,7 +1,123 @@
|
1
|
1
|
package com.zipcodewilmington.phonebook;
|
2
|
2
|
|
|
3
|
+import org.junit.Assert;
|
|
4
|
+import org.junit.Test;
|
|
5
|
+
|
|
6
|
+import java.util.ArrayList;
|
|
7
|
+
|
3
|
8
|
/**
|
4
|
|
- * Created by leon on 1/23/18.
|
|
9
|
+ * Created by William on 10/28/2018.
|
5
|
10
|
*/
|
6
|
11
|
public class PhoneBookTest {
|
7
|
|
-}
|
|
12
|
+
|
|
13
|
+ @Test
|
|
14
|
+ public void testHasEntry(){
|
|
15
|
+ //Given
|
|
16
|
+ PhoneBook book = new PhoneBook();
|
|
17
|
+ String name = "AA";
|
|
18
|
+ ArrayList<String> phoneNumber = new ArrayList<>();
|
|
19
|
+
|
|
20
|
+ phoneNumber.add("211-111-2222");
|
|
21
|
+
|
|
22
|
+ book.addContact(name, phoneNumber);
|
|
23
|
+
|
|
24
|
+ //When
|
|
25
|
+ boolean actualOutput = book.hasEntry(name);
|
|
26
|
+
|
|
27
|
+ //Then
|
|
28
|
+ Assert.assertTrue(actualOutput);
|
|
29
|
+ }
|
|
30
|
+
|
|
31
|
+ @Test
|
|
32
|
+ public void testAdd(){
|
|
33
|
+ //Given
|
|
34
|
+ PhoneBook book = new PhoneBook();
|
|
35
|
+ String name = "AA";
|
|
36
|
+ ArrayList<String> phoneNumber = new ArrayList<>();
|
|
37
|
+ phoneNumber.add("211-111-2222");
|
|
38
|
+
|
|
39
|
+ //When
|
|
40
|
+ book.addContact(name, phoneNumber);
|
|
41
|
+
|
|
42
|
+ //Then
|
|
43
|
+ Assert.assertEquals(1, book.size());
|
|
44
|
+ }
|
|
45
|
+
|
|
46
|
+ @Test
|
|
47
|
+ public void testRemove(){
|
|
48
|
+ //Given
|
|
49
|
+ PhoneBook book = new PhoneBook();
|
|
50
|
+ String name = "AA";
|
|
51
|
+ ArrayList<String> phoneNumber = new ArrayList<>();
|
|
52
|
+ phoneNumber.add("211-111-2222");
|
|
53
|
+
|
|
54
|
+ //When
|
|
55
|
+ book.removeContact(name, phoneNumber);
|
|
56
|
+
|
|
57
|
+ //Then
|
|
58
|
+ Assert.assertEquals(0, book.size());
|
|
59
|
+ }
|
|
60
|
+
|
|
61
|
+ @Test
|
|
62
|
+ public void testLookUp(){
|
|
63
|
+ //Given
|
|
64
|
+ PhoneBook book = new PhoneBook();
|
|
65
|
+ String name = "AA";
|
|
66
|
+ ArrayList<String> phoneNumber = new ArrayList<>();
|
|
67
|
+ phoneNumber.add("221-111-2222");
|
|
68
|
+ ArrayList<String> expected = new ArrayList<String>();
|
|
69
|
+ expected.add("221-111-2222");
|
|
70
|
+ //When
|
|
71
|
+ book.addContact("AA", phoneNumber);
|
|
72
|
+ book.lookUp(name);
|
|
73
|
+
|
|
74
|
+ //Then
|
|
75
|
+ Assert.assertEquals(expected, book.lookUp("AA"));
|
|
76
|
+ }
|
|
77
|
+
|
|
78
|
+ @Test
|
|
79
|
+ public void testSize(){
|
|
80
|
+ //Given
|
|
81
|
+ PhoneBook book = new PhoneBook();
|
|
82
|
+ ArrayList<String> phoneNumber = new ArrayList<>();
|
|
83
|
+ String name = "AA";
|
|
84
|
+ phoneNumber.add("211-111-2222");
|
|
85
|
+
|
|
86
|
+ book.addContact(name, phoneNumber);
|
|
87
|
+
|
|
88
|
+ //When
|
|
89
|
+ int actualOutput = book.size();
|
|
90
|
+ int expectedOutput = 1;
|
|
91
|
+
|
|
92
|
+ //Then
|
|
93
|
+ Assert.assertEquals(expectedOutput, actualOutput);
|
|
94
|
+ }
|
|
95
|
+
|
|
96
|
+ @Test
|
|
97
|
+ public void testList(){
|
|
98
|
+
|
|
99
|
+ PhoneBook phoneBook = new PhoneBook();
|
|
100
|
+ ArrayList<String> phoneNumber = new ArrayList<>();
|
|
101
|
+ String name = "AA";
|
|
102
|
+ phoneNumber.add("221-111-2222");
|
|
103
|
+
|
|
104
|
+ //When
|
|
105
|
+ phoneBook.addContact("AA", phoneNumber);
|
|
106
|
+
|
|
107
|
+ phoneBook.listNamesAndNumbers();
|
|
108
|
+ }
|
|
109
|
+
|
|
110
|
+ @Test
|
|
111
|
+ public void testNameList(){
|
|
112
|
+
|
|
113
|
+ PhoneBook phoneBook = new PhoneBook();
|
|
114
|
+ ArrayList<String> phoneNumber = new ArrayList<>();
|
|
115
|
+ String name = "AA";
|
|
116
|
+ phoneNumber.add("221-111-2222");
|
|
117
|
+
|
|
118
|
+ //When
|
|
119
|
+ phoneBook.addContact("AA", phoneNumber);
|
|
120
|
+
|
|
121
|
+ phoneBook.listNames();
|
|
122
|
+ }
|
|
123
|
+}
|