UserService { public Collection<UserDTO> buildUserDTOList(Collection<User> users) { User currentUser = authenticationService.getCurrentUser(); Collection<String> currentFriendLogins = friendRepository.findFriendsForUser(currentUser.getLogin()); Collection<String> currentFollowersLogins = followerRepository.findFollowersForUser(currentUser.getLogin()); Collection<String> currentBlockedUsersLogins = blockService.getUsersBlockedLoginForUser(currentUser.getLogin()); Collection<UserDTO> userDTOs = new ArrayList<UserDTO>(); for (User user : users) { UserDTO userDTO = getUserDTOFromUser(user); userDTO.setYou(user.equals(currentUser)); if (!userDTO.isYou()) { userDTO.setFriend(currentFriendLogins.contains(user.getLogin())); userDTO.setFollower(currentFollowersLogins.contains(user.getLogin())); userDTO.setBlocked(currentBlockedUsersLogins.contains(user.getLogin())); } userDTOs.add(userDTO); } return userDTOs; }  User getUserByLogin(String login); String getLoginByRssUid(String rssUid); User getUserByUsername(String username); Collection<User> getUsersByLogin(Collection<String> logins); List<User> getUsersForCurrentDomain(int pagination); void updateUser(User user); void updatePassword(User user); void createUser(User user); void createTatamibot(String domain); void deleteUser(User user); @Secured("ROLE_ADMIN") @CacheEvict(value = {"group-user-cache", "group-cache","suggest-users-cache"}, allEntries = true) boolean desactivateUser( String username ); void registerUser(User user); void lostPassword(User user); String validateRegistration(String key); void updateWeeklyDigestRegistration(boolean registration); void updateDailyDigestRegistration(boolean registration); String updateRssTimelinePreferences(boolean booleanPreferencesRssTimeline); boolean isDomainHandledByLDAP(String domain); Collection<UserDTO> buildUserDTOList(Collection<User> users); UserDTO buildUserDTO(User user);  }
@Test public void testBuildUserDTOList() { String login = "jdubois@ippon.fr"; mockAuthenticationOnUserService(login); User testUser = userService.getUserByLogin(login); Collection<User> users = new ArrayList<User>(); users.add(testUser); Collection<UserDTO> userDTOs = userService.buildUserDTOList(users); assertEquals(1, userDTOs.size()); UserDTO dto = userDTOs.iterator().next(); assertEquals("Julien", dto.getFirstName()); assertEquals(3, dto.getFollowersCount()); assertEquals(4, dto.getFriendsCount()); }