Simple Phonebook

PhoneBookTest.java 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. import org.junit.Assert;
  2. import org.junit.After;
  3. import org.junit.Before;
  4. import org.junit.Test;
  5. import java.util.ArrayList;
  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. @Test
  15. public void addTest() {
  16. String expected = "(555)-555-5555";
  17. PhoneBook pb = new PhoneBook();
  18. pb.add("Jane Doe", "(555)-555-5555");
  19. String actual = pb.lookup("Jane Doe");
  20. Assert.assertEquals(expected, actual);
  21. }
  22. @Test
  23. public void addTest2() {
  24. String expected = "(555)-555-5555, (444)-444-4444, (333)-333-3333";
  25. PhoneBook pb = new PhoneBook();
  26. ArrayList<String> phoneNumbers = new ArrayList<String>();
  27. phoneNumbers.add("(555)-555-5555");
  28. phoneNumbers.add("(444)-444-4444");
  29. phoneNumbers.add("(333)-333-3333");
  30. pb.add("Sloths McSlotherson", phoneNumbers);
  31. String actual = pb.lookup("Sloths McSlotherson");
  32. Assert.assertEquals(expected, actual);
  33. }
  34. public void addTest3() {
  35. String expected = "(555)-555-5555, (444)-444-4444, (333)-333-3333";
  36. PhoneBook pb = new PhoneBook();
  37. ArrayList<String> phoneNumbers = new ArrayList<String>();
  38. phoneNumbers.add("(555)-555-5555");
  39. phoneNumbers.add("(444)-444-4444");
  40. pb.add("Turtle Turtleton", phoneNumbers);
  41. pb.add("Trutle Turtleton", "(333)-333-3333");
  42. String actual = pb.lookup("Turtle Turtleton");
  43. Assert.assertEquals(expected, actual);
  44. }
  45. @Test
  46. public void removeTest() {
  47. String expected = "Not Found";
  48. PhoneBook pb = new PhoneBook();
  49. pb.add("Kylo Ren", "(555)-867-5309");
  50. pb.remove("Kylo Ren");
  51. String actual = pb.lookup("Kylo Ren");
  52. Assert.assertEquals(expected, actual);
  53. }
  54. @Test
  55. public void removeTestIndividualNumber() {
  56. String expected = "(555)-867-5309, (789)-789-6789";
  57. PhoneBook pb = new PhoneBook();
  58. pb.add("Kylo Ren", "(555)-867-5309");
  59. pb.add("Kylo Ren", "(888)-888-8888");
  60. pb.add("Kylo Ren", "(789)-789-6789");
  61. pb.remove("Kylo Ren", 1);
  62. String actual = pb.lookup("Kylo Ren");
  63. Assert.assertEquals(expected, actual);
  64. }
  65. @Test
  66. public void lookupTest() {
  67. String expected = "(GIL)-EAD-SUXX";
  68. PhoneBook pb = new PhoneBook();
  69. pb.add("Kylo Ren", "(555)-867-5309");
  70. pb.add("June Osborne", "(GIL)-EAD-SUXX");
  71. pb.add("Serena Joy", "(555)-555-5555");
  72. String actual = pb.lookup("June Osborne");
  73. Assert.assertEquals(expected, actual);
  74. }
  75. @Test
  76. public void reverseLookupTest() {
  77. String expected = "Serena Joy";
  78. PhoneBook pb = new PhoneBook();
  79. pb.add("Kylo Ren", "(555)-867-5309");
  80. pb.add("June Osborne", "(GIL)-EAD-SUXX");
  81. pb.add("Serena Joy", "(555)-555-5555");
  82. String actual = pb.reverseLookup("(555)-555-5555");
  83. Assert.assertEquals(expected, actual);
  84. }
  85. @Test
  86. public void reverseLookupTest2() {
  87. String expected = "Serena Joy";
  88. PhoneBook pb = new PhoneBook();
  89. pb.add("Kylo Ren", "(555)-867-5309");
  90. pb.add("Kylo Ren", "(345)-123-6789");
  91. pb.add("June Osborne", "(GIL)-EAD-SUXX");
  92. pb.add("Serena Joy", "(555)-555-5555");
  93. pb.add("Serena Joy", "(321)-543-8765");
  94. pb.add("Serena Joy", "(893)-789-0123");
  95. String actual = pb.reverseLookup("(321)-543-8765");
  96. Assert.assertEquals(expected, actual);
  97. }
  98. }