Build a simple PhoneBook program.

PhoneBookTest.java 1.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. import static org.junit.Assert.*;
  2. import org.junit.After;
  3. import org.junit.Before;
  4. import org.junit.Test;
  5. /**
  6. * The test class PhoneBookTest.
  7. *
  8. * @author (your name)
  9. * @version (a version number or a date)
  10. */
  11. public class PhoneBookTest
  12. {
  13. PhoneBook testObj;
  14. /**
  15. * Default constructor for test class PhoneBookTest
  16. */
  17. public PhoneBookTest()
  18. {
  19. }
  20. /**
  21. * Sets up the test fixture.
  22. *
  23. * Called before every test case method.
  24. */
  25. @Before
  26. public void setUp()
  27. {
  28. testObj = new PhoneBook();
  29. }
  30. /**
  31. * Tears down the test fixture.
  32. *
  33. * Called after every test case method.
  34. */
  35. @After
  36. public void tearDown()
  37. {
  38. }
  39. @Test
  40. public void testadd(){
  41. String expected = "4545666667";
  42. //PhoneBook phoneBook = new PhoneBook();
  43. testObj.add("john",expected);
  44. String actual = testObj.lookUp("john");
  45. assertEquals(actual, expected);
  46. }
  47. @Test
  48. public void testremoveAndLookUp(){
  49. String expected = "5454";
  50. testObj.add("gei", "5454");
  51. assertEquals(expected,testObj.lookUp("gei"));
  52. String expectedAfterDelete = null;
  53. testObj.remove("gei");
  54. assertEquals(expectedAfterDelete, testObj.lookUp("gei"));
  55. }
  56. @Test
  57. public void testreverseLookUp(){
  58. String expected = "John";
  59. testObj.add("John", "4343");
  60. assertEquals(expected, testObj.reverseLookUp("4343"));
  61. }
  62. }