|
@@ -1,7 +1,103 @@
|
1
|
1
|
package com.zipcodewilmington.phonebook;
|
2
|
2
|
|
3
|
|
-/**
|
4
|
|
- * Created by leon on 1/23/18.
|
5
|
|
- */
|
6
|
|
-public class PhoneBookTest {
|
|
3
|
+import com.zipcodewilmington.phonebook.PhoneBook;
|
|
4
|
+import org.junit.Assert;
|
|
5
|
+import org.junit.Test;
|
|
6
|
+
|
|
7
|
+public class PhoneBookTest
|
|
8
|
+{
|
|
9
|
+ private static final int Expected = 0;
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+@Test
|
|
13
|
+ public void testHasEntry()
|
|
14
|
+{
|
|
15
|
+ //Given
|
|
16
|
+ PhoneBook book = new PhoneBook();
|
|
17
|
+ String name = "John";
|
|
18
|
+ String phoneNumber = "111-111-1111";
|
|
19
|
+ book.hasEntry(name);
|
|
20
|
+ //When
|
|
21
|
+ boolean actualOutput = book.hasEntry(name);
|
|
22
|
+ //Then
|
|
23
|
+ Assert.assertEquals(true,actualOutput);
|
|
24
|
+ }
|
|
25
|
+
|
|
26
|
+@Test
|
|
27
|
+public void testAdd(){
|
|
28
|
+ //Given
|
|
29
|
+ PhoneBook book = new PhoneBook();
|
|
30
|
+ String name = "kayle";
|
|
31
|
+ String phoneNumber = "408-111-2222";
|
|
32
|
+
|
|
33
|
+ //When
|
|
34
|
+ //book.add(name, phoneNumber);
|
|
35
|
+ String actualOutput = book.add(name, phoneNumber);
|
|
36
|
+ //Then
|
|
37
|
+ Assert.assertEquals(null, actualOutput);
|
|
38
|
+ }
|
|
39
|
+
|
|
40
|
+@Test
|
|
41
|
+public void testLookup()
|
|
42
|
+ {
|
|
43
|
+ //Given
|
|
44
|
+ PhoneBook book = new PhoneBook();
|
|
45
|
+ String name = "Tayler";
|
|
46
|
+ String phoneNumber = "408-999-3333";
|
|
47
|
+
|
|
48
|
+ String actualOutput=book.lookup(name);
|
|
49
|
+
|
|
50
|
+ Assert.assertEquals(phoneNumber, actualOutput);
|
|
51
|
+ }
|
|
52
|
+
|
|
53
|
+@Test
|
|
54
|
+public void testLookup_forMultipleEntries()
|
|
55
|
+ {
|
|
56
|
+ //Given
|
|
57
|
+ PhoneBook book = new PhoneBook();
|
|
58
|
+ book.add("name1", "111");
|
|
59
|
+ book.add("name2", "408");
|
|
60
|
+
|
|
61
|
+ String name = "John";
|
|
62
|
+ String phoneNumber = "111-111-1111";
|
|
63
|
+
|
|
64
|
+ //book.lookup(name);
|
|
65
|
+ String actualOutput=book.lookup(name);
|
|
66
|
+
|
|
67
|
+ Assert.assertEquals(actualOutput ,phoneNumber );
|
|
68
|
+ }
|
|
69
|
+@Test
|
|
70
|
+public void testRemove()
|
|
71
|
+ {
|
|
72
|
+ PhoneBook book= new PhoneBook();
|
|
73
|
+ String expectedname="Kayle";
|
|
74
|
+ String name="Kayle";
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+ String actualOutput=book.hasRemove(name);
|
|
78
|
+ Assert.assertEquals(actualOutput,name);
|
|
79
|
+
|
|
80
|
+ }
|
|
81
|
+@Test
|
|
82
|
+public void testReserveLookup()
|
|
83
|
+ {
|
|
84
|
+ PhoneBook book= new PhoneBook();
|
|
85
|
+ String name="John";
|
|
86
|
+ String phoneNumber = book.lookup(name);
|
|
87
|
+ String actualOutput = book.reverseLookup(phoneNumber);
|
|
88
|
+
|
|
89
|
+ Assert.assertEquals(name,actualOutput);
|
|
90
|
+ }
|
|
91
|
+
|
|
92
|
+@Test
|
|
93
|
+public void testListNamesandNumbers()
|
|
94
|
+ {
|
|
95
|
+ PhoneBook book= new PhoneBook();
|
|
96
|
+ book.clearSortedMap();
|
|
97
|
+ book.add("Kayle", "408-111-2222");
|
|
98
|
+ book.add("John", "111-111-1111");
|
|
99
|
+ String expected = "John 111-111-1111\nKayle 408-111-2222\n";
|
|
100
|
+ String actualOutput= book.listNamesAndNumbers();
|
|
101
|
+ Assert.assertEquals(expected, actualOutput);
|
|
102
|
+ }
|
7
|
103
|
}
|