Build a simple PhoneBook program.

PhoneBookTest.java 1.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. import static org.junit.Assert.*;
  2. import org.junit.After;
  3. import org.junit.Assert;
  4. import org.junit.Before;
  5. import org.junit.Test;
  6. public class PhoneBookTest
  7. {
  8. PhoneBook pBookTest = new PhoneBook();
  9. @Test
  10. public void addNumberTest(){
  11. //when
  12. //pBook.add("Police", "9-1-1");
  13. //expected
  14. String expected = "Police 9-1-1";
  15. //actual
  16. String actual = pBookTest.add("Police","9-1-1");
  17. Assert.assertEquals(expected, actual);
  18. }
  19. @Test
  20. public void removeNumberTest(){
  21. //expected
  22. String expected = "Police";
  23. //actual
  24. String actual = pBookTest.remove("Police");
  25. Assert.assertEquals(expected, actual);
  26. }
  27. @Test
  28. public void lookUpNumberTest(){
  29. //when
  30. pBookTest.add("John Doe", "111-111-1111");
  31. //expected
  32. String expected = "111-111-1111";
  33. //actual
  34. String actual = pBookTest.lookUp("John Doe");
  35. Assert.assertEquals(expected, actual);
  36. }
  37. @Test
  38. public void reverseLookUpTest(){
  39. //when
  40. pBookTest.add("James Bond", "098-765-4321");
  41. //expected
  42. String expected = "James Bond";
  43. //actual
  44. String actual = pBookTest.reverseLookUp("098-765-4321");
  45. Assert.assertEquals(expected, actual);
  46. }
  47. @Test
  48. public void displayNumberTest(){
  49. //when
  50. pBookTest.add("Carol", "333-333-3333");
  51. pBookTest.add("Bruce", "222-222-2222");
  52. pBookTest.add("Alice", "111-111-1111");
  53. //expected
  54. String expected = "Alice 111-111-1111\n" +
  55. "Bruce 222-222-2222\n" +
  56. "Carol 333-333-3333\n";
  57. //actual
  58. String actual = pBookTest.displayPhoneBook();
  59. Assert.assertEquals(expected, actual);
  60. }
  61. }