|
@@ -1,8 +1,13 @@
|
1
|
1
|
package com.zipcodewilmington.phonebook;
|
2
|
2
|
|
|
3
|
+
|
3
|
4
|
import org.junit.Assert;
|
4
|
5
|
import org.junit.Test;
|
5
|
6
|
|
|
7
|
+import java.util.ArrayList;
|
|
8
|
+import java.util.Collection;
|
|
9
|
+import java.util.TreeMap;
|
|
10
|
+
|
6
|
11
|
|
7
|
12
|
/**
|
8
|
13
|
* Created by leon on 1/23/18.
|
|
@@ -10,36 +15,153 @@ import org.junit.Test;
|
10
|
15
|
public class PhoneBookTest {
|
11
|
16
|
|
12
|
17
|
@Test
|
13
|
|
- public void testConstructor() {
|
14
|
|
- // Given
|
15
|
|
- String expectedName = "";
|
16
|
|
- String expectedPhoneNumber = "";
|
|
18
|
+ public void addContactTest() {
|
|
19
|
+
|
|
20
|
+ PhoneBook testPhoneBook = new PhoneBook();
|
|
21
|
+
|
|
22
|
+ Contact contact1 = new Contact("Jerry");
|
|
23
|
+ contact1.addPhoneNumber("1234");
|
|
24
|
+
|
|
25
|
+ // Actual
|
|
26
|
+ testPhoneBook.addContact("Jerry", "43234");
|
|
27
|
+
|
|
28
|
+ }
|
|
29
|
+
|
|
30
|
+ @Test
|
|
31
|
+ public void getNumberOfContactsTest() {
|
|
32
|
+
|
|
33
|
+ PhoneBook testPhoneBook = new PhoneBook();
|
|
34
|
+
|
|
35
|
+ testPhoneBook.addContact("Jerry", "78998");
|
|
36
|
+ testPhoneBook.addContact("Newman", "90980");
|
|
37
|
+ testPhoneBook.addContact("Elaine", "432345");
|
|
38
|
+
|
|
39
|
+ int expectedNumberOfContacts = 3;
|
|
40
|
+ //int actualNumberOfContacts =
|
|
41
|
+ }
|
|
42
|
+
|
|
43
|
+ @Test
|
|
44
|
+ public void lookupByNameTest() {
|
|
45
|
+
|
|
46
|
+ PhoneBook testPhoneBook = new PhoneBook();
|
|
47
|
+ testPhoneBook.addContact("Madeline", "898098");
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+ ArrayList expectedLookupByNameResult = new ArrayList();
|
|
51
|
+ ArrayList actualLookupByNameResult = testPhoneBook.lookupByName("Madeline");
|
|
52
|
+
|
|
53
|
+ }
|
|
54
|
+
|
|
55
|
+ @Test
|
|
56
|
+ public void lookupByNumberTest() {
|
|
57
|
+
|
|
58
|
+ PhoneBook testPhoneBook = new PhoneBook();
|
|
59
|
+
|
17
|
60
|
|
18
|
|
- // When
|
19
|
|
- Person person = new Person(expectedName, expectedPhoneNumber);
|
20
|
61
|
|
21
|
|
- // Then
|
22
|
|
- String actualName = person.getName();
|
23
|
|
- String actualPhoneNumber = person.getPhoneNumber();
|
24
|
62
|
|
25
|
|
- Assert.assertEquals(expectedName, actualName);
|
26
|
|
- Assert.assertEquals(expectedPhoneNumber, actualPhoneNumber);
|
27
|
63
|
}
|
28
|
64
|
|
29
|
65
|
@Test
|
30
|
|
- public void testConstructorWithNameAndPhonNumber() {
|
|
66
|
+ public void removeContactTest() {
|
31
|
67
|
// Given
|
32
|
|
- String expectedName = "Leon";
|
33
|
|
- String expectedPhoneNumber = "123";
|
|
68
|
+ String personNameToRemove = "Bob";
|
|
69
|
+ int expectedListSize = 0;
|
34
|
70
|
|
35
|
71
|
// When
|
36
|
|
- Person person = new Person(expectedName, expectedPhoneNumber);
|
|
72
|
+ PhoneBook testPhoneBook = new PhoneBook();
|
|
73
|
+ testPhoneBook.addContact(personNameToRemove, "23423");
|
|
74
|
+ testPhoneBook.removeContact(personNameToRemove);
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+ Assert.assertEquals(expectedListSize, testPhoneBook.getNumberOfContacts());
|
|
79
|
+ }
|
|
80
|
+
|
|
81
|
+ @Test
|
|
82
|
+ public void listAllContactsTest() {
|
|
83
|
+
|
|
84
|
+ PhoneBook testPhoneBook = new PhoneBook();
|
|
85
|
+ testPhoneBook.addContact("Kramer", "23423");
|
|
86
|
+
|
|
87
|
+ Collection actualContactsList = testPhoneBook.listAllContacts();
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+ // Actual
|
|
91
|
+ // Create object
|
|
92
|
+ Collection expectedContactsList = new ArrayList<Contact>();
|
|
93
|
+ Contact contact1 = new Contact("Kramer");
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+ contact1.addPhoneNumber("23423");
|
|
97
|
+
|
|
98
|
+ // add contacts to expectedList
|
|
99
|
+ expectedContactsList.add(contact1);
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+ Assert.assertEquals(expectedContactsList, actualContactsList);
|
|
103
|
+ }
|
|
104
|
+
|
|
105
|
+
|
37
|
106
|
|
38
|
|
- // Then
|
39
|
|
- String actualPhoneNumber = person.getPhoneNumber();
|
40
|
|
- String actualName = person.getName();
|
41
|
107
|
|
42
|
|
- Assert.assertEquals(expectedPhoneNumber, actualPhoneNumber);
|
43
|
|
- Assert.assertEquals(expectedName, actualName);
|
44
|
108
|
}
|
45
|
|
-}
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+ //addContact ---- done
|
|
112
|
+ //removeContact ----- done
|
|
113
|
+ //lookupByName ----- done
|
|
114
|
+ //lookupByNumber
|
|
115
|
+ //addPhoneNumber ---- done
|
|
116
|
+ //removePhoneNumber ---- done
|
|
117
|
+ //list all entries (names & phone numbers) ----- done
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+// @Test
|
|
121
|
+// public void testGetName() {
|
|
122
|
+// // Given
|
|
123
|
+// String expectedName = "Bob";
|
|
124
|
+//
|
|
125
|
+//
|
|
126
|
+// // When
|
|
127
|
+// Person person = new Person("Bob", ;
|
|
128
|
+//
|
|
129
|
+// // Then
|
|
130
|
+// String actualName = person.getName();
|
|
131
|
+// Assert.assertEquals(expectedName, actualName);
|
|
132
|
+//
|
|
133
|
+// }
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+ // @Test
|
|
137
|
+// public void testGetPhoneNumber() {
|
|
138
|
+// // Given
|
|
139
|
+// String expectedName = "Madeline";
|
|
140
|
+// String expectedPhoneNumber = "123";
|
|
141
|
+//
|
|
142
|
+// // When
|
|
143
|
+// Person person = new Person(expectedName, expectedPhoneNumber);
|
|
144
|
+//
|
|
145
|
+// // Then
|
|
146
|
+// String actualPhoneNumber = person.getPhoneNumber();
|
|
147
|
+// String actualName = person.getName();
|
|
148
|
+//
|
|
149
|
+// Assert.assertEquals(expectedPhoneNumber, actualPhoneNumber);
|
|
150
|
+// Assert.assertEquals(expectedName, actualName);
|
|
151
|
+// }
|
|
152
|
+//
|
|
153
|
+
|
|
154
|
+//
|
|
155
|
+//
|
|
156
|
+//
|
|
157
|
+// @Test
|
|
158
|
+// public void testLookup() {
|
|
159
|
+// PhoneBook testPB = new PhoneBook();
|
|
160
|
+// testPB.addPerson("bob", "123");
|
|
161
|
+//
|
|
162
|
+// String actualPhoneNumber = testPB.lookupPhoneNumber("Bob");
|
|
163
|
+// Assert.assertEquals("123", actualPhoneNumber);
|
|
164
|
+//
|
|
165
|
+// }
|
|
166
|
+
|
|
167
|
+
|