Simple Phonebook

PhoneBookTest.java 2.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. String name = "Ryan";
  21. String phoneNumber= "123-456-7890";
  22. pb.add(name, phoneNumber);
  23. assertFalse(phonebook.isEmpty());
  24. }
  25. @Test
  26. public void testRemove()
  27. {
  28. String name = "Ryan";
  29. String phoneNumber= "123-456-7890";
  30. String name1 = "Marcus";
  31. String phoneNumber1= "650-789-1234";
  32. pb.add(name, phoneNumber);
  33. pb.remove(name);
  34. assertTrue(phonebook.isEmpty());
  35. }
  36. @Test
  37. public void testRemoveRecord()
  38. {
  39. String name = "Ryan";
  40. String phoneNumber= "123-456-7890";
  41. pb.add(name, phoneNumber);
  42. pb.remove(name);
  43. assertTrue(phonebook.isEmpty());
  44. }
  45. @Test
  46. public void testLookup()
  47. {
  48. String name = "Ryan";
  49. String phoneNumber= "123-456-7890";
  50. pb.add(name, phoneNumber);
  51. Collection<String> expected = phonebook.values();
  52. assertEquals(expected, pb.lookup(name));
  53. }
  54. @Test
  55. public void testReverseLookup() {
  56. String name = "Ryan";
  57. String phoneNumber= "123-456-7890";
  58. pb.add(name, phoneNumber);
  59. Collection<String> expected = phonebook.keySet();
  60. assertEquals(expected, pb.reverseLookup(phoneNumber));
  61. }
  62. @Test
  63. public void testDisplay()
  64. {
  65. String name = "Ryan";
  66. String phoneNumber= "123-456-7890";
  67. pb.add(name, phoneNumber);
  68. TreeMap<String, String> expected = phonebook;
  69. assertEquals(expected, pb.display());
  70. }
  71. }