|
@@ -1,5 +1,4 @@
|
1
|
1
|
|
2
|
|
-
|
3
|
2
|
import static org.junit.Assert.*;
|
4
|
3
|
import org.junit.After;
|
5
|
4
|
import org.junit.Before;
|
|
@@ -12,31 +11,98 @@ import org.junit.Test;
|
12
|
11
|
* @version (a version number or a date)
|
13
|
12
|
*/
|
14
|
13
|
public class PhoneBookTest
|
15
|
|
-{
|
16
|
|
- /**
|
17
|
|
- * Default constructor for test class PhoneBookTest
|
18
|
|
- */
|
19
|
|
- public PhoneBookTest()
|
20
|
|
- {
|
|
14
|
+{ private PhoneBook phonebook;
|
|
15
|
+ private String name;
|
|
16
|
+ private String phoneNumber;
|
|
17
|
+
|
|
18
|
+ @Before
|
|
19
|
+ public void setUp(){
|
|
20
|
+ phonebook = new PhoneBook();
|
|
21
|
+
|
|
22
|
+ }
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+ @Test
|
|
27
|
+ public void addTestFirstNumberForName(){
|
|
28
|
+ String name = "Raymond";
|
|
29
|
+ String expected = "302-444-0094\n";
|
|
30
|
+
|
|
31
|
+ phonebook.addElement(name,"302-444-0094");
|
|
32
|
+ String actual = phonebook.lookUp(name);
|
|
33
|
+
|
|
34
|
+ assertEquals(expected,actual);
|
|
35
|
+
|
|
36
|
+ }
|
|
37
|
+
|
|
38
|
+ @Test
|
|
39
|
+ public void testAddKeyAlreadyExists() {
|
|
40
|
+ String name = "Raymond";
|
|
41
|
+ String phoneNumber1 = "302-450-8066";
|
|
42
|
+ String phoneNumber2 = "302-465-1770";
|
|
43
|
+
|
|
44
|
+ String expected = phoneNumber1 + "\n" + phoneNumber2 + "\n";
|
|
45
|
+ phonebook.addElement(name,phoneNumber1);
|
|
46
|
+ phonebook.addElement(name,phoneNumber2);
|
|
47
|
+ String actual = phonebook.lookUp(name);
|
|
48
|
+
|
|
49
|
+ assertEquals(expected,actual);
|
21
|
50
|
}
|
22
|
51
|
|
23
|
|
- /**
|
24
|
|
- * Sets up the test fixture.
|
25
|
|
- *
|
26
|
|
- * Called before every test case method.
|
27
|
|
- */
|
28
|
|
- @Before
|
29
|
|
- public void setUp()
|
30
|
|
- {
|
|
52
|
+ @Test
|
|
53
|
+ public void removeTest(){
|
|
54
|
+ String name1 = "Raymond";
|
|
55
|
+ String name2 = "Eric";
|
|
56
|
+ String phoneNumber1 = "302-450-8099";
|
|
57
|
+ String phoneNumber2 = "302-333-0003";
|
|
58
|
+ phonebook.addElement(name1, phoneNumber1);
|
|
59
|
+ phonebook.addElement(name2, phoneNumber2);
|
|
60
|
+
|
|
61
|
+ String expected = "Eric";
|
|
62
|
+ phonebook.remove(name1);
|
|
63
|
+ String actual = name2;
|
|
64
|
+
|
|
65
|
+ assertEquals(expected,actual);
|
31
|
66
|
}
|
32
|
67
|
|
33
|
|
- /**
|
34
|
|
- * Tears down the test fixture.
|
35
|
|
- *
|
36
|
|
- * Called after every test case method.
|
37
|
|
- */
|
38
|
|
- @After
|
39
|
|
- public void tearDown()
|
40
|
|
- {
|
|
68
|
+ @Test
|
|
69
|
+ public void lookUpTest(){
|
|
70
|
+ String name = "Raymond";
|
|
71
|
+ String phoneNumber = "302-333-3333";
|
|
72
|
+ phonebook.addElement(name,phoneNumber);
|
|
73
|
+
|
|
74
|
+ String expected = "302-333-3333";
|
|
75
|
+ phonebook.lookUp(name);
|
|
76
|
+ String actual = phoneNumber;
|
|
77
|
+
|
|
78
|
+ assertEquals(expected,actual);
|
41
|
79
|
}
|
|
80
|
+
|
|
81
|
+ @Test
|
|
82
|
+ public void reverseLookup(){
|
|
83
|
+ String name = "Raymond";
|
|
84
|
+ String phoneNumber = "302-333-3333";
|
|
85
|
+ phonebook.addElement(name,phoneNumber);
|
|
86
|
+
|
|
87
|
+ String expected = "Raymond";
|
|
88
|
+ phonebook.reverseLookup(phoneNumber);
|
|
89
|
+ String actual = name;
|
|
90
|
+
|
|
91
|
+ assertEquals(expected,actual);
|
|
92
|
+ }
|
|
93
|
+
|
|
94
|
+ @Test
|
|
95
|
+ public void displayTest(){
|
|
96
|
+ String name = "Raymond";
|
|
97
|
+ String phoneNumber = "302-450-2222";
|
|
98
|
+ phonebook.addElement(name,phoneNumber);
|
|
99
|
+
|
|
100
|
+ String expected = "Raymond:302-450-2222";
|
|
101
|
+ phonebook.display();
|
|
102
|
+ String actual = name + ":" + phoneNumber;
|
|
103
|
+
|
|
104
|
+ assertEquals(expected,actual);
|
|
105
|
+ }
|
|
106
|
+
|
|
107
|
+
|
42
|
108
|
}
|