### Question:
DefaultUserService implements UserService { @Override public SearchResult<User> getUsersByFreeTextSearch(String searchTerm, int offset, int pageSize) { final int count = userRepository.getCountByUsernameOrEmail(searchTerm); final List<User> users = userRepository.findByUsernameOrEmail(searchTerm, offset, pageSize); final SearchResult<User> searchResult = new SearchResult<User>(users, count); searchResult.setOffset(offset); searchResult.setPageSize(pageSize); return searchResult; } @Autowired  DefaultUserService(PageRepository pageRepository,
                              UserRepository userRepository,
                              WidgetRepository widgetRepository,
                              PageTemplateRepository pageTemplateRepository,
                              CategoryRepository categoryRepository,
                              PersonRepository personRepository); @Override UserDetails loadUserByUsername(String username); @Override User getAuthenticatedUser(); @Override void setAuthenticatedUser(String userId); @Override void clearAuthenticatedUser(); @Override @Transactional void registerNewUser(User user); @Override User getUserById(String id); @Override User getUserByUsername(String userName); @Override User getUserByEmail(String userEmail); @Override User getUserByOpenId(String openId); @Override @Transactional void updateUserProfile(User user); @Override SearchResult<User> getAll(); @Override SearchResult<User> getLimitedList(int offset, int pageSize); @Override SearchResult<Person> getLimitedListOfPersons(int offset, int pageSize); @Override SearchResult<User> getUsersByFreeTextSearch(String searchTerm, int offset, int pageSize); @Override SearchResult<Person> getPersonsByFreeTextSearch(String searchTerm, int offset, int pageSize); @Override List<Person> getAllPeople(); @Override @Transactional // TODO RAVE-300: add security check that is is called by admin or the user itself void deleteUser(String userId); @Override List<Person> getAllByAddedWidget(String widgetId); @Override void updatePassword(User newUser); @Override void sendUserNameReminder(User newUser); @Override void sendPasswordReminder(User newUser); @Override boolean isValidReminderRequest(String forgotPasswordHash, int nrOfMinutesValid); @Override @Transactional boolean addFriend(String friendUsername, String username); @Override @Transactional void removeFriend(String friendUsername, String username); @Override HashMap<String, List<Person>> getFriendsAndRequests(String username); @Override List<Person> getFriendRequestsReceived(String username); @Override @Transactional boolean acceptFriendRequest(String friendUsername, String username); @Override UserDetails loadUserDetails(OpenIDAuthenticationToken token);  }### Answer:
@Test public void getUsersByFreeTextSearch() { final String searchTerm = "Doe"; User user1 = new UserImpl("123", "john.doe.sr"); User user2 = new UserImpl("456", "john.doe.jr"); List<User> users = new ArrayList<User>(); users.add(user1); users.add(user2); final int offset = 0; final int pageSize = 10; expect(userRepository.getCountByUsernameOrEmail(searchTerm)).andReturn(users.size()); expect(userRepository.findByUsernameOrEmail(searchTerm, offset, pageSize)).andReturn(users); replay(userRepository); SearchResult<User> result = service.getUsersByFreeTextSearch(searchTerm, offset, pageSize); assertEquals(pageSize, result.getPageSize()); assertEquals(users.size(), result.getResultSet().size()); assertEquals(user1, result.getResultSet().get(0)); verify(userRepository); }