import static org.junit.Assert.*; import org.junit.After; import org.junit.Before; import org.junit.Test; import java.util.*; /** * The test class PhoneBookTest. * * @author (your name) * @version (a version number or a date) */ public class PhoneBookTest { PhoneBook test = new PhoneBook(); /** * Default constructor for test class PhoneBookTest */ public PhoneBookTest() { } /** * Sets up the test fixture. * * Called before every test case method. */ @Before public void setUp() { } @Test public void addTest(){ //Given ArrayList list = new ArrayList(); list.add("5704282076"); //When int expected = 1; TreeMap actual = test.add("Chad", list); //Result assertEquals(expected, actual.size()); } @Test public void removeRecordTest(){ //Given ArrayList list = new ArrayList(); list.add("5704282076"); list.add("5707429337"); test.add("Chad", list); //When int expected = 0; TreeMap actual = test.removeRecord("Chad"); //Result assertEquals(expected, actual.size()); } @Test public void lookUpTest(){ //Given ArrayList list = new ArrayList(); list.add("5704282076"); test.add("Chad", list); //When ArrayList expected = list; ArrayList actual = test.lookUp("Chad"); //Result assertEquals(expected, actual); } @Test public void invertMapTest(){ //Given ArrayList list = new ArrayList(); list.add("5704282076"); test.add("Chad", list); test.invertMap(); //When String expected = "Chad"; String actual = test.reverseLookUp("5704282076"); //Result assertEquals(expected, actual); } @Test public void displayTest(){ //Given ArrayList list = new ArrayList(); list.add("5704282076"); ArrayList list1 = new ArrayList(); list1.add("111-222-333"); ArrayList list2 = new ArrayList(); list2.add("222-444-4444"); test.add("Chad", list); test.add("Zebra", list1); test.add("Dog", list2); //When String expected = "Chad 5704282076\nDog 222-444-4444\nZebra 111-222-333\n"; String actual = test.display(); //Result assertEquals(expected, actual); } @Test public void arrayContainsTest(){ //Given ArrayList list = new ArrayList(); list.add("5704282076"); //When boolean actual = test.arrayContains(list,"5704282076"); //Result assertTrue(actual); } @Test public void removeTest(){ //Given ArrayList list = new ArrayList(); list.add("5704282076"); list.add("5707429337"); ArrayList list1 = new ArrayList(); list1.add("111-222-333"); ArrayList list2 = new ArrayList(); list2.add("222-444-4444"); test.add("Chad", list); test.add("Zebra", list1); test.add("Dog", list2); test.remove("Chad","5704282076"); //When boolean actual = test.arrayContains(list,"5704282076"); //Result assertFalse(actual); } /** * Tears down the test fixture. * * Called after every test case method. */ @After public void tearDown() { } }