|
@@ -5,54 +5,84 @@ import org.junit.Before;
|
5
|
5
|
import org.junit.Test;
|
6
|
6
|
|
7
|
7
|
import java.util.ArrayList;
|
8
|
|
-import java.util.Map;
|
9
|
|
-import java.util.Set;
|
|
8
|
+
|
|
9
|
+import static junit.framework.TestCase.assertTrue;
|
|
10
|
+import static org.junit.Assert.assertEquals;
|
10
|
11
|
|
11
|
12
|
|
12
|
13
|
/**
|
13
|
14
|
* Created by leon on 1/23/18.
|
14
|
15
|
*/
|
15
|
|
-public class PhoneBookTest {
|
16
|
|
-
|
|
16
|
+ public class PhoneBookTest {
|
17
|
17
|
|
18
|
18
|
PhoneBook phoneBook;
|
19
|
19
|
|
20
|
20
|
@Before
|
21
|
|
- public void setUp(){
|
|
21
|
+ public void setUp() {
|
22
|
22
|
phoneBook = new PhoneBook();
|
|
23
|
+ }
|
23
|
24
|
|
|
25
|
+ @Test
|
|
26
|
+ public void addNewEntryTest(){
|
|
27
|
+ String name = "April";
|
|
28
|
+ String number = "6547783321";
|
|
29
|
+ phoneBook.addNewEntry(name, number);
|
|
30
|
+ boolean entryHasBeenCreated = phoneBook.getPhoneBook().containsKey(name);
|
|
31
|
+ assertTrue(entryHasBeenCreated);
|
24
|
32
|
}
|
25
|
33
|
@Test
|
26
|
|
- public void addContactTest(){
|
27
|
|
- phoneBook.addContact("Genya", "6578356767");
|
28
|
|
- boolean genyaIsInPhoneBook = phoneBook.getContactsList().keySet().contains("Genya");
|
29
|
|
- Assert.assertTrue(genyaIsInPhoneBook);
|
30
|
|
-
|
|
34
|
+ public void removeEntryTest(){
|
|
35
|
+ String name = "April";
|
|
36
|
+ String number = "6547783321";
|
|
37
|
+ phoneBook.addNewEntry(name, number);
|
|
38
|
+ phoneBook.removeEntry(name);
|
|
39
|
+ boolean entryHasBeenRemoved = !phoneBook.getPhoneBook().containsKey(name);
|
|
40
|
+ assertTrue(entryHasBeenRemoved);
|
31
|
41
|
}
|
32
|
42
|
@Test
|
33
|
|
- public void removeContactTest(){
|
34
|
|
- phoneBook.removeContact("Pete Jones");
|
35
|
|
- boolean peteJonesHasBeenRemoved = !phoneBook.getContactsList().containsKey("Pete Jones");
|
36
|
|
- Assert.assertTrue(peteJonesHasBeenRemoved);
|
|
43
|
+ public void removeNumberTest(){
|
|
44
|
+ String name = "April";
|
|
45
|
+ String number = "6547783321";
|
|
46
|
+ phoneBook.addNewEntry(name, number);
|
|
47
|
+ phoneBook.removeNumber(name, number);
|
|
48
|
+ boolean numberHasBeenRemovedFromContact = !phoneBook.getPhoneBook().get(name).getPhoneNumbers().contains(number);
|
|
49
|
+ assertTrue(numberHasBeenRemovedFromContact);
|
|
50
|
+ }
|
|
51
|
+ @Test
|
|
52
|
+ public void lookUpContactPhoneNumbersTest(){
|
|
53
|
+ String name = "April";
|
|
54
|
+ String number = "6547783321";
|
|
55
|
+ phoneBook.addNewEntry(name, number);
|
|
56
|
+ ArrayList<String> actualPhoneList = phoneBook.lookUpContactPhoneNumbers(name);
|
|
57
|
+ ArrayList<String> expectedPhoneList = new ArrayList<>();
|
|
58
|
+ expectedPhoneList.add(number);
|
|
59
|
+ assertEquals(expectedPhoneList, actualPhoneList);
|
37
|
60
|
}
|
38
|
|
-
|
39
|
61
|
@Test
|
40
|
62
|
public void listAllNamesAndNumbersTest(){
|
|
63
|
+ String name = "April";
|
|
64
|
+ String number = "6547783321";
|
|
65
|
+ String secondName = "Genya";
|
|
66
|
+ String secondNumber = "8753349987";
|
|
67
|
+ phoneBook.addNewEntry(name, number);
|
|
68
|
+ phoneBook.addNewEntry(secondName, secondNumber);
|
|
69
|
+ String actual = phoneBook.toString();
|
|
70
|
+ String expected = "April 6547783321 Genya 8753349987";
|
|
71
|
+ assertEquals(expected, actual);
|
|
72
|
+ //Print all the things
|
41
|
73
|
phoneBook.listAllNamesAndNumbers();
|
42
|
|
- String expected = new String();
|
43
|
|
- Set<Map.Entry<String, ArrayList>> actual = phoneBook.getContactsList().entrySet();
|
44
|
|
- Assert.assertEquals(expected, actual);
|
45
|
74
|
}
|
46
|
|
-
|
47
|
75
|
@Test
|
48
|
76
|
public void reverseLookUpTest(){
|
49
|
|
- phoneBook.reverseLookUp();
|
50
|
|
- String expected = new String();
|
51
|
|
- Set<Map.Entry<String, ArrayList>> actual = phoneBook.getContactsList().entrySet();
|
52
|
|
- Assert.assertEquals(expected, actual);
|
53
|
|
-
|
|
77
|
+ String name = "April";
|
|
78
|
+ String number = "6547783321";
|
|
79
|
+ String secondName = "Genya";
|
|
80
|
+ String secondNumber = "8753349987";
|
|
81
|
+ phoneBook.addNewEntry(name, number);
|
|
82
|
+ phoneBook.addNewEntry(secondName, secondNumber);
|
|
83
|
+ String actual = phoneBook.reverseLookUp(number);
|
|
84
|
+ String expected = "April";
|
|
85
|
+ assertEquals(expected, actual);
|
54
|
86
|
}
|
55
|
87
|
|
56
|
88
|
}
|
57
|
|
-
|
58
|
|
-
|