GroupManagementServiceImpl implements GroupManagementService { @Override public Response getGroupCount() { try { String currentUser = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername(); int count = DeviceMgtAPIUtils.getGroupManagementProviderService().getGroupCount(currentUser); return Response.status(Response.Status.OK).entity(count).build(); } catch (GroupManagementException e) { String msg = "Error occurred while retrieving group count."; log.error(msg, e); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); } }  @Override Response getGroups(String name, String owner, int offset, int limit); @Override Response getGroupCount(); @Override Response createGroup(DeviceGroup group); @Override Response getGroup(int groupId); @Override Response updateGroup(int groupId, DeviceGroup deviceGroup); @Override Response deleteGroup(int groupId); @Override Response manageGroupSharing(int groupId, List<String> userRoles); @Override Response getRolesOfGroup(int groupId); @Override Response getDevicesOfGroup(int groupId, int offset, int limit); @Override Response getDeviceCountOfGroup(int groupId); @Override Response addDevicesToGroup(int groupId, List<DeviceIdentifier> deviceIdentifiers); @Override Response removeDevicesFromGroup(int groupId, List<DeviceIdentifier> deviceIdentifiers); @Override Response updateDeviceAssigningToGroups(DeviceToGroupsAssignment deviceToGroupsAssignment); @Override Response getGroups(String deviceId, String deviceType);  }
@Test(description = "This method tests the behaviour of getGroupCount method under valid conditions and invalid " + "conditions") public void testGetGroupCount() throws GroupManagementException { PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getGroupManagementProviderService")) .toReturn(groupManagementProviderService); PowerMockito.stub(PowerMockito.method(PrivilegedCarbonContext.class, "getThreadLocalCarbonContext")) .toReturn(context); Mockito.doReturn(2).when(groupManagementProviderService).getGroupCount(Mockito.anyString()); Response response = groupManagementService.getGroupCount(); Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode(), "GetGroupCount request failed with valid parameters"); Mockito.reset(groupManagementProviderService); Mockito.doThrow(new GroupManagementException()).when(groupManagementProviderService) .getGroupCount(Mockito.anyString()); response = groupManagementService.getGroupCount(); Assert.assertEquals(response.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), "GetGroupCount request succeeded with in-valid parameters"); }