import org.junit.Assert; import org.junit.After; import org.junit.Before; import org.junit.Test; import java.util.Iterator; import java.util.Map; import java.util.Set; import java.util.SortedMap; import java.util.TreeMap; import java.util.ArrayList; /** * The test class PhoneBookTest. * * @author (your name) * @version (a version number or a date) */ public class PhoneBookTest { PhoneBook book; @Before public void setUp() { this.book = new PhoneBook(); } @Test public void addTest() { //Given //When book.add("Leeks", "194-345-3458"); String lookup = book.lookup("Leeks"); //Then Assert.assertEquals("194-345-3458", lookup); } @Test public void lookupTest() { //Given book.add("Leeks", "194-345-3458"); book.add("Leeks", "345-234-4643"); String phoneNumber = book.lookup("Leeks"); //Then Assert.assertEquals("194-345-3458, 345-234-4643", phoneNumber); } @Test public void lookupTest1() { //Given book.add("Leeks", "194-345-3458"); book.add("Leeks", "345-234-4643"); String phoneNumber = book.lookup("Banana"); //Then Assert.assertEquals("This entry doesn't exist. Please enter valid entry.", phoneNumber); } @Test public void removeTest() { //Given book.add("Leeks", "194-345-3458"); book.add("Leeks", "345-234-4643"); book.remove("Leeks", "194-345-3458"); //When String phoneNumber = book.lookup("Leeks"); //Then Assert.assertEquals("345-234-4643", phoneNumber); } @Test public void removeTest1() { //Given //When book.add("Leeks", "194-345-3458"); book.add("Leeks", "345-234-4643"); book.remove("Leeks", "194-345-3458"); book.remove("Leeks", "345-234-4643"); //Then Assert.assertEquals("This entry doesn't exist. Please enter valid entry.", book.lookup("Leeks")); } @Test public void reverseLookupTest() { //Given book.add("Leeks", "194-345-3458"); //When String name = book.reverseLookup("194-345-3458"); //Then Assert.assertEquals("Leeks", name); } @Test public void reverseLookupTest1() { //Given book.add("Leeks", "194-345-3458"); book.remove("Leeks", "194-345-3458"); //When String name = book.reverseLookup("194-345-3458"); //Then Assert.assertEquals("This entry doesn't exist. Please enter valid entry.", name); } }