Build a simple PhoneBook program.

PhoneBookTest.java 1.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. /**
  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. public Map<String,String> input = new TreeMap<String,String>();
  16. /**
  17. * Default constructor for test class PhoneBookTest
  18. */
  19. @Test
  20. public void testConstructor()
  21. {
  22. PhoneBook phoneBook = new PhoneBook();
  23. }
  24. @Test
  25. public void testAddingPhoneNumber(){
  26. input.put("Amy","232-323-3233");
  27. int expectedSize = 1;
  28. int actual1 = input.size();
  29. //When
  30. assertEquals(expectedSize,actual1);
  31. }
  32. @Test
  33. public void testRemovingPhoneNumber(){
  34. //Given
  35. input.put("Amy","232-323-3233");
  36. //Then
  37. String expected = null;
  38. String actual = phoneBook.remove("Amy");
  39. //When
  40. assertEquals(expected,actual);
  41. }
  42. @Test
  43. public void testLookUp(){
  44. input.put("Amy","232-323-3233");
  45. input.put("John","243-567-9963");
  46. input.put("Brian","555-555-5555");
  47. String expected = "Amy"+"232-323-3233";
  48. boolean key = false;
  49. if(input.containsKey("Amy")){
  50. key = true;
  51. }
  52. assertTrue(key);
  53. }
  54. @Test
  55. public void testReverseLookUp(){
  56. input.put("Amy","232-323-3233");
  57. input.put("John","243-567-9963");
  58. input.put("Brian","555-555-5555");
  59. String expected = "Amy"+"232-323-3233";
  60. boolean value = false;
  61. if(input.containsValue("232-323-3233")){
  62. value = true;
  63. }
  64. assertTrue(value);
  65. }
  66. }