@Test public void testRemoveUnfamiliarContact() { UserContact userContact = new UserContact(CONTACT, createUserContactType()); userContact.setId(1L); user.addContact(userContact); userContactsService.removeContact(2L); assertEquals(user.getUserContacts().size(), 1); }
@Test public void testRemoveContact() { UserContact userContact = new UserContact(CONTACT, createUserContactType()); userContact.setId(1L); user.addContact(userContact); when(userContactsDao.getContactById(1L)).thenReturn(userContact); userContactsService.removeContact(1L); assertEquals(user.getUserContacts().size(), 0); }
@Test public void testsGetAvailableContactTypes() { List<UserContactType> expectedTypes = new ArrayList<UserContactType>(); expectedTypes.add(createUserContactType()); when(userContactsDao.getAvailableContactTypes()).thenReturn(expectedTypes); List<UserContactType> types = userContactsService.getAvailableContactTypes(); assertTrue(types.containsAll(expectedTypes)); }
@Test public void testAddContact() throws NotFoundException { UserContactType type = createUserContactType(); UserContact contact = new UserContact(CONTACT, type); when(userContactsDao.isExist(type.getId())).thenReturn(true); when(userContactsDao.get(type.getId())).thenReturn(type); UserContact addedContact = userContactsService.addContact(contact.getValue(), contact.getType().getId()); assertEquals(addedContact.getValue(), CONTACT); assertEquals(addedContact.getType(), type); }