GroupManagementServiceImpl implements GroupManagementService { @Override public Response getGroup(int groupId) { try { GroupManagementProviderService service = DeviceMgtAPIUtils.getGroupManagementProviderService(); DeviceGroup deviceGroup = service.getGroup(groupId); if (deviceGroup != null) { return Response.status(Response.Status.OK).entity(deviceGroup).build(); } else { return Response.status(Response.Status.NOT_FOUND).build(); } } catch (GroupManagementException e) { String error = "Error occurred while getting the group."; log.error(error, e); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(error).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 getGroup method under various conditions") public void testGetGroup() throws GroupManagementException { PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getGroupManagementProviderService")) .toReturn(groupManagementProviderService); Mockito.doReturn(new DeviceGroup()).when(groupManagementProviderService).getGroup(1); Mockito.doReturn(null).when(groupManagementProviderService).getGroup(2); Mockito.doThrow(new GroupManagementException()).when(groupManagementProviderService).getGroup(3); Response response = groupManagementService.getGroup(1); Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode(), "getGroup request failed for a request with valid parameters"); response = groupManagementService.getGroup(2); Assert.assertEquals(response.getStatus(), Response.Status.NOT_FOUND.getStatusCode(), "getGroup request returned a group for a non-existing group"); response = groupManagementService.getGroup(3); Assert.assertEquals(response.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), "getGroup request returned a group for a in-valid request"); }