Build a simple PhoneBook program.

PhoneBookTest.java 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. import java.util.TreeMap;
  2. import static org.junit.Assert.*;
  3. import org.junit.After;
  4. import org.junit.Before;
  5. import org.junit.Test;
  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. PhoneBook phoneBook =new PhoneBook();
  15. private String name;
  16. private String number;
  17. @Test
  18. public void testAddToPhoneBook1(){
  19. phoneBook.addToPhoneBook("Zebra", "111-222-333");;
  20. String expectedString = "[Zebra=[111-222-333]]";
  21. String actualString = phoneBook.displayFromPhoneBook();
  22. assertEquals(expectedString, actualString);
  23. }
  24. @Test
  25. public void testAddToPhoneBookIndividualNumbers(){
  26. phoneBook.addToPhoneBookIndividualNumbers("Zebra", "111-222-333");
  27. phoneBook.addToPhoneBookIndividualNumbers("Zebra", "222-444-4444");
  28. String expectedString = "[Zebra=[111-222-333, 222-444-4444]]";
  29. String actualString = phoneBook.displayFromPhoneBook();
  30. assertEquals(expectedString, actualString);
  31. }
  32. @Test
  33. public void testRemoveFromPhoneBook1(){
  34. PhoneBook phoneBook3 =new PhoneBook();
  35. phoneBook3.addToPhoneBook("Zebra", "111-222-3333");
  36. phoneBook3.addToPhoneBook("Dog", "222-444-4444");
  37. phoneBook3.addToPhoneBook("Cat", "555-666-7777");
  38. phoneBook3.addToPhoneBook("Alligator", "888-999-1010");
  39. phoneBook3.addToPhoneBook("Wolf", "111-121-1313");
  40. phoneBook3.removeFromPhoneBook("Dog");
  41. String expectedString = "[Alligator=[888-999-1010], Cat=[555-666-7777], Wolf=[111-121-1313], Zebra=[111-222-3333]]";
  42. String actualString = phoneBook3.displayFromPhoneBook();
  43. assertEquals(expectedString, actualString);
  44. }
  45. @Test
  46. public void testRemoveFromPhoneBookIndividualNumbers(){
  47. phoneBook.addToPhoneBook("Zebra", "111-222-3333");
  48. phoneBook.addToPhoneBookIndividualNumbers("Zebra", "222-444-4444");
  49. phoneBook.removeFromPhoneBookIndividualNumbers("Zebra", "111-222-3333");
  50. String expectedString = "[Zebra=[222-444-4444]]";
  51. String actualString = phoneBook.displayFromPhoneBook();
  52. assertEquals(expectedString, actualString);
  53. }
  54. @Test
  55. public void testLookupFromPhoneBook(){
  56. PhoneBook phoneBook4 =new PhoneBook();
  57. phoneBook4.addToPhoneBook("Zebra", "111-222-3333");
  58. phoneBook4.addToPhoneBook("Dog", "222-444-4444");
  59. phoneBook4.addToPhoneBook("Cat", "555-666-7777");
  60. phoneBook4.addToPhoneBook("Alligator", "888-999-1010");
  61. phoneBook4.addToPhoneBook("Wolf", "111-121-1313");
  62. String expectedString = "[555-666-7777]";
  63. String actualString = phoneBook4.lookupFromPhoneBook("Cat");
  64. assertEquals(expectedString, actualString);
  65. }
  66. @Test
  67. public void testReverseLookup(){
  68. phoneBook.addToPhoneBook("Zebra", "111-222-3333");
  69. phoneBook.addToPhoneBook("Dog", "222-444-4444");
  70. phoneBook.addToPhoneBook("Cat", "555-666-7777");
  71. phoneBook.addToPhoneBook("Alligator", "888-999-1010");
  72. phoneBook.addToPhoneBook("Wolf", "111-121-1313");
  73. String expectedString = "Wolf";
  74. String actualString = phoneBook.reverseLookupFromPhoneBook("111-121-1313");
  75. assertEquals(expectedString, actualString);
  76. }
  77. }