Build a simple PhoneBook program.

PhoneBookTest.java 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. PhoneBook phoneBook = new PhoneBook();
  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. @Test
  29. public void assTest() {
  30. PhoneBook phoneBook = new PhoneBook();
  31. //given
  32. phoneBook.add("Ben", "358-1032");
  33. //then
  34. String actual = phoneBook.lookup("Ben");
  35. String expected = "358-1032";
  36. //assert
  37. assertEquals(expected, actual);
  38. }
  39. @Test
  40. public void removeTest() {
  41. PhoneBook phoneBook = new PhoneBook();
  42. //given
  43. phoneBook.add("Ben", "358-1032");
  44. phoneBook.remove("Ben");
  45. //then
  46. int actual = phoneBook.getSize();
  47. int expected = 0;
  48. //assert
  49. assertEquals(expected, actual);
  50. }
  51. @Test
  52. public void reverseLookupTest() {
  53. PhoneBook phoneBook = new PhoneBook();
  54. //given
  55. phoneBook.add("Ben", "358-1032");
  56. //then
  57. String actual = phoneBook.reverseLookup("358-1032");
  58. String expected = "Ben";
  59. //assert
  60. assertEquals(expected, actual);
  61. }
  62. @Test
  63. public void displayTest() {
  64. PhoneBook phoneBook = new PhoneBook();
  65. //given
  66. phoneBook.add("Ben", "358-1032");
  67. //then
  68. String actual = phoneBook.display();
  69. String expected = "Ben : 358-1032";
  70. //assert
  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. }