UserService { public Page<UserDTO> search(Pageable pageable, String query) { return this.userRepository .findAllByLoginContainingOrFirstNameContainingOrLastNameContainingOrLoginLike( pageable, query, query, query, query ).map(UserDTO::new); } UserService(UserRepository userRepository, AuthorityRepository authorityRepository, PasswordEncoder passwordEncoder); User register(UserRegister user); void update(UserDTO userDTO); void update(String id, String login, String firstName, String lastName, String email, String langKey); void delete(String login); Optional<User> activateRegistration(String key); Page<UserDTO> search(Pageable pageable, String query); Page<UserDTO> getAll(Pageable pageable); Optional<User> getById(String id); Optional<User> getByLogin(String login); Optional<User> getByEmail(String email); void changePassword(String id, String password); Optional<User> requestPasswordReset(String mail); Optional<User> completePasswordReset(String password, String key); @Scheduled(cron = "0 0 1 * * ?") void removeNotActivatedUsers();  }
@Test public void whenSearchNotExistingUser() { this.createUser(); List<UserDTO> result = this.userService.search(PageRequest.of(0, 1), "set").getContent(); assertTrue(result.isEmpty()); }
@Test public void whenSearchUser() { User expected = this.createUser(); UserDTO result = this.userService.search(PageRequest.of(0, 1), "tes").getContent().get(0); assertEquals(expected.getLogin(), result.getLogin()); }