Build a simple PhoneBook program.

PhoneBookTest.java 1.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. private PhoneBook phoneBook;
  20. /**
  21. * Sets up the test fixture.
  22. *
  23. * Called before every test case method.
  24. */
  25. @Before
  26. public void setUp()
  27. {
  28. phoneBook = new PhoneBook();
  29. }
  30. @Test
  31. public void testAdd()
  32. {
  33. //plug in a String name here using methods from main class
  34. String name = "Ryan";
  35. String expectedPhoneNumber= "123-456-7890";
  36. phoneBook.add(name, expectedPhoneNumber);
  37. String actualPhoneNumber = phoneBook.lookUp(name);
  38. assertEquals(actualPhoneNumber, expectedPhoneNumber);
  39. }
  40. /**
  41. * Tears down the test fixture.
  42. *
  43. * Called after every test case method.
  44. */
  45. @After
  46. public void tearDown()
  47. {
  48. }
  49. }