KeyCloakUserManager extends BaseKeyCloakManager implements UserManager,
                                                                        ContextualManager { @Override public SearchResponse<User> search(SearchRequest request) throws SecurityManagementException { final SearchRequest req = getSearchRequest(request); if (req.getPage() <= 0) { throw new RuntimeException("First page must be 1."); } final int page = req.getPage() - 1; final int pageSize = req.getPageSize(); final List<User> users = new ArrayList<User>(); final int[] numberOfFoundUsers = new int[]{0}; final boolean[] hasNextPage = new boolean[]{false}; consumeRealm(realmResource -> { final UsersResource usersResource = realmResource.users(); final List<UserRepresentation> userRepresentations = usersResource.search(req.getSearchPattern(), page * pageSize, pageSize + 1); numberOfFoundUsers[0] = usersResource.search(req.getSearchPattern(), 1, Integer.MAX_VALUE).size(); if (userRepresentations != null && !userRepresentations.isEmpty()) { int x = 0; for (UserRepresentation userRepresentation : userRepresentations) { if (x == req.getPageSize()) { hasNextPage[0] = true; } else { final User user = createUser(userRepresentation); users.add(user); x++; } } } }); return new SearchResponseImpl<User>(users, page + 1, pageSize, numberOfFoundUsers[0], hasNextPage[0]); } KeyCloakUserManager(); @Override void initialize(final UserSystemManager userSystemManager); @Override SearchResponse<User> search(SearchRequest request); @Override User get(String username); @Override List<User> getAll(); @Override User create(User entity); @Override User update(User entity); @Override void delete(String... identifiers); @Override UserManagerSettings getSettings(); @Override void assignGroups(String username,
                             Collection<String> groups); @Override void assignRoles(String username,
                            Collection<String> roles); @Override void changePassword(String username,
                               String newPassword); @Override void destroy();  }
@Test(expected = RuntimeException.class) public void testSearchPageZero() { AbstractEntityManager.SearchRequest request = buildSearchRequestMock("", 0, 5); AbstractEntityManager.SearchResponse<User> response = usersManager.search(request); }