|
@@ -2,7 +2,9 @@ package com.zipcodewilmington.phonebook;
|
2
|
2
|
|
3
|
3
|
import org.junit.Assert;
|
4
|
4
|
import org.junit.Test;
|
|
5
|
+import sun.nio.cs.ext.SJIS;
|
5
|
6
|
|
|
7
|
+import java.util.ArrayList;
|
6
|
8
|
import java.util.TreeMap;
|
7
|
9
|
|
8
|
10
|
/**
|
|
@@ -19,7 +21,10 @@ public class PhoneBookTest {
|
19
|
21
|
@Test
|
20
|
22
|
public void testConstructorWithArgument() {
|
21
|
23
|
PhoneBook book = new PhoneBook();
|
22
|
|
- book.add("Bob", "302-555-1234");
|
|
24
|
+ ArrayList<String> number = new ArrayList<String>();
|
|
25
|
+ number.add("302-555-2222");
|
|
26
|
+ number.add("302-555-3456");
|
|
27
|
+ book.inputEntry("Bob", number);
|
23
|
28
|
Assert.assertNotNull(book);
|
24
|
29
|
}
|
25
|
30
|
|
|
@@ -28,11 +33,13 @@ public class PhoneBookTest {
|
28
|
33
|
|
29
|
34
|
//Given
|
30
|
35
|
PhoneBook book = new PhoneBook();
|
31
|
|
- String expectedAddition = "302-555-1234";
|
32
|
36
|
|
|
37
|
+ ArrayList<String> expectedAddition = new ArrayList<String>();
|
|
38
|
+ expectedAddition.add("302-555-2222");
|
|
39
|
+ expectedAddition.add("302-555-3456");
|
33
|
40
|
//When
|
34
|
|
- book.add("Bob", "302-555-1234");
|
35
|
|
- String actualAddition = book.lookup("Bob");
|
|
41
|
+ book.inputEntry("Bob", expectedAddition);
|
|
42
|
+ ArrayList<String> actualAddition = new ArrayList<String>(book.lookup("Bob"));
|
36
|
43
|
|
37
|
44
|
//Then
|
38
|
45
|
Assert.assertEquals(expectedAddition, actualAddition);
|
|
@@ -40,15 +47,18 @@ public class PhoneBookTest {
|
40
|
47
|
}
|
41
|
48
|
|
42
|
49
|
@Test
|
43
|
|
- public void testRemove() {
|
|
50
|
+ public void testRemoveEntry() {
|
44
|
51
|
|
45
|
52
|
//Given
|
46
|
53
|
PhoneBook book = new PhoneBook();
|
47
|
|
- book.add("Bob", "302-555-1234");
|
|
54
|
+ ArrayList<String> bobNumber = new ArrayList<String>();
|
|
55
|
+ bobNumber.add("302-555-2222");
|
|
56
|
+ bobNumber.add("302-555-3456");
|
|
57
|
+ book.inputEntry("Bob", bobNumber);
|
48
|
58
|
String expectedValue = "";
|
49
|
59
|
|
50
|
60
|
//When
|
51
|
|
- book.remove("Bob");
|
|
61
|
+ book.removeEntry("Bob");
|
52
|
62
|
String actualValue = book.display();
|
53
|
63
|
|
54
|
64
|
//Then
|
|
@@ -56,46 +66,37 @@ public class PhoneBookTest {
|
56
|
66
|
}
|
57
|
67
|
|
58
|
68
|
@Test
|
59
|
|
- public void testRemove2() {
|
|
69
|
+ public void testRemoveEntry2() {
|
60
|
70
|
|
61
|
71
|
//Given
|
62
|
72
|
PhoneBook book = new PhoneBook();
|
63
|
|
- book.add("Bob", "302-555-1234");
|
64
|
|
- String expectedValue = "";
|
|
73
|
+
|
|
74
|
+ ArrayList<String> expectedValue = new ArrayList<String>();
|
|
75
|
+ expectedValue.add("302-555-2222");
|
|
76
|
+ expectedValue.add("302-555-3456");
|
|
77
|
+ book.inputEntry("Bob", expectedValue);
|
65
|
78
|
|
66
|
79
|
//When
|
67
|
|
- book.remove("Robert");
|
|
80
|
+ book.removeEntry("Robert");
|
68
|
81
|
String actualValue = book.display();
|
69
|
82
|
|
70
|
83
|
//Then
|
71
|
84
|
Assert.assertNotEquals(expectedValue, actualValue);
|
72
|
|
-
|
73
|
|
-
|
74
|
85
|
}
|
75
|
86
|
|
76
|
|
-
|
77
|
87
|
@Test
|
78
|
88
|
public void testLookup(){
|
79
|
|
-
|
80
|
89
|
//Given
|
81
|
90
|
PhoneBook book = new PhoneBook();
|
82
|
|
- String expectedNumber = "302-555-1234";
|
83
|
|
- book.add("Bob", expectedNumber);
|
84
|
|
- //When
|
85
|
|
- String actualNumber = book.lookup("Bob");
|
86
|
|
- //Then
|
87
|
|
- Assert.assertEquals(expectedNumber, actualNumber);
|
88
|
|
- }
|
89
|
91
|
|
90
|
|
- @Test
|
91
|
|
- public void testLookup2(){
|
|
92
|
+ ArrayList<String> expectedNumber = new ArrayList<String>();
|
|
93
|
+ expectedNumber.add("302-555-2223");
|
|
94
|
+ expectedNumber.add("302-555-3456");
|
|
95
|
+ book.inputEntry("Bob", expectedNumber);
|
92
|
96
|
|
93
|
|
- //Given
|
94
|
|
- PhoneBook book = new PhoneBook();
|
95
|
|
- book.add("Bob", "302-555-1234");
|
96
|
|
- String expectedNumber = null;
|
97
|
97
|
//When
|
98
|
|
- String actualNumber = book.lookup("Frank");
|
|
98
|
+ ArrayList<String> actualNumber = new ArrayList<String>(book.lookup("Bob"));
|
|
99
|
+
|
99
|
100
|
//Then
|
100
|
101
|
Assert.assertEquals(expectedNumber, actualNumber);
|
101
|
102
|
}
|
|
@@ -105,11 +106,17 @@ public class PhoneBookTest {
|
105
|
106
|
|
106
|
107
|
//Given
|
107
|
108
|
PhoneBook book = new PhoneBook();
|
108
|
|
- book.add("Bob", "302-555-1234");
|
109
|
|
- String expectedNumber = "302-555-9988";
|
110
|
|
- book.add("Frank", expectedNumber);
|
|
109
|
+
|
|
110
|
+ ArrayList<String> bobNumber = new ArrayList<String>();
|
|
111
|
+ bobNumber.add("302-555-2223");
|
|
112
|
+ book.inputEntry("Bob", bobNumber);
|
|
113
|
+
|
|
114
|
+ ArrayList<String> expectedNumber = new ArrayList<String>();
|
|
115
|
+ expectedNumber.add("302-555-9988");
|
|
116
|
+ book.inputEntry("Frank", expectedNumber);
|
|
117
|
+
|
111
|
118
|
//When
|
112
|
|
- String actualNumber = book.lookup("Frank");
|
|
119
|
+ ArrayList<String> actualNumber = new ArrayList<String> (book.lookup("Frank"));
|
113
|
120
|
//Then
|
114
|
121
|
Assert.assertEquals(expectedNumber, actualNumber);
|
115
|
122
|
}
|
|
@@ -120,9 +127,13 @@ public class PhoneBookTest {
|
120
|
127
|
//Given
|
121
|
128
|
PhoneBook book = new PhoneBook();
|
122
|
129
|
String expectedName = "Bob";
|
123
|
|
- book.add(expectedName, "302-555-1234");
|
124
|
|
- //When
|
125
|
|
- String actualName = book.reverseLookup("302-555-1234");
|
|
130
|
+ ArrayList<String> bobNumber = new ArrayList<String>();
|
|
131
|
+ bobNumber.add("302-555-2223");
|
|
132
|
+ book.inputEntry(expectedName, bobNumber);
|
|
133
|
+
|
|
134
|
+ //When;
|
|
135
|
+ String actualName = book.reverseLookup("302-555-2223");
|
|
136
|
+
|
126
|
137
|
//Then
|
127
|
138
|
Assert.assertEquals(expectedName, actualName);
|
128
|
139
|
}
|
|
@@ -130,11 +141,18 @@ public class PhoneBookTest {
|
130
|
141
|
|
131
|
142
|
@Test
|
132
|
143
|
public void testDisplay() {
|
133
|
|
- //Given: need help from instructor
|
134
|
|
- String expectedNameNumber = "Bob 302-555-1234\nFrank 777-555-1111\n";
|
|
144
|
+ //Given:
|
135
|
145
|
PhoneBook book = new PhoneBook();
|
136
|
|
- book.add("Bob", "302-555-1234");
|
137
|
|
- book.add("Frank", "777-555-1111");
|
|
146
|
+ ArrayList<String> bobNumber = new ArrayList<String>();
|
|
147
|
+ bobNumber.add("302-555-1234");
|
|
148
|
+ bobNumber.add("302-556-1245");
|
|
149
|
+ ArrayList<String> frankNumber = new ArrayList<String>();
|
|
150
|
+ frankNumber.add("777-555-1111");
|
|
151
|
+ book.inputEntry("Bob", bobNumber);
|
|
152
|
+ book.inputEntry("Frank", frankNumber);
|
|
153
|
+
|
|
154
|
+ String expectedNameNumber = "Bob " + bobNumber.toString() + "\n" + "Frank " + frankNumber.toString() + "\n";
|
|
155
|
+
|
138
|
156
|
//When
|
139
|
157
|
String actualNameNumber = book.display();
|
140
|
158
|
//Then
|