import 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 { TreeMap> phoneBook = new TreeMap<>(); /** * Default constructor for test class PhoneBookTest */ public PhoneBookTest() { } /** * Sets up the test fixture. * * Called before every test case method. */ @Before public void setUp() { PhoneBook pb = new PhoneBook(); } /** * Tears down the test fixture. * * Called after every test case method. */ @After public void tearDown() { } // add entries @Test public void testAdd() { String expected = "Zebra 111-222-3333 222-444-5555\n"; PhoneBook pb = new PhoneBook(); pb.add("Zebra", "111-222-3333"); pb.add("Zebra", "222-444-5555"); String actual = pb.display(); Assert.assertEquals(expected, actual); } @Test public void testRemove() { String expected = "Zebra 222-444-5555\n"; PhoneBook pb = new PhoneBook(phoneBook); pb.add("Zebra", "111-222-3333"); pb.add("Zebra", "222-444-5555"); pb.remove("Zebra", "111-222-3333"); String actual = pb.display(); Assert.assertEquals(expected, actual); } @Test public void testRemoveRecord() { String expected = "Zebra 222-444-5555\n"; PhoneBook pb = new PhoneBook(phoneBook); pb.add("Dog", "111-222-3333"); pb.add("Dog", "333-444-5555"); pb.add("Zebra", "222-444-5555"); pb.removeRecord("Dog"); String actual = pb.display(); Assert.assertEquals(expected, actual); } @Test public void testLookup() { ArrayList expected = new ArrayList<>(); expected.add("111-222-3333"); expected.add("222-444-5555"); PhoneBook pb = new PhoneBook(phoneBook); pb.add("Zebra", "111-222-3333"); pb.add("Zebra", "222-444-5555"); ArrayList actual = pb.lookup("Zebra"); Assert.assertEquals(expected, actual); } @Test public void testReverseLookup() { String expected = "Zebra"; PhoneBook pb = new PhoneBook(phoneBook); pb.add("Zebra", "111-222-3333"); pb.add("Zebra", "222-444-5555"); String actual = pb.reverseLookup("222-444-5555"); Assert.assertEquals(expected, actual); } }