|
@@ -5,6 +5,7 @@ import org.junit.Assert;
|
5
|
5
|
import org.junit.Before;
|
6
|
6
|
import org.junit.Test;
|
7
|
7
|
|
|
8
|
+import java.util.List;
|
8
|
9
|
import java.util.Map;
|
9
|
10
|
import java.util.TreeMap;
|
10
|
11
|
|
|
@@ -16,14 +17,12 @@ import java.util.TreeMap;
|
16
|
17
|
|
17
|
18
|
|
18
|
19
|
public class PhoneBookTest {
|
19
|
|
- private static PhoneBook phoneBookRecord;
|
|
20
|
+ private static PhoneBook phoneBookTest;
|
20
|
21
|
|
21
|
|
- @Before
|
22
|
|
- public void setUp() {
|
23
|
|
- //PhoneBook phoneBookRecord;
|
24
|
|
- Map<String,String>initialRecord = new TreeMap<String, String>(){ {put("John","1234567890");put("Micheal","5678901234");
|
25
|
|
- put("James","1234554321");}};
|
26
|
|
- this.phoneBookRecord=new PhoneBook(initialRecord);
|
|
22
|
+ @Before
|
|
23
|
+ public void setUp() {
|
|
24
|
+ PhoneBook phoneBookTest = new PhoneBook();
|
|
25
|
+ phoneBookTest.add("John","1234567890");
|
27
|
26
|
|
28
|
27
|
}
|
29
|
28
|
|
|
@@ -32,42 +31,62 @@ public class PhoneBookTest {
|
32
|
31
|
}
|
33
|
32
|
|
34
|
33
|
@Test
|
35
|
|
- public void testLookup() {
|
36
|
|
- String expected = "5678901234";
|
37
|
|
- String actual = phoneBookRecord.lookup("Micheal");
|
38
|
|
- Assert.assertEquals(expected, actual);
|
|
34
|
+ public void testLookup() {
|
|
35
|
+ PhoneBook phoneBookTest = new PhoneBook();
|
|
36
|
+ phoneBookTest.add("James","555555555");
|
|
37
|
+
|
|
38
|
+ String actual = phoneBookTest.lookup("John");
|
|
39
|
+ Assert.assertEquals("555555555 ",actual);
|
39
|
40
|
}
|
40
|
41
|
@Test
|
41
|
42
|
public void testListNames(){
|
|
43
|
+ PhoneBook phoneBookTest = new PhoneBook();
|
|
44
|
+ phoneBookTest.add("John","1234567890");
|
|
45
|
+ phoneBookTest.add("James","555555555");
|
42
|
46
|
String expected = "James\n" +
|
43
|
|
- "John\n"+
|
44
|
|
- "Micheal\n";
|
45
|
|
- String actual = phoneBookRecord.listNames();
|
|
47
|
+ "John\n";
|
|
48
|
+ String actual = phoneBookTest.listNames();
|
46
|
49
|
Assert.assertEquals(expected, actual);
|
47
|
50
|
|
48
|
51
|
}
|
49
|
52
|
@Test
|
50
|
53
|
public void testListNumbersAndNumbers(){
|
51
|
|
- String expected = "James "+ "1234554321\n"+
|
52
|
|
- "John "+"1234567890\n"+
|
53
|
|
- "Micheal "+"5678901234";
|
54
|
|
- String actual =phoneBookRecord.listNamesAndNumbers();
|
|
54
|
+ PhoneBook phoneBookTest = new PhoneBook();
|
|
55
|
+ phoneBookTest.add("John","1234567890");
|
|
56
|
+ phoneBookTest.add("James","555555555");
|
|
57
|
+ phoneBookTest.add("Micheal","5678901234");
|
|
58
|
+ String expected = "James "+ "555555555\n"+
|
|
59
|
+ "John "+"1234567890\n"+
|
|
60
|
+ "Micheal "+"5678901234\n";
|
|
61
|
+ String actual =phoneBookTest.listNamesAndNumbers();
|
55
|
62
|
Assert.assertEquals(expected, actual);
|
56
|
63
|
}
|
57
|
64
|
|
58
|
65
|
@Test
|
59
|
66
|
public void testAdd(){
|
|
67
|
+ PhoneBook phoneBookTest = new PhoneBook();
|
60
|
68
|
boolean expected = true;
|
61
|
|
- boolean actual = phoneBookRecord.add("Peter","7777777777");
|
|
69
|
+ boolean actual = phoneBookTest.add("Peter","7777777777");
|
62
|
70
|
Assert.assertEquals(expected, actual);
|
63
|
71
|
|
64
|
72
|
}
|
65
|
73
|
@Test
|
66
|
74
|
public void testRemove(){
|
|
75
|
+ PhoneBook phoneBookTest = new PhoneBook();
|
|
76
|
+ phoneBookTest.add("John","1234567890");
|
67
|
77
|
boolean expected =true;
|
68
|
|
- boolean actual = phoneBookRecord.remove("John");
|
|
78
|
+ boolean actual = phoneBookTest.remove("John");
|
69
|
79
|
Assert.assertEquals(expected, actual);
|
70
|
80
|
}
|
|
81
|
+ @Test
|
|
82
|
+ public void testReverseLookup() {
|
|
83
|
+ PhoneBook phoneBookTest = new PhoneBook();
|
|
84
|
+ phoneBookTest.add("James","555555555");
|
|
85
|
+
|
|
86
|
+ String actual = phoneBookTest.reverseLookUp("555555555");
|
|
87
|
+ Assert.assertEquals("James",actual);
|
|
88
|
+ }
|
|
89
|
+
|
71
|
90
|
|
72
|
91
|
|
73
|
92
|
}
|