|
@@ -1,7 +1,147 @@
|
1
|
1
|
package com.zipcodewilmington.phonebook;
|
2
|
2
|
|
|
3
|
+import org.junit.Assert;
|
|
4
|
+import org.junit.Test;
|
|
5
|
+import sun.nio.cs.ext.SJIS;
|
|
6
|
+
|
|
7
|
+import java.util.ArrayList;
|
|
8
|
+import java.util.Arrays;
|
|
9
|
+import java.util.TreeMap;
|
|
10
|
+
|
3
|
11
|
/**
|
4
|
12
|
* Created by leon on 1/23/18.
|
5
|
13
|
*/
|
6
|
14
|
public class PhoneBookTest {
|
|
15
|
+ @Test
|
|
16
|
+ public void testDefaultConstructor() {
|
|
17
|
+ PhoneBook book = new PhoneBook();
|
|
18
|
+ Assert.assertNotNull(book);
|
|
19
|
+ }
|
|
20
|
+
|
|
21
|
+ @Test
|
|
22
|
+ public void testConstructorWithArgument() {
|
|
23
|
+ PhoneBook book = new PhoneBook();
|
|
24
|
+ ArrayList<String> number = new ArrayList<String>(Arrays.asList("302-555-2222","302-555-3456"));
|
|
25
|
+ book.addEntry("Bob", number);
|
|
26
|
+ Assert.assertNotNull(book);
|
|
27
|
+ }
|
|
28
|
+
|
|
29
|
+ @Test
|
|
30
|
+ public void testAddEntry() {
|
|
31
|
+ //Given
|
|
32
|
+ PhoneBook book = new PhoneBook();
|
|
33
|
+ ArrayList<String> expectedAddition = new ArrayList<String>(Arrays.asList("302-555-2222","302-555-3456"));
|
|
34
|
+ //When
|
|
35
|
+ book.addEntry("Bob", expectedAddition);
|
|
36
|
+ ArrayList<String> actualAddition = new ArrayList<String>(book.lookup("Bob"));
|
|
37
|
+ //Then
|
|
38
|
+ Assert.assertEquals(expectedAddition, actualAddition);
|
|
39
|
+ }
|
|
40
|
+
|
|
41
|
+ @Test
|
|
42
|
+ public void addNumberToEntry() {
|
|
43
|
+ //Given
|
|
44
|
+ PhoneBook book = new PhoneBook();
|
|
45
|
+ ArrayList<String> bobNumber = new ArrayList<String>(Arrays.asList("302-555-2234"));
|
|
46
|
+ book.addEntry("Bob", bobNumber);
|
|
47
|
+ //Expected
|
|
48
|
+ ArrayList<String> expectedAddition = new ArrayList<String>(Arrays.asList("302-555-2234","302-555-1111"));
|
|
49
|
+ //When
|
|
50
|
+ book.addNumberToEntry("Bob", "302-555-1111");
|
|
51
|
+ ArrayList<String> actualAddition = book.lookup("Bob");
|
|
52
|
+ //Then
|
|
53
|
+ Assert.assertEquals(expectedAddition, actualAddition);
|
|
54
|
+ }
|
|
55
|
+
|
|
56
|
+ @Test
|
|
57
|
+ public void removeNumberFromEntry() {
|
|
58
|
+ //Given
|
|
59
|
+ PhoneBook book = new PhoneBook();
|
|
60
|
+ ArrayList<String> bobNumber = new ArrayList<String>(Arrays.asList("302-555-2234","302-555-1111"));
|
|
61
|
+ book.addEntry("Bob", bobNumber);
|
|
62
|
+ //Expected
|
|
63
|
+ ArrayList<String> expectedAfterDeletion = new ArrayList<String>(Arrays.asList("302-555-2234"));
|
|
64
|
+ //When
|
|
65
|
+ book.removeNumberFromEntry("Bob", "302-555-1111");
|
|
66
|
+ ArrayList<String> actualAfterDeletion = book.lookup("Bob");
|
|
67
|
+ //Then
|
|
68
|
+ Assert.assertEquals(expectedAfterDeletion, actualAfterDeletion);
|
|
69
|
+ }
|
|
70
|
+
|
|
71
|
+ @Test
|
|
72
|
+ public void testRemoveEntry() {
|
|
73
|
+
|
|
74
|
+ //Given
|
|
75
|
+ PhoneBook book = new PhoneBook();
|
|
76
|
+ ArrayList<String> bobNumber = new ArrayList<String>(Arrays.asList("302-555-2222","302-555-3456"));
|
|
77
|
+ book.addEntry("Bob", bobNumber);
|
|
78
|
+ //Expected
|
|
79
|
+ String expectedValue = "";
|
|
80
|
+ //When
|
|
81
|
+ book.removeEntry("Bob");
|
|
82
|
+ String actualValue = book.display();
|
|
83
|
+ //Then
|
|
84
|
+ Assert.assertEquals(expectedValue, actualValue);
|
|
85
|
+ }
|
|
86
|
+
|
|
87
|
+ @Test
|
|
88
|
+ public void testLookup(){
|
|
89
|
+ //To test if lookup returns all of the person's phone numbers
|
|
90
|
+ //Given
|
|
91
|
+ PhoneBook book = new PhoneBook();
|
|
92
|
+ ArrayList<String> expectedNumber = new ArrayList<String>(Arrays.asList("302-555-2223","302-555-3456"));
|
|
93
|
+ book.addEntry("Bob", expectedNumber);
|
|
94
|
+ //When
|
|
95
|
+ ArrayList<String> actualNumber = new ArrayList<String>(book.lookup("Bob"));
|
|
96
|
+ //Then
|
|
97
|
+ Assert.assertEquals(expectedNumber, actualNumber);
|
|
98
|
+ }
|
|
99
|
+
|
|
100
|
+ @Test
|
|
101
|
+ public void testLookup2(){
|
|
102
|
+ //To test if lookup picks out the right person when there are multiple entries
|
|
103
|
+ //Given
|
|
104
|
+ PhoneBook book = new PhoneBook();
|
|
105
|
+ ArrayList<String> bobNumber = new ArrayList<String>(Arrays.asList("302-555-2223"));
|
|
106
|
+ book.addEntry("Bob", bobNumber);
|
|
107
|
+ //Expected
|
|
108
|
+ ArrayList<String> expectedNumber = new ArrayList<String>(Arrays.asList("302-555-9988"));
|
|
109
|
+ book.addEntry("Frank", expectedNumber);
|
|
110
|
+ //When
|
|
111
|
+ ArrayList<String> actualNumber = new ArrayList<String> (book.lookup("Frank"));
|
|
112
|
+ //Then
|
|
113
|
+ Assert.assertEquals(expectedNumber, actualNumber);
|
|
114
|
+ }
|
|
115
|
+
|
|
116
|
+ @Test
|
|
117
|
+ public void testreverseLookup(){
|
|
118
|
+ // to test if right person is returned when searching by one of multiple phone numbers
|
|
119
|
+ //Given
|
|
120
|
+ PhoneBook book = new PhoneBook();
|
|
121
|
+ ArrayList<String> bobNumber = new ArrayList<String>(Arrays.asList("302-555-2223","302-555-5555"));
|
|
122
|
+ String expectedName = "Bob";
|
|
123
|
+ book.addEntry(expectedName, bobNumber);
|
|
124
|
+ //When
|
|
125
|
+ String actualName = book.reverseLookup("302-555-2223");
|
|
126
|
+ //Then
|
|
127
|
+ Assert.assertEquals(expectedName, actualName);
|
|
128
|
+ }
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+ @Test
|
|
132
|
+ public void testDisplay() {
|
|
133
|
+ //Given:
|
|
134
|
+ PhoneBook book = new PhoneBook();
|
|
135
|
+ ArrayList<String> bobNumber = new ArrayList<String>(Arrays.asList("302-555-1234","302-556-1245"));
|
|
136
|
+ book.addEntry("Bob", bobNumber);
|
|
137
|
+ ArrayList<String> frankNumber = new ArrayList<String>(Arrays.asList("777-555-1111"));
|
|
138
|
+ book.addEntry("Frank", frankNumber);
|
|
139
|
+ //Expected
|
|
140
|
+ String expectedNameNumber = "Bob " + bobNumber.toString() + "\n" + "Frank " + frankNumber.toString() + "\n";
|
|
141
|
+ //When
|
|
142
|
+ String actualNameNumber = book.display();
|
|
143
|
+ //Then
|
|
144
|
+ Assert.assertEquals(expectedNameNumber, actualNameNumber);
|
|
145
|
+ }
|
|
146
|
+
|
7
|
147
|
}
|