GroupManagementServiceImpl implements GroupManagementService { @Override public Response manageGroupSharing(int groupId, List<String> userRoles) { try { DeviceMgtAPIUtils.getGroupManagementProviderService() .manageGroupSharing(groupId, userRoles); return Response.status(Response.Status.OK).build(); } catch (GroupManagementException e) { String msg = "Error occurred while managing group share. "; if (e.getErrorMessage() != null){ msg += e.getErrorMessage(); } log.error(msg, e); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); } catch (RoleDoesNotExistException e) { return Response.status(Response.Status.BAD_REQUEST).entity(e.getMessage()).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 manageGroupSharing under various conditions") public void testManageGroupSharing() throws GroupManagementException, RoleDoesNotExistException { PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getGroupManagementProviderService")) .toReturn(groupManagementProviderService); Mockito.doNothing().when(groupManagementProviderService).manageGroupSharing(1, null); Mockito.doThrow(new GroupManagementException("test")).when(groupManagementProviderService) .manageGroupSharing(2, null); Mockito.doThrow(new RoleDoesNotExistException()).when(groupManagementProviderService) .manageGroupSharing(3, null); Response response = groupManagementService.manageGroupSharing(1, null); Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode(), "managegroupSharing request failed for a request with valid parameters"); response = groupManagementService.manageGroupSharing(2, null); Assert.assertEquals(response.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), "managegroupSharing request succeeded for a request with in-valid parameters"); response = groupManagementService.manageGroupSharing(3, null); Assert.assertEquals(response.getStatus(), Response.Status.BAD_REQUEST.getStatusCode(), "managegroupSharing request succeeded for a request with in-valid parameters"); }