Build a simple PhoneBook program.

PhoneBookTest.java 1.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. Collection<String> c;
  9. Iterator<String> iter = c.iterator();
  10. public PhoneBookTest(){
  11. }
  12. @Test
  13. public void addTest(){
  14. String number = "302-559-6954";
  15. String name = "Ken";
  16. testPhonebook.put(number, name);
  17. String expected = testPhonebook.get(number);
  18. assertEquals(name, expected);
  19. }
  20. @Test
  21. public void removeTest(){
  22. testPhonebook.put("9393939", "Hirself");
  23. testPhonebook.remove("9393939");
  24. String actual = testPhonebook.get("9393939");
  25. String expected = null;
  26. assertEquals(actual, expected);
  27. }
  28. @Test
  29. public void lookupTest(){
  30. testPhonebook.put("9393939", "Hirself");
  31. testPhonebook.get("9393939");
  32. String actual = testPhonebook.get("9393939");
  33. String expected = "Hirself";
  34. assertEquals(actual, expected);
  35. }
  36. @Test
  37. public void reverseLookupTest(){
  38. testPhonebook.put("9393939", "Hirself");
  39. String actual = testPhonebook.get("9393939");
  40. String expected = "Hirself";
  41. assertEquals(actual, expected);
  42. }
  43. @Test
  44. public void removeRecordTest(){
  45. testPhonebook.put("9393939", "Hirself");
  46. testPhonebook.put("8484848", "Moped");
  47. for(TreeMap<String, String> entry : c){
  48. entry.remove();
  49. }
  50. String actual = null;
  51. }
  52. }