Build a simple PhoneBook program.

PhoneBookTest.java 2.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. import static org.junit.Assert.*;
  2. import org.junit.After;
  3. import org.junit.Before;
  4. import org.junit.Test;
  5. import java.util.*;
  6. import java.util.stream.Collectors;
  7. /**
  8. * The test class PhoneBookTest.
  9. *
  10. * @author (your name)
  11. * @version (a version number or a date)
  12. */
  13. public class PhoneBookTest
  14. {
  15. TreeMap<String, String> phonebook = new TreeMap<>();
  16. PhoneBook pb = new PhoneBook(phonebook);
  17. @Test
  18. public void testAdd()
  19. {
  20. //plug in a String name here using methods from main class
  21. String name = "Ryan";
  22. String phoneNumber= "123-456-7890";
  23. pb.add(name, phoneNumber);
  24. assertFalse(phonebook.isEmpty());
  25. }
  26. @Test
  27. public void testRemove()
  28. {
  29. String name = "Ryan";
  30. String phoneNumber= "123-456-7890";
  31. pb.add(name, phoneNumber);
  32. pb.remove(name);
  33. assertTrue(phonebook.isEmpty());
  34. }
  35. @Test
  36. public void testRemoveRecord()
  37. {
  38. String name = "Ryan";
  39. String phoneNumber= "123-456-7890";
  40. pb.add(name, phoneNumber);
  41. pb.remove(name);
  42. assertTrue(phonebook.isEmpty());
  43. }
  44. @Test
  45. public void testLookup()
  46. {
  47. String name = "Ryan";
  48. String phoneNumber= "123-456-7890";
  49. pb.add(name, phoneNumber);
  50. Collection<String> expected = phonebook.values();
  51. assertEquals(expected, pb.lookup(name));
  52. }
  53. @Test
  54. public void testReverseLookup() {
  55. String name = "Ryan";
  56. String phoneNumber= "123-456-7890";
  57. pb.add(name, phoneNumber);
  58. Collection<String> expected = phonebook.keySet();
  59. assertEquals(expected, pb.reverseLookup(phoneNumber));
  60. }
  61. @Test
  62. public void testDisplay()
  63. {
  64. String name = "Ryan";
  65. String phoneNumber= "123-456-7890";
  66. pb.add(name, phoneNumber);
  67. TreeMap<String, String> expected = phonebook;
  68. assertEquals(expected, pb.display());
  69. }
  70. @Test
  71. public void testEntries()
  72. {
  73. assertEquals(null, 1);
  74. }
  75. }