### Question:
ScanService implements SynchronMessageHandler { @Override @IsRecevingSyncMessage(MessageID.START_SCAN) public DomainMessageSynchronousResult receiveSynchronMessage(DomainMessage request) { notNull(request, "Request may not be null!"); if (!request.hasID(MessageID.START_SCAN)) { return new DomainMessageSynchronousResult(MessageID.UNSUPPORTED_OPERATION, new UnsupportedOperationException("Can only handle " + MessageID.START_SCAN)); } return startScan(request); }  @Override @IsRecevingSyncMessage(MessageID.START_SCAN) DomainMessageSynchronousResult receiveSynchronMessage(DomainMessage request);  }### Answer:
@Test public void when_no_exception_is_thrown_result_has_not_failed() throws Exception { DomainMessageSynchronousResult result = serviceToTest.receiveSynchronMessage(prepareValidRequest()); assertFalse(result.hasFailed()); }
@Test public void scanservice_does_execute_webscan_execution_service() throws Exception { serviceToTest.receiveSynchronMessage(prepareValidRequest()); verify(webScanProductExecutionService).executeProductsAndStoreResults(any()); }
@Test public void scanservice_does_execute_infrascan_execution_service() throws Exception { serviceToTest.receiveSynchronMessage(prepareValidRequest()); verify(infrastructureScanProductExecutionService).executeProductsAndStoreResults(any()); }
@Test public void scanservice_does_execute_codescan_execution_service() throws Exception { serviceToTest.receiveSynchronMessage(prepareValidRequest()); verify(codeScanProductExecutionService).executeProductsAndStoreResults(any()); }
@Test public void scanservice_does_cleanup_storage_of_job__when_not_failed() throws Exception { DomainMessageSynchronousResult result = serviceToTest.receiveSynchronMessage(prepareValidRequest()); verify(jobStorage).deleteAll(); assertFalse(result.hasFailed()); }
@Test public void scanservice_does_cleanup_storage_of_job__when_HAS_failed() throws Exception { DomainMessage request = prepareValidRequest(); doThrow(new SecHubExecutionException("ups...", new RuntimeException())).when(webScanProductExecutionService).executeProductsAndStoreResults(any()); DomainMessageSynchronousResult result = serviceToTest.receiveSynchronMessage(request); assertTrue(result.hasFailed()); verify(jobStorage).deleteAll(); }
@Test public void scanservice_does_execute_report_service() throws Exception { serviceToTest.receiveSynchronMessage(prepareValidRequest()); verify(reportService).createReport(any()); }
@Test public void scanservice_set_result_traficlight_as_from_report() throws Exception { DomainMessageSynchronousResult result = serviceToTest.receiveSynchronMessage(prepareValidRequest()); assertEquals(TRAFFIC_LIGHT, result.get(MessageDataKeys.REPORT_TRAFFIC_LIGHT)); }
@Test public void scanservice_does_NOT_execute_reportservice_when_webscan_throws_sechubexception() throws Exception { DomainMessage request = prepareValidRequest(); doThrow(new SecHubExecutionException("ups...", new RuntimeException())).when(webScanProductExecutionService).executeProductsAndStoreResults(any()); DomainMessageSynchronousResult result = serviceToTest.receiveSynchronMessage(request); assertTrue(result.hasFailed()); verify(webScanProductExecutionService).executeProductsAndStoreResults(any()); verify(reportService, never()).createReport(any()); }