Build a simple PhoneBook program.

PhoneBookTest.java 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. /**
  14. * Default constructor for test class PhoneBookTest
  15. */
  16. public PhoneBookTest()
  17. {
  18. }
  19. /**
  20. * Sets up the test fixture.
  21. *
  22. * Called before every test case method.
  23. */
  24. @Before
  25. public void setUp()
  26. {
  27. }
  28. PhoneBook phonebook = new PhoneBook();
  29. @Test
  30. public void addTest() {
  31. //Expected
  32. String expected = "Lewis Dominguez 3023005754";
  33. //Actual
  34. String actual = phonebook.add("Lewis Dominguez", "3023005754");
  35. assertEquals(expected, actual);
  36. }
  37. @Test
  38. public void removeTest() {
  39. phonebook.add("Lewis Dominguez", "3023005754");
  40. //Expected
  41. String expected = "Lewis Dominguez";
  42. //Actual
  43. String actual = phonebook.remove("Lewis Dominguez");
  44. assertEquals(expected, actual);
  45. }
  46. @Test
  47. public void lookupTest() {
  48. phonebook.add("Lewis Dominguez", "3023005754");
  49. //Expected
  50. String expected = "3023005754";
  51. //Actual
  52. String actual = phonebook.lookup("Lewis Dominguez");
  53. assertEquals(expected, actual);
  54. }
  55. @Test
  56. public void reverseLookupTest() {
  57. phonebook.add("Lewis Dominguez", "3023005754");
  58. //Expected
  59. String expected = "Lewis Dominguez";
  60. //Actual
  61. String actual = phonebook.reverseLookup("3023005754");
  62. assertEquals(expected, actual);
  63. }
  64. // @Test
  65. // public void displayTest() {
  66. // phonebook.add("Lewis Dominguez", "3023005754");
  67. // //Expected
  68. // String expected = "Lewis Dominguez -> 3023005753";
  69. // //Actual
  70. // String actual = phonebook.display("Lewis Dominguez 3023005754");
  71. // assertEquals(expected, actual);
  72. // }
  73. /**
  74. * Tears down the test fixture.
  75. *
  76. * Called after every test case method.
  77. */
  78. @After
  79. public void tearDown()
  80. {
  81. }
  82. }