Build a simple PhoneBook program.

PhoneBookTest.java 1.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import static org.junit.Assert.*;
  2. import org.junit.After;
  3. import org.junit.Before;
  4. import org.junit.Test;
  5. public class PhoneBookTest
  6. {
  7. @Test
  8. public void testAdd()
  9. {
  10. PhoneBook test = new PhoneBook();
  11. boolean expected = true;
  12. String name = "Jenny";
  13. String number = "(302)-867-5309";
  14. test.add(name, number);
  15. boolean actual = test.getPhoneBook().containsKey(name);
  16. assertEquals(expected, actual);
  17. }
  18. // vvvv I hope this is okay since I know the add method works now vvvv
  19. @Test
  20. public void testAddPhoneBookEntry_And_Lookup()
  21. {
  22. PhoneBook test = new PhoneBook();
  23. String name = "Jenny";
  24. String expectedNumber = "(302)-867-5309";
  25. test.add(name, expectedNumber);
  26. String actual = test.lookup(name);
  27. assertEquals(expectedNumber, actual);
  28. }
  29. @Test(expected = NullPointerException.class)
  30. public void testRemoveEntry_And_Lookup()
  31. {
  32. PhoneBook test = new PhoneBook();
  33. String name = "Jenny";
  34. String number = "(302)-867-5309";
  35. test.add(name, number);
  36. test.removeEntry(name);
  37. test.lookup(name);
  38. }
  39. @Test
  40. public void testReverseLookup()
  41. {
  42. PhoneBook test = new PhoneBook();
  43. String phoneNumber = "(302)-867-5309";
  44. String expectedName = "Jenny";
  45. test.add(expectedName, phoneNumber);
  46. String actual = test.reverseLookup(phoneNumber);
  47. assertEquals(expectedName, actual);
  48. }
  49. @Test
  50. public void testDisplay() {
  51. PhoneBook test = new PhoneBook();
  52. test.add("hey", "302");
  53. test.add("yo", "521");
  54. test.add("hey", "498");
  55. System.out.println(test.display());
  56. }
  57. }