Build a simple PhoneBook program.

PhoneBookTest.java 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. import org.junit.Assert;
  2. import org.junit.After;
  3. import org.junit.Before;
  4. import org.junit.Test;
  5. import java.util.*;
  6. /**
  7. * The test class PhoneBookTest.
  8. *
  9. * @author (your name)
  10. * @version (a version number or a date)
  11. */
  12. public class PhoneBookTest
  13. {
  14. TreeMap<String, ArrayList<String>> phoneBook = new TreeMap<>();
  15. /**
  16. * Default constructor for test class PhoneBookTest
  17. */
  18. public PhoneBookTest()
  19. {
  20. }
  21. /**
  22. * Sets up the test fixture.
  23. *
  24. * Called before every test case method.
  25. */
  26. @Before
  27. public void setUp()
  28. {
  29. PhoneBook pb = new PhoneBook(phoneBook);
  30. }
  31. /**
  32. * Tears down the test fixture.
  33. *
  34. * Called after every test case method.
  35. */
  36. @After
  37. public void tearDown()
  38. {
  39. }
  40. // add entries
  41. @Test
  42. public void testOne() {
  43. String expected = "Dog 222-444-5555\nZebra 111-222-3333\n";
  44. PhoneBook pb = new PhoneBook(phoneBook);
  45. pb.add("Zebra", "111-222-3333");
  46. pb.add("Dog", "222-444-5555");
  47. String actual = pb.display();
  48. Assert.assertEquals(expected, actual);
  49. }
  50. @Test
  51. public void testTwo() {
  52. String expected = "Dog 222-444-5555\n";
  53. PhoneBook pb = new PhoneBook(phoneBook);
  54. pb.add("Zebra", "111-222-3333");
  55. pb.add("Dog", "222-444-5555");
  56. pb.remove("Zebra");
  57. String actual = pb.display();
  58. Assert.assertEquals(expected, actual);
  59. }
  60. @Test
  61. public void TestThree() {
  62. String expected = "222-444-5555";
  63. PhoneBook pb = new PhoneBook(phoneBook);
  64. pb.add("Zebra", "111-222-3333");
  65. pb.add("Dog", "222-444-5555");
  66. String actual = pb.lookup("Dog");
  67. Assert.assertEquals(expected, actual);
  68. }
  69. @Test
  70. public void TestFour() {
  71. String expected = "Dog";
  72. PhoneBook pb = new PhoneBook(phoneBook);
  73. pb.add("Zebra", "111-222-3333");
  74. pb.add("Dog", "222-444-5555");
  75. String actual = pb.reverseLookup("222-444-5555");
  76. Assert.assertEquals(expected, actual);
  77. }
  78. // Testing list of phonenumbers for an entry
  79. @Test
  80. public void TestFive() {
  81. String expected = "Dog 111-222-3333, 444-555-6666\n";
  82. PhoneBook pb = new PhoneBook(phoneBook);
  83. pb.add("Dog", "111-222-3333");
  84. pb.add("Dog", "444-555-6666");
  85. String actual = pb.display();
  86. Assert.assertEquals(expected, actual);
  87. }
  88. @Test
  89. public void Test2()
  90. {
  91. }
  92. }