ScanEngineServiceImpl implements ScanEngineService { @Override public Container removeContainer(Scan scan) { Container removedContainerInfo = null; try { logService.insert(scan, LogType.INFO, "Removing the scanner container for the scan: " + scan.getJobId()); for (Container containerInfo : dockerHandler.list()) { Map<String, String> labels = containerInfo.getLabels(); if (labels.get(CONTAINER_SCAN_JOB_ID_LABEL_NAME).equals(scan.getJobId())) { dockerHandler.clean(containerInfo.getId()); removedContainerInfo = containerInfo; logService.insert(scan, LogType.INFO, "Scanner container successfully removed. Container id: " + containerInfo.getId()); break; } } } catch (ScanManagerException e) { logService.insertError(scan, e); } return removedContainerInfo; } @Autowired  ScanEngineServiceImpl(ScanService scanService, ScannerService scannerService, LogService logService,
                                 ContainerHandler dockerHandler); @Override void beginPendingScans(); @Override void cancelScan(Scan scan); @Override Container removeContainer(Scan scan);  }
@Test(dataProvider = "getScanEngineData", dataProviderClass = ServiceTestDataProvider.class) public void testRemoveContainer(Object scanDataObject, Object containerDataObject) { try { Scan scan = ServiceTestDataProvider.parseScanObject(scanDataObject); Container container = ServiceTestDataProvider.parseContainerObject(containerDataObject); if (scan != null && container != null) { Mockito.when(containerHandler.list()).thenReturn(Collections.singletonList(container)); Mockito.doNothing().when(containerHandler).clean(container.getId()); Container removedTestContainer = scanEngineService.removeContainer(scan); Assert.assertEquals(scan.getJobId(), removedTestContainer.getLabels().get(CONTAINER_SCAN_JOB_ID_LABEL_NAME)); } else { throw new ScanManagerException("Unable to get the scan test data"); } } catch (ScanManagerException e) { Assert.fail(e.getMessage()); } }