UserManagementServiceImpl implements UserManagementService { @GET @Path("/count") @Override public Response getUserCount() { try { UserStoreCountRetriever userStoreCountRetrieverService = DeviceMgtAPIUtils.getUserStoreCountRetrieverService(); RealmConfiguration secondaryRealmConfiguration = DeviceMgtAPIUtils.getUserRealm().getRealmConfiguration() .getSecondaryRealmConfig(); if (secondaryRealmConfiguration != null) { if (!secondaryRealmConfiguration.isPrimary() && !Constants.JDBC_USERSTOREMANAGER. equals(secondaryRealmConfiguration.getUserStoreClass().getClass())) { return getUserCountViaUserStoreManager(); } } if (userStoreCountRetrieverService != null) { long count = userStoreCountRetrieverService.countUsers(""); if (count != -1) { BasicUserInfoList result = new BasicUserInfoList(); result.setCount(count); return Response.status(Response.Status.OK).entity(result).build(); } } } catch (UserStoreCounterException e) { String msg = "Error occurred while retrieving the count of users that exist within the current tenant"; log.error(msg, e); } catch (UserStoreException e) { String msg = "Error occurred while retrieving user stores."; log.error(msg, e); } return getUserCountViaUserStoreManager(); }  @POST @Override Response addUser(UserInfo userInfo); @GET @Path("/{username}") @Override Response getUser(@PathParam("username") String username, @QueryParam("domain") String domain,
                            @HeaderParam("If-Modified-Since") String ifModifiedSince); @PUT @Path("/{username}") @Override Response updateUser(@PathParam("username") String username, @QueryParam("domain") String domain, UserInfo userInfo); @DELETE @Path("/{username}") @Override Response removeUser(@PathParam("username") String username, @QueryParam("domain") String domain); @GET @Path("/{username}/roles") @Override Response getRolesOfUser(@PathParam("username") String username, @QueryParam("domain") String domain); @GET @Override Response getUsers(@QueryParam("filter") String filter, @HeaderParam("If-Modified-Since") String timestamp,
                             @QueryParam("offset") int offset,
                             @QueryParam("limit") int limit); @GET @Path("/count") @Override Response getUserCount(); @GET @Path("/checkUser") @Override Response isUserExists(@QueryParam("username") String userName); @GET @Path("/search/usernames") @Override Response getUserNames(@QueryParam("filter") String filter, @QueryParam("domain") String domain,
                                 @HeaderParam("If-Modified-Since") String timestamp,
                                 @QueryParam("offset") int offset, @QueryParam("limit") int limit); @PUT @Path("/credentials") @Override Response resetPassword(OldPasswordResetWrapper credentials); @POST @Path("/send-invitation") @Produces({MediaType.APPLICATION_JSON}) Response inviteExistingUsersToEnrollDevice(List<String> usernames); @POST @Path("/enrollment-invite") @Override Response inviteToEnrollDevice(EnrollmentInvitation enrollmentInvitation);  }
@Test(description = "This method tests the behaviour of getUserCount method of UserManagementService", dependsOnMethods = {"testRemoveUser"}) public void testGetUserCount() throws UserStoreException { PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getUserRealm")).toReturn(userRealm); PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getUserStoreCountRetrieverService")) .toReturn(null); PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getUserStoreManager")) .toReturn(this.userStoreManager); Response response = userManagementService.getUserCount(); Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode(), "User count retrieval failed"); }