GroupManagementServiceImpl implements GroupManagementService { @Override public Response getRolesOfGroup(int groupId) { try { List<String> groupRoles = DeviceMgtAPIUtils.getGroupManagementProviderService().getRoles(groupId); RoleList deviceGroupRolesList = new RoleList(); if(groupRoles != null) { deviceGroupRolesList.setList(groupRoles); deviceGroupRolesList.setCount(groupRoles.size()); } else { deviceGroupRolesList.setList(new ArrayList<>()); deviceGroupRolesList.setCount(0); } return Response.status(Response.Status.OK).entity(deviceGroupRolesList).build(); } catch (GroupManagementException e) { String msg = "Error occurred while getting roles of the group."; 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 functionality of getGroupRoles under various conditions") public void testGetGroupRoles() throws GroupManagementException { PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getGroupManagementProviderService")) .toReturn(groupManagementProviderService); Mockito.doReturn(new ArrayList<String>()).when(groupManagementProviderService).getRoles(1); Mockito.doReturn(null).when(groupManagementProviderService).getRoles(2); Mockito.doThrow(new GroupManagementException()).when(groupManagementProviderService).getRoles(3); Response response = groupManagementService.getRolesOfGroup(1); Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode(), "getRolesOfGroup request failed for a request with valid parameters"); response = groupManagementService.getRolesOfGroup(2); Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode(), "getRolesOfGroup request failed for a request with valid parameters"); response = groupManagementService.getRolesOfGroup(3); Assert.assertEquals(response.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), "getRolesOfGroup request failed for a request with in-valid parameters"); }