GroupManagementServiceImpl implements GroupManagementService { @Override public Response updateGroup(int groupId, DeviceGroup deviceGroup) { if (deviceGroup == null) { return Response.status(Response.Status.BAD_REQUEST).build(); } try { DeviceMgtAPIUtils.getGroupManagementProviderService().updateGroup(deviceGroup, groupId); return Response.status(Response.Status.OK).build(); } catch (GroupManagementException e) { String msg = "Error occurred while adding new group."; log.error(msg, e); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); } catch (GroupNotExistException e) { String msg = "There is another group already exists with name '" + deviceGroup.getName() + "'."; log.warn(msg); return Response.status(Response.Status.CONFLICT).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 updateGroup method under various conditions") public void testUpdateGroup() throws GroupManagementException, GroupNotExistException { PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getGroupManagementProviderService")) .toReturn(groupManagementProviderService); DeviceGroup deviceGroup = new DeviceGroup(); deviceGroup.setGroupId(1); Mockito.doNothing().when(groupManagementProviderService).updateGroup(deviceGroup, 1); Mockito.doThrow(new GroupManagementException()).when(groupManagementProviderService) .updateGroup(deviceGroup, 2); Mockito.doThrow(new GroupNotExistException()).when(groupManagementProviderService).updateGroup(deviceGroup, 3); Response response = groupManagementService.updateGroup(1, deviceGroup); Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode(), "update request failed for a request with valid parameters"); response = groupManagementService.updateGroup(2, deviceGroup); Assert.assertEquals(response.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), "update request succeeded for a in-valid request"); response = groupManagementService.updateGroup(3, deviceGroup); Assert.assertEquals(response.getStatus(), Response.Status.CONFLICT.getStatusCode(), "update request succeeded for a in-valid request"); response = groupManagementService.updateGroup(4, null); Assert.assertEquals(response.getStatus(), Response.Status.BAD_REQUEST.getStatusCode(), "update request succeeded for a in-valid request"); }