Build a simple PhoneBook program.

PhoneBookTest.java 1.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. @Test
  14. public void phoneBooktest(){
  15. PhoneBook yellowPages = new PhoneBook();
  16. }
  17. @Test
  18. public void addTest(){
  19. //Given
  20. PhoneBook yellowPages = new PhoneBook();
  21. yellowPages.add("Jenny", "123-867-5309");
  22. //Then:
  23. String actual = yellowPages.lookUp("Jenny");
  24. String expected = "123-867-5309";
  25. //Assert:
  26. assertEquals(expected, actual);
  27. }
  28. @Test
  29. public void removeTest() {
  30. //Given:
  31. PhoneBook yellowPages = new PhoneBook();
  32. yellowPages.add("Jenny", "123-867-5309");
  33. yellowPages.remove("Jenny");
  34. //Then:
  35. int actual = yellowPages.getSize();
  36. int expected = 0;
  37. //Assert:
  38. assertEquals(expected, actual);
  39. }
  40. @Test
  41. public void reverseLookUpTest() {
  42. //Given:
  43. PhoneBook yellowPages = new PhoneBook();
  44. yellowPages.add("Jenny", "123-867-5309");
  45. //Then:
  46. String actual = yellowPages.reverseLookUp("123-867-5309");
  47. String expected = "Jenny";
  48. //Assert:
  49. assertEquals(expected, actual);
  50. }
  51. @Test
  52. public void displayTest(){
  53. //Given:
  54. PhoneBook yellowPages = new PhoneBook();
  55. yellowPages.add("Jenny", "123-867-5309");
  56. //Then:
  57. String actual = yellowPages.display();
  58. String expected ="Jenny : 123-867-5309";
  59. //Assert:
  60. assertEquals(expected, actual);
  61. }
  62. }