Build a simple PhoneBook program.

PhoneBookTest.java 1.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import java.util.*;
  2. import static org.junit.Assert.*;
  3. import org.junit.After;
  4. import org.junit.Before;
  5. import org.junit.Test;
  6. public class PhoneBookTest{
  7. Map<String, String> testPhonebook = new TreeMap<>();
  8. public PhoneBookTest(){
  9. }
  10. @Test
  11. public void addTest(){
  12. String number = "302-559-6954";
  13. String name = "Ken";
  14. testPhonebook.put(number, name);
  15. String expected = testPhonebook.get(number);
  16. assertEquals(name, expected);
  17. }
  18. @Test
  19. public void removeTest(){
  20. testPhonebook.put("9393939", "Hirself");
  21. testPhonebook.remove("9393939");
  22. String actual = testPhonebook.get("9393939");
  23. String expected = null;
  24. assertEquals(actual, expected);
  25. }
  26. @Test
  27. public void lookupTest(){
  28. testPhonebook.put("9393939", "Hirself");
  29. testPhonebook.get("9393939");
  30. String actual = testPhonebook.get("9393939");
  31. String expected = "Hirself";
  32. assertEquals(actual, expected);
  33. }
  34. @Test
  35. public void reverseLookupTest(){
  36. testPhonebook.put("9393939", "Hirself");
  37. testPhonebook.get("9393939");
  38. String actual = testPhonebook.get("Hirself");
  39. String expected = "9393939";
  40. assertEquals(actual, expected);
  41. }
  42. }