Build a simple PhoneBook program.

PhoneBookTest.java 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. private PhoneBook phoneBook;
  14. /**
  15. * Default constructor for test class PhoneBookTest
  16. */
  17. public PhoneBookTest()
  18. {
  19. }
  20. /**
  21. * Sets up the test fixture.
  22. *
  23. * Called before every test case method.
  24. */
  25. @Before
  26. public void setUp()
  27. {
  28. phoneBook = new PhoneBook();
  29. }
  30. @Test
  31. public void testAdd() {
  32. //Given
  33. String name = "J";
  34. String phoneNumber = "2121112222";
  35. //Then
  36. phoneBook.addListings(name, phoneNumber);
  37. int expectedSize = 1;
  38. int actualSize = phoneBook.size();
  39. //
  40. assertEquals(expectedSize, actualSize);
  41. }
  42. @Test
  43. public void testRemove() {
  44. //Given
  45. String name = "J";
  46. String phoneNumber = "2121112222";
  47. //Then
  48. phoneBook.addListings(name, phoneNumber);
  49. int expectedSize = 1;
  50. int actualSize = phoneBook.size();
  51. //
  52. assertEquals(expectedSize, actualSize);
  53. }
  54. @Test
  55. public void testLookup() {
  56. //Given
  57. String name = "J";
  58. String phoneNumber = "2121112222";
  59. //Then
  60. phoneBook.addListings(name, phoneNumber);
  61. int expectedSize = 1;
  62. int actualSize = phoneBook.size();
  63. //
  64. assertEquals(expectedSize, actualSize);
  65. }
  66. @Test
  67. public void testReverseLookup() {
  68. //Given
  69. String name = "J";
  70. String phoneNumber = "2121112222";
  71. //Then
  72. phoneBook.addListings(name, phoneNumber);
  73. int expectedSize = 1;
  74. int actualSize = phoneBook.size();
  75. //
  76. assertEquals(expectedSize, actualSize);
  77. }
  78. @Test
  79. public void testReverseLookupWhenNotFound() {
  80. //Given
  81. String name = "J";
  82. String phoneNumber = "2121112222";
  83. //Then
  84. phoneBook.addListings(name, phoneNumber);
  85. int expectedSize = 1;
  86. int actualSize = phoneBook.size();
  87. //
  88. assertEquals(expectedSize, actualSize);
  89. }
  90. }