GroupManagementServiceImpl implements GroupManagementService { @Override public Response addDevicesToGroup(int groupId, List<DeviceIdentifier> deviceIdentifiers) { try { DeviceMgtAPIUtils.getGroupManagementProviderService().addDevices(groupId, deviceIdentifiers); return Response.status(Response.Status.OK).build(); } catch (GroupManagementException e) { String msg = "Error occurred while adding devices to group."; log.error(msg, e); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); } catch (DeviceNotFoundException 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 addDevicesToGroup method under various conditions.") public void testAddDevicesToGroup() throws GroupManagementException, DeviceNotFoundException { PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getGroupManagementProviderService")) .toReturn(groupManagementProviderService); List<DeviceIdentifier> deviceIdentifiers = new ArrayList<>(); Mockito.doNothing().when(groupManagementProviderService).addDevices(1, deviceIdentifiers); Mockito.doThrow(new GroupManagementException()).when(groupManagementProviderService).addDevices(2, deviceIdentifiers); Mockito.doThrow(new DeviceNotFoundException()).when(groupManagementProviderService).addDevices(3, deviceIdentifiers); Response response = groupManagementService.addDevicesToGroup(1, deviceIdentifiers); Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode(), "addDevicesToGroup request failed for a request with valid parameters"); response = groupManagementService.addDevicesToGroup(2, deviceIdentifiers); Assert.assertEquals(response.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), "addDevicesToGroup request succeded for a request with in-valid parameters"); response = groupManagementService.addDevicesToGroup(3, deviceIdentifiers); Assert.assertEquals(response.getStatus(), Response.Status.BAD_REQUEST.getStatusCode(), "addDevicesToGroup request succeded for a request with in-valid parameters"); }