PageRenderTime 28ms CodeModel.GetById 13ms RepoModel.GetById 1ms app.codeStats 0ms

/src/ChatAppTests/ContactListTest.java

https://bitbucket.org/blitz2145/cop4331-chat-application
Java | 61 lines | 47 code | 8 blank | 6 comment | 2 complexity | c9d32a1514411d01e41558ceefe09389 MD5 | raw file
  1. package ChatAppTests;
  2. import static org.junit.Assert.*;
  3. import org.junit.Test;
  4. import ChatApp.Contact;
  5. import ChatApp.ContactList;
  6. public class ContactListTest {
  7. /**
  8. * Tests setSelected(), getSelected(), add(), and find()
  9. */
  10. @Test
  11. public void testSetSelected() {
  12. ContactList list = new ContactList();
  13. Contact c1 = new Contact("abc");
  14. Contact c2 = new Contact("def");
  15. Contact c3 = new Contact("ghi");
  16. list.add(c1);
  17. list.add(c2);
  18. list.add(c3);
  19. int index = list.find("def");
  20. list.setSelected(index);
  21. Contact selected = list.getSelected();
  22. assertTrue(selected.getUsername().equals("def"));
  23. }
  24. /**
  25. * Tests remove() and size()
  26. */
  27. @Test
  28. public void testRemove() {
  29. ContactList list = new ContactList();
  30. Contact c1 = new Contact("abc");
  31. Contact c2 = new Contact("def");
  32. Contact c3 = new Contact("ghi");
  33. list.add(c1);
  34. list.add(c2);
  35. list.add(c3);
  36. int size = list.size();
  37. list.remove(c2);
  38. assertTrue(list.size() == size - 1);
  39. }
  40. @Test
  41. public void testSaveContacts() {
  42. ContactList list = new ContactList();
  43. Contact c1 = new Contact("abc");
  44. Contact c2 = new Contact("def");
  45. Contact c3 = new Contact("ghi");
  46. list.add(c1);
  47. list.add(c2);
  48. list.add(c3);
  49. list.saveContacts();
  50. ContactList list2 = new ContactList();
  51. assertTrue(list2.size() == (list.size()));
  52. }
  53. }