Build a simple PhoneBook program.

PhoneBookTest.java 1.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import static org.junit.Assert.*;
  2. import org.junit.After;
  3. import org.junit.Before;
  4. import org.junit.Test;
  5. import java.util.TreeMap;
  6. import java.util.Map;
  7. import java.util.ArrayList;
  8. public class PhoneBookTest {
  9. PhoneBook pb = new PhoneBook();
  10. ArrayList<String> numbers = new ArrayList<String>();
  11. @Test
  12. public void addTest(){
  13. String entry = pb.add("Kris", "666-666-6666");
  14. int actual = pb.getSize();
  15. assertEquals(1, actual);
  16. }
  17. @Test
  18. public void removeTest(){
  19. pb.add("Emily", "777-777-7777");
  20. pb.add("Karl", "888-888-8888");
  21. pb.add("Chad", "999-999-9999");
  22. String entry = pb.remove("Emily");
  23. assertEquals(false, pb.keyExists("Emily"));
  24. }
  25. @Test
  26. public void lookupTest(){
  27. pb.add("Karl", "888-888-8888");
  28. String entry = pb.lookup("Karl");
  29. assertEquals("888-888-8888",pb.lookup("Karl"));
  30. }
  31. @Test
  32. public void reverseLookupTest(){
  33. pb.add("Chad", "999-999-9999");
  34. String entry = pb.reverseLookup("Chad");
  35. assertEquals("Chad",pb.reverseLookup("999-999-9999"));
  36. }
  37. }