Build a simple PhoneBook program.

PhoneBookTest.java 2.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. /**
  20. * Sets up the test fixture.
  21. *
  22. * Called before every test case method.
  23. */
  24. @Before
  25. public void setUp()
  26. {
  27. }
  28. /**
  29. * Tears down the test fixture.
  30. *
  31. * Called after every test case method.
  32. */
  33. @After
  34. public void tearDown()
  35. {
  36. }
  37. @Test
  38. public void addEntry()
  39. {
  40. PhoneBook phoneBoo1 = new PhoneBook();
  41. phoneBoo1.addEntry("nicholas", "3027387978");
  42. assertEquals("nicholas: 3027387978", phoneBoo1.display());
  43. }
  44. @Test
  45. public void addTwoNumberForOnePersonTest()
  46. {
  47. PhoneBook phoneBoo1 = new PhoneBook();
  48. phoneBoo1.addEntry("nick", "302");
  49. phoneBoo1.addNumberTo("nick", "103");
  50. assertEquals("nick: 302103", phoneBoo1.display());
  51. }
  52. @Test
  53. public void reverseLoopupTest()
  54. {
  55. PhoneBook phoneBoo1 = new PhoneBook();
  56. phoneBoo1.addEntry("nick", "302");
  57. assertEquals("nick", phoneBoo1.reverseLoopup("302"));
  58. }
  59. @Test
  60. public void lookupTest()
  61. {
  62. PhoneBook phoneBoo1 = new PhoneBook();
  63. phoneBoo1.addEntry("nick", "302");
  64. assertEquals("302", phoneBoo1.lookUp("nick"));
  65. }
  66. @Test
  67. public void RemoveRecordTest()
  68. {
  69. PhoneBook phoneBoo2 = new PhoneBook();
  70. phoneBoo2.addEntry("m", "302");
  71. phoneBoo2.removeRecord("m");
  72. assertEquals("", phoneBoo2.lookUp("m"));
  73. }
  74. @Test
  75. public void removePhoneNumberTest()
  76. {
  77. PhoneBook phoneBoo1 = new PhoneBook();
  78. phoneBoo1.addEntry("m", "123");
  79. phoneBoo1.addNumberTo("m", "456");
  80. phoneBoo1.removePhoneNumber("m", "456");
  81. assertEquals("123", phoneBoo1.lookUp("m"));
  82. }
  83. }