@Test(description = "This method tests updateDeviceAssigningToGroups under different conditions.")
public void testUpdateDeviceAssigningToGroups() throws GroupManagementException, DeviceNotFoundException {

    PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getGroupManagementProviderService"))
            .toReturn(groupManagementProviderService);
    Mockito.reset(groupManagementProviderService);
    DeviceToGroupsAssignment deviceToGroupsAssignment = new DeviceToGroupsAssignment();
    List<Integer> groupIds = new ArrayList<>();
    groupIds.add(1);
    groupIds.add(2);
    deviceToGroupsAssignment.setDeviceGroupIds(groupIds);
    deviceToGroupsAssignment.setDeviceIdentifier(new DeviceIdentifier("test", "android"));
    List<DeviceGroup> deviceGroups = new ArrayList<>();
    DeviceGroup deviceGroup = new DeviceGroup();
    deviceGroup.setGroupId(1);
    deviceGroups.add(deviceGroup);
    deviceGroup = new DeviceGroup();
    deviceGroup.setGroupId(3);
    deviceGroup.setOwner(CarbonConstants.REGISTRY_SYSTEM_USERNAME);
    deviceGroups.add(deviceGroup);
    deviceGroup = new DeviceGroup();
    deviceGroup.setGroupId(4);
    deviceGroup.setOwner("test");
    deviceGroups.add(deviceGroup);
    Mockito.doReturn(deviceGroups).when(groupManagementProviderService)
            .getGroups(Mockito.any(DeviceIdentifier.class));
    Mockito.doNothing().when(groupManagementProviderService).addDevices(Mockito.anyInt(), Mockito.any());
    Mockito.doNothing().when(groupManagementProviderService).removeDevice(Mockito.anyInt(), Mockito.any());
    Response response = groupManagementService.updateDeviceAssigningToGroups(deviceToGroupsAssignment);
    Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode(),
            "updateDeviceAssigningToGroups request failed with valid parameters");
    Mockito.doThrow(new DeviceNotFoundException()).when(groupManagementProviderService)
            .removeDevice(Mockito.anyInt(), Mockito.any());
    response = groupManagementService.updateDeviceAssigningToGroups(deviceToGroupsAssignment);
    Assert.assertEquals(response.getStatus(), Response.Status.BAD_REQUEST.getStatusCode(),
            "updateDeviceAssigningToGroups request succeeded with in-valid parameters");
    Mockito.doThrow(new GroupManagementException()).when(groupManagementProviderService)
            .getGroups(Mockito.any(DeviceIdentifier.class));
    response = groupManagementService.updateDeviceAssigningToGroups(deviceToGroupsAssignment);
    Assert.assertEquals(response.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(),
            "updateDeviceAssigningToGroups request succeeded with in-valid parameters");
}