Build a simple PhoneBook program.

PhoneBookTest.java 1.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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
  30. public void testRemovePhoneBookEntry_And_Lookup()
  31. {
  32. PhoneBook test = new PhoneBook();
  33. String name = "Jenny";
  34. String wrongName = "Tommy Tutone";
  35. String number = "(302)-867-5309";
  36. test.add(name, number);
  37. String actual = test.lookup(wrongName);
  38. assertEquals("N/A", actual);
  39. }
  40. @Test
  41. public void testReverseLookup()
  42. {
  43. PhoneBook test = new PhoneBook();
  44. String phoneNumber = "(302)-867-5309";
  45. String expectedName = "Jenny";
  46. test.add(expectedName, phoneNumber);
  47. String actual = test.reverseLookup(phoneNumber);
  48. assertEquals(expectedName, actual);
  49. }
  50. }