GroupManagementServiceImpl implements GroupManagementService { @Override public Response getDevicesOfGroup(int groupId, int offset, int limit) { try { GroupManagementProviderService service = DeviceMgtAPIUtils.getGroupManagementProviderService(); List<Device> deviceList = service.getDevices(groupId, offset, limit); int deviceCount = service.getDeviceCount(groupId); DeviceList deviceListWrapper = new DeviceList(); if (deviceList != null) { deviceListWrapper.setList(deviceList); } else { deviceListWrapper.setList(new ArrayList<>()); } deviceListWrapper.setCount(deviceCount); return Response.status(Response.Status.OK).entity(deviceListWrapper).build(); } catch (GroupManagementException e) { String msg = "Error occurred while getting devices 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 getDevicesOfGroup under various conditions") public void testGetDevicesOfGroup() throws GroupManagementException { PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getGroupManagementProviderService")) .toReturn(groupManagementProviderService); Mockito.doReturn(1).when(groupManagementProviderService).getDeviceCount(Mockito.anyInt()); Mockito.doReturn(new ArrayList<Device>()).when(groupManagementProviderService).getDevices(1, 0, 10); Mockito.doReturn(null).when(groupManagementProviderService).getDevices(2, 0, 10); Mockito.doThrow(new GroupManagementException()).when(groupManagementProviderService).getDevices(3, 0, 10); Response response = groupManagementService.getDevicesOfGroup(1, 0, 10); Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode(), "getDevicesOfGroup request failed for a request with valid parameters"); response = groupManagementService.getDevicesOfGroup(2, 0, 10); Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode(), "getDevicesOfGroup request failed for a request with valid parameters"); response = groupManagementService.getDevicesOfGroup(3, 0, 10); Assert.assertEquals(response.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), "getDevicesOfGroup request succeded for a request with in-valid parameters"); }