GeneralInterrogationService { public void sendGeneralInterrogation(final ClientConnection deviceConnection, final RequestMetadata requestMetadata) throws IOException { final int commonAddress = deviceConnection.getConnectionParameters().getCommonAddress(); deviceConnection.getConnection() .interrogation(commonAddress, CauseOfTransmission.ACTIVATION, new IeQualifierOfInterrogation(QUALIFIER_OF_INTERROGATION_ID)); final ASdu asdu = new ASdu(ASduType.C_IC_NA_1, false, CauseOfTransmission.ACTIVATION, false, false, ORIGINATOR_ADDRESS, commonAddress, new InformationObject(0, new IeQualifierOfInterrogation(QUALIFIER_OF_INTERROGATION_ID))); final LogItem logItem = new LogItem(requestMetadata.getDeviceIdentification(), requestMetadata.getOrganisationIdentification(), false, asdu.toString()); this.loggingService.log(logItem); }  void sendGeneralInterrogation(final ClientConnection deviceConnection, final RequestMetadata requestMetadata);  }
@Test void testSendGeneralInterrogationShouldLogSameAsduAsUsedInInterrogation() throws Exception { final ConnectionParameters connectionParameters = ConnectionParameters.newBuilder() .deviceIdentification(DEVICE_IDENTIFICATION) .build(); final DeviceConnection deviceConnection = new DeviceConnection(this.connection, connectionParameters); final RequestMetadata requestMetadata = RequestMetadataFactory.forDevice(DEVICE_IDENTIFICATION); doCallRealMethod().when(this.connection) .interrogation(anyInt(), any(CauseOfTransmission.class), any(IeQualifierOfInterrogation.class)); this.generalInterrogationService.sendGeneralInterrogation(deviceConnection, requestMetadata); final ArgumentCaptor<ASdu> asduCaptor = ArgumentCaptor.forClass(ASdu.class); final ArgumentCaptor<LogItem> logItemCaptor = ArgumentCaptor.forClass(LogItem.class); verify(this.connection).send(asduCaptor.capture()); verify(this.loggingService).log(logItemCaptor.capture()); assertThat(logItemCaptor.getValue().getMessage()).isEqualTo(asduCaptor.getValue().toString()); }