|
@@ -1,5 +1,6 @@
|
1
|
1
|
package com.zipcodewilmington.phonebook;
|
2
|
2
|
|
|
3
|
+import com.sun.org.apache.xpath.internal.operations.Bool;
|
3
|
4
|
import org.junit.Assert;
|
4
|
5
|
import org.junit.Before;
|
5
|
6
|
import org.junit.Test;
|
|
@@ -9,69 +10,76 @@ import java.util.TreeMap;
|
9
|
10
|
/**
|
10
|
11
|
* Created by leon on 1/23/18.
|
11
|
12
|
*/
|
|
13
|
+
|
12
|
14
|
public class PhoneBookTest {
|
13
|
|
- // constructor
|
14
|
|
- String name = "Jess";
|
15
|
|
- String number = "1234567";
|
16
|
|
- String nameA = "Alice";
|
17
|
|
- String numberA = "1111111";
|
18
|
|
- String nameB = "Sean";
|
19
|
|
- String numberB = "2222222";
|
20
|
|
-
|
21
|
|
- private PhoneBook phoneBook = new PhoneBook();
|
22
|
|
- // instance
|
23
|
|
-
|
24
|
|
-
|
25
|
|
- @Before
|
26
|
|
- public void setUp(){
|
27
|
|
- phoneBook = new PhoneBook();
|
28
|
|
- }
|
29
|
|
-
|
30
|
|
- @Test
|
31
|
|
- public boolean testAddAContact() {
|
32
|
|
- //instance of new phone book
|
33
|
|
-// phoneBook.addAContact(name, number);
|
34
|
|
-// Assert.assertTrue(phoneBook.addAContact(name, number).equals(name, number));
|
35
|
|
- TreeMap.containsKey(String);
|
36
|
|
- Assert.assertTrue(phoneBook.addAContact(name));
|
37
|
|
-
|
38
|
|
- }
|
39
|
|
-@Test
|
40
|
|
- public void removeAContact(String name){
|
41
|
|
- //Given
|
42
|
|
- String expected = "Null";
|
43
|
|
-
|
44
|
|
- //When
|
45
|
|
- phoneBook.addAContact(expected);
|
46
|
|
- tmap.add(name);
|
47
|
|
- //first must add a name to map
|
48
|
|
-
|
49
|
|
- phoneBook.lookupContactName(expected);
|
50
|
|
- String actual = phoneBook.removeAContact();
|
51
|
|
- tmap.remove(name);
|
52
|
|
- //Then
|
53
|
|
- Assert.assertTrue(expected, actual);
|
|
15
|
+ private static PhoneBook phoneBookTest;
|
|
16
|
+
|
|
17
|
+ public void setUp() {
|
|
18
|
+ phoneBookTest = new PhoneBook();
|
|
19
|
+ }
|
|
20
|
+
|
|
21
|
+ @Test
|
|
22
|
+ public void testAdd() {
|
|
23
|
+ PhoneBook phoneBook = new PhoneBook();
|
|
24
|
+ phoneBook.add("Jess", "3333333");
|
|
25
|
+ String expected = phoneBook.lookup("Jess");
|
|
26
|
+ Assert.assertEquals(expected, "3333333");
|
54
|
27
|
}
|
|
28
|
+
|
55
|
29
|
@Test
|
56
|
|
- public void testLookupContactName (){
|
57
|
|
- //Given
|
58
|
|
- phoneBook.lookupContactName("Jess");
|
59
|
|
- String expected = "1234567";
|
|
30
|
+ public void testDelete() {
|
|
31
|
+ PhoneBook phoneBook = new PhoneBook();
|
|
32
|
+ phoneBook.add("Kat", "2342233");
|
|
33
|
+ Boolean actual = phoneBook.delete("Kat");
|
|
34
|
+ Assert.assertTrue(actual);
|
|
35
|
+ }
|
60
|
36
|
|
61
|
|
- //When
|
62
|
|
- String actual = phoneBook.lookupContactName("Jess");
|
|
37
|
+ @Test
|
|
38
|
+ public void testLookup() {
|
|
39
|
+ PhoneBook phoneBook = new PhoneBook();
|
|
40
|
+ phoneBook.add("Sean", "556665");
|
|
41
|
+ String actual = phoneBook.lookup("Sean");
|
|
42
|
+ Assert.assertEquals("556665", actual);
|
|
43
|
+ }
|
63
|
44
|
|
64
|
|
- //Then
|
65
|
|
- Assert.assertEquals(expected, actual);
|
|
45
|
+ // actual is what method in Phonebook class gives us back
|
|
46
|
+ @Test
|
|
47
|
+ public void testReverseLookup() {
|
|
48
|
+ PhoneBook phoneBook = new PhoneBook();
|
|
49
|
+ phoneBook.add("Sean", "556665");
|
|
50
|
+ String actual = phoneBook.reverseLookup("556665");
|
|
51
|
+ Assert.assertEquals("Sean", actual);
|
66
|
52
|
}
|
67
|
53
|
|
68
|
54
|
@Test
|
69
|
|
- public void printOut(){
|
70
|
|
- System.out.println(phoneBook.listOfAllNames());
|
|
55
|
+ public void testListAllNames() {
|
|
56
|
+ PhoneBook phoneBook = new PhoneBook();
|
|
57
|
+ phoneBook.add("Sean", "556665");
|
|
58
|
+ phoneBook.add("Joe", "9766847");
|
|
59
|
+ phoneBook.add("Bree", "993255");
|
|
60
|
+ String expected = "Name Bree\nName Joe\nName Sean\n";
|
|
61
|
+ String actual = phoneBook.listAllNames();
|
|
62
|
+ Assert.assertEquals(expected, actual);
|
|
63
|
+ }
|
71
|
64
|
|
|
65
|
+ @Test
|
|
66
|
+ public void testListAllNamesAndNumbers() {
|
|
67
|
+ PhoneBook phoneBook = new PhoneBook();
|
|
68
|
+ phoneBook.add("Sean", "5566651111");
|
|
69
|
+ phoneBook.add("Joe", "9766847111");
|
|
70
|
+ phoneBook.add("Bree", "9932551111");
|
|
71
|
+ String expected = "Name Bree\n Number: 9932551111\n" +
|
|
72
|
+ "Name Joe\n Number: 9766847111\n" +
|
|
73
|
+ "Name Sean\n Number: 5566651111\n";
|
|
74
|
+ String actual = phoneBook.listAllNamesAndNumbers();
|
|
75
|
+ Assert.assertEquals(expected, actual);
|
72
|
76
|
}
|
73
|
77
|
}
|
74
|
78
|
|
75
|
79
|
|
76
|
80
|
|
77
|
81
|
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
|