Simple Phonebook

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import java.util.*;
  2. import static org.junit.Assert.*;
  3. import org.junit.Test;
  4. public class PhoneBookTest
  5. {
  6. @Test
  7. public void addTest(){
  8. PhoneBook phoneBook = new PhoneBook();
  9. phoneBook.add("vince","333-333-3333");
  10. int actual = phoneBook.size();
  11. int expected = 1;
  12. assertEquals(actual,expected);
  13. }
  14. @Test
  15. public void removeTest(){
  16. PhoneBook phoneBook = new PhoneBook();
  17. phoneBook.add("vince","333-333-3333");
  18. phoneBook.remove("vince");
  19. int actual = phoneBook.size();
  20. int expected = 0;
  21. assertEquals(actual,expected);
  22. }
  23. @Test
  24. public void lookupTest(){
  25. PhoneBook phoneBook = new PhoneBook();
  26. phoneBook.add("vince","333-333-3333");
  27. String actual = phoneBook.lookup("vince");
  28. String expected = "333-333-3333";
  29. assertEquals(actual,expected);
  30. }
  31. @Test
  32. public void lookupReverseTest(){
  33. PhoneBook phoneBook = new PhoneBook();
  34. phoneBook.add("vince","333-333-3333");
  35. String actual = phoneBook.reverseLookup("333-333-3333");
  36. String expected = "vince";
  37. assertEquals(actual,expected);
  38. }
  39. @Test
  40. public void displayTest(){
  41. PhoneBook phoneBook = new PhoneBook();
  42. phoneBook.add("vince","333-333-3333");
  43. phoneBook.add("bill","444-444-4444");
  44. phoneBook.add("john","555-555-5555");
  45. String actual = phoneBook.display();
  46. String expected = "bill : 444-444-4444\njohn : 555-555-5555\nvince : 333-333-3333\n";
  47. assertEquals(actual,expected);
  48. }
  49. }