123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191 |
- import java.util.*;
- import static org.junit.Assert.*;
- import org.junit.After;
- import org.junit.Before;
- import org.junit.Test;
-
- /**
- * The test class PhoneBookTest.
- *
- * @author (your name)
- * @version (a version number or a date)
- */
- public class PhoneBookTest
- {
- @Test
- public void testAddEntry(){
- //given
- PhoneBook phoneBook = new PhoneBook();
-
- //actual
- phoneBook.addEntry("eric", "3025884804", "3025884805", "3025884806");
- String actual = phoneBook.lookup("eric");
-
- //expected
- String expected = "3025884804, 3025884805, 3025884806";
-
- //test
- assertEquals(expected, actual);
- }
-
- @Test
- public void testAddEntryMultiple(){
- //given
- PhoneBook phoneBook = new PhoneBook();
-
- //actual
- phoneBook.addEntry("eric", "3025884804", "3025884805", "3025884806");
- phoneBook.addEntry("john", "3025844804", "3025884705");
- phoneBook.addEntry("jane", "3025884704");
- String actual = phoneBook.lookup("eric");
- String actual1 = phoneBook.lookup("john");
- String actual2 = phoneBook.lookup("jane");
-
- //expected
- String expected = "3025884804, 3025884805, 3025884806";
- String expected1 = "3025844804, 3025884705";
- String expected2 = "3025884704";
-
- //test
- assertEquals(expected, actual);
- }
-
- @Test
- public void testRemoveEntry(){
- //given
- PhoneBook phoneBook = new PhoneBook();
-
- //actual
- phoneBook.addEntry("eric", "3025884804", "3025884805", "3025884806");
- phoneBook.removeEntry("eric");
- String actual = phoneBook.lookup("eric");
-
- //expected
- String expected = null;
-
- //test
- assertEquals(expected, actual);
- }
-
- @Test
- public void testRemoveEntryMultiple(){
- //given
- PhoneBook phoneBook = new PhoneBook();
-
- //actual
- phoneBook.addEntry("eric", "3025884804", "3025884805", "3025884806");
- phoneBook.addEntry("john", "3025844804", "3025884705");
- phoneBook.addEntry("jane", "3025884704");
- phoneBook.removeEntry("john");
- phoneBook.removeEntry("eric");
- String actual = phoneBook.lookup("john");
- String actual1 = phoneBook.lookup("eric");
- String actual2 = phoneBook.lookup("jane");
-
- //expected
- String expected = null;
- String expected1 = null;
- String expected2 = "3025884704";
-
- //test
- assertEquals(expected, actual);
- assertEquals(expected1, actual1);
- assertEquals(expected2, actual2);
- }
-
- @Test
- public void testReverseLookup(){
- //given
- PhoneBook phoneBook = new PhoneBook();
-
- //actual
- phoneBook.addEntry("eric", "3025884804", "3025884805", "3025884806");
- phoneBook.addEntry("john", "3025844804", "3025884705");
- phoneBook.addEntry("jane", "3025884704");
- String actual = phoneBook.reverseLookup("3025884804", "3025884805", "3025884806");
- String actual1 = phoneBook.reverseLookup("3025844804", "3025884705");
- String actual2 = phoneBook.reverseLookup("3025884704");
- String actual3 = phoneBook.reverseLookup("4025884704");
-
- //expected
- String expected = "eric";
- String expected1 = "john";
- String expected2 = "jane";
- String expected3 = null;
-
- //test
- assertEquals(expected, actual);
- assertEquals(expected1, actual1);
- assertEquals(expected2, actual2);
- assertEquals(expected3, actual3);
- }
-
- @Test
- public void testAddNumberToEntry(){
- //given
- PhoneBook phoneBook = new PhoneBook();
-
- //actual
- phoneBook.addEntry("eric", "3025884804", "3025884805", "3025884806");
- phoneBook.addNumberToEntry("eric", "3025884807");
- String actual = phoneBook.lookup("eric");
-
- //expected
- String expected = "3025884804, 3025884805, 3025884806, 3025884807";
-
- //test
- assertEquals(expected, actual);
- }
-
- @Test
- public void testAddNumberToEntryMultiple(){
- //given
- PhoneBook phoneBook = new PhoneBook();
-
- //actual
- phoneBook.addEntry("john", "3025884804", "3025884705");
- phoneBook.addNumberToEntry("john", "3025884788", "3025884789");
- String actual = phoneBook.lookup("john");
-
- //expected
- String expected = "3025884804, 3025884705, 3025884788, 3025884789";
-
- //test
- assertEquals(expected, actual);
- }
-
- @Test
- public void testRemoveNumberFromEntry(){
- //given
- PhoneBook phoneBook = new PhoneBook();
-
- //actual
- phoneBook.addEntry("eric", "3025884804", "3025884805", "3025884806");
- phoneBook.removeNumberFromEntry("eric", "3025884805");
- String actual = phoneBook.lookup("eric");
-
- //expected
- String expected = "3025884804, 3025884806";
-
- //test
- assertEquals(expected, actual);
- }
-
- @Test
- public void testRemoveNumberFromEntryMultiple(){
- //given
- PhoneBook phoneBook = new PhoneBook();
-
- //actual
- phoneBook.addEntry("eric", "3025884804", "3025884805", "3025884806", "3025884807");
- phoneBook.removeNumberFromEntry("eric", "3025884804", "3025884806");
- String actual = phoneBook.lookup("eric");
-
- //expected
- String expected = "3025884805, 3025884807";
-
- //test
- assertEquals(expected, actual);
- }
- }
|