Build a simple PhoneBook program.

PhoneBookTest.java 2.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. import static org.junit.Assert.*;
  2. import org.junit.Test;
  3. import java.util.ArrayList;
  4. public class PhoneBookTest
  5. {
  6. PhoneBook newEntry = new PhoneBook();
  7. @Test
  8. public void addEntryTest(){
  9. newEntry.addEntry("Rachelle","123-4567");
  10. Entry actual = newEntry.getEntry("Rachelle");
  11. assertEquals("123-4567",actual.getPhoneNumber());
  12. }
  13. @Test
  14. public void addNumberToExistingEntryTest(){
  15. newEntry.addEntry("Rachelle","123-4567");
  16. Entry actual = newEntry.getEntry("Rachelle");
  17. actual.addPhoneNumber("987-6543");
  18. assertEquals("123-4567, 987-6543",actual.getPhoneNumber());
  19. }
  20. @Test
  21. public void addNumberToExistingEntryTest2(){
  22. newEntry.addEntry("Rachelle","123-4567");
  23. newEntry.addAdditionalNumbers("Rachelle","987-6543");
  24. assertEquals("123-4567, 987-6543",newEntry.lookupNumber("Rachelle"));
  25. }
  26. @Test
  27. public void hasEntryTest(){
  28. newEntry.addEntry("Rachelle","123-4567");
  29. assertTrue(newEntry.hasEntry("Rachelle"));
  30. }
  31. @Test
  32. public void removeEntryTest(){
  33. newEntry.addEntry("Rachelle","123-4567");
  34. newEntry.removeEntry("Rachelle");
  35. assertFalse(newEntry.hasEntry("Rachelle"));
  36. }
  37. @Test public void lookupNumberTest(){
  38. newEntry.addEntry("Rachelle","123-4567");
  39. assertEquals("123-4567",newEntry.lookupNumber("Rachelle"));
  40. }
  41. @Test public void reverseLookupTest(){
  42. newEntry.addEntry("Rachelle","123-4567");
  43. assertEquals("Rachelle",newEntry.reverseLookup("123-4567"));
  44. }
  45. @Test public void reverseLookupTest2(){
  46. newEntry.addEntry("Rachelle","123-4567");
  47. assertEquals("no match",newEntry.reverseLookup("987-5432"));
  48. }
  49. @Test public void displayPhonebookTest(){
  50. newEntry.addEntry("Rachelle","123-4567");
  51. newEntry.addEntry("Kris","987-6543");
  52. assertEquals("Kris 987-6543\nRachelle 123-4567\n", newEntry.displayPhonebook());
  53. }
  54. @Test public void entryArrayContainsNumberTest(){
  55. newEntry.addEntry("Rachelle","123-4567");
  56. Entry actual = newEntry.getEntry("Rachelle");
  57. assertTrue(actual.entryArrayContainsNumber("123-4567"));
  58. }
  59. @Test public void entryArrayContainsNumberTest2(){
  60. newEntry.addEntry("Rachelle","123-4567");
  61. Entry actual = newEntry.getEntry("Rachelle");
  62. assertFalse(actual.entryArrayContainsNumber("987-6543"));
  63. }
  64. }