@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); }
@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)); }