|
@@ -5,38 +5,57 @@ import org.junit.After;
|
5
|
5
|
import org.junit.Before;
|
6
|
6
|
import org.junit.Test;
|
7
|
7
|
|
8
|
|
-/**
|
9
|
|
- * The test class PhoneBookTest.
|
10
|
|
- *
|
11
|
|
- * @author (your name)
|
12
|
|
- * @version (a version number or a date)
|
13
|
|
- */
|
|
8
|
+
|
14
|
9
|
public class PhoneBookTest
|
15
|
10
|
{
|
16
|
|
- /**
|
17
|
|
- * Default constructor for test class PhoneBookTest
|
18
|
|
- */
|
19
|
|
- public PhoneBookTest()
|
|
11
|
+ @Test
|
|
12
|
+ public void testAdd()
|
20
|
13
|
{
|
|
14
|
+ PhoneBook test = new PhoneBook();
|
|
15
|
+ boolean expected = true;
|
|
16
|
+ String name = "Jenny";
|
|
17
|
+ String number = "(302)-867-5309";
|
|
18
|
+ test.add(name, number);
|
|
19
|
+
|
|
20
|
+ boolean actual = test.getPhoneBook().containsKey(name);
|
|
21
|
+ assertEquals(expected, actual);
|
21
|
22
|
}
|
22
|
|
-
|
23
|
|
- /**
|
24
|
|
- * Sets up the test fixture.
|
25
|
|
- *
|
26
|
|
- * Called before every test case method.
|
27
|
|
- */
|
28
|
|
- @Before
|
29
|
|
- public void setUp()
|
|
23
|
+ // vvvv I hope this is okay since I know the add method works now vvvv
|
|
24
|
+ @Test
|
|
25
|
+ public void testAddPhoneBookEntry_And_Lookup()
|
30
|
26
|
{
|
|
27
|
+ PhoneBook test = new PhoneBook();
|
|
28
|
+ String name = "Jenny";
|
|
29
|
+ String expectedNumber = "(302)-867-5309";
|
|
30
|
+ test.add(name, expectedNumber);
|
|
31
|
+
|
|
32
|
+ String actual = test.lookup(name);
|
|
33
|
+ assertEquals(expectedNumber, actual);
|
31
|
34
|
}
|
32
|
|
-
|
33
|
|
- /**
|
34
|
|
- * Tears down the test fixture.
|
35
|
|
- *
|
36
|
|
- * Called after every test case method.
|
37
|
|
- */
|
38
|
|
- @After
|
39
|
|
- public void tearDown()
|
|
35
|
+
|
|
36
|
+ @Test
|
|
37
|
+ public void testRemovePhoneBookEntry_And_Lookup()
|
40
|
38
|
{
|
|
39
|
+ PhoneBook test = new PhoneBook();
|
|
40
|
+ String name = "Jenny";
|
|
41
|
+ String wrongName = "Tommy Tutone";
|
|
42
|
+ String number = "(302)-867-5309";
|
|
43
|
+ test.add(name, number);
|
|
44
|
+
|
|
45
|
+ String actual = test.lookup(wrongName);
|
|
46
|
+ assertEquals("N/A", actual);
|
41
|
47
|
}
|
|
48
|
+
|
|
49
|
+ @Test
|
|
50
|
+ public void testReverseLookup()
|
|
51
|
+ {
|
|
52
|
+ PhoneBook test = new PhoneBook();
|
|
53
|
+ String phoneNumber = "(302)-867-5309";
|
|
54
|
+ String expectedName = "Jenny";
|
|
55
|
+ test.add(expectedName, phoneNumber);
|
|
56
|
+
|
|
57
|
+ String actual = test.reverseLookup(phoneNumber);
|
|
58
|
+ assertEquals(expectedName, actual);
|
|
59
|
+
|
|
60
|
+ }
|
42
|
61
|
}
|