SecurityAnalysisTool implements Tool { @Override public void run(CommandLine line, ToolRunningContext context) throws Exception { run(line, context, createBuilder(PlatformConfig.defaultConfig()), SecurityAnalysisParameters::load, new ImportersServiceLoader(), TableFormatterConfig::load); }  @Override Command getCommand(); @Override void run(CommandLine line, ToolRunningContext context);  }
@Test public void testRunWithLog() throws Exception { try (ByteArrayOutputStream bout = new ByteArrayOutputStream(); ByteArrayOutputStream berr = new ByteArrayOutputStream(); PrintStream out = new PrintStream(bout); PrintStream err = new PrintStream(berr); ComputationManager cm = mock(ComputationManager.class)) { CommandLine cl = mockCommandLine(ImmutableMap.of("case-file", "network.xml", "log-file", "out.zip"), ImmutableSet.of("skip-postproc")); ToolRunningContext context = new ToolRunningContext(out, err, fileSystem, cm, cm); SecurityAnalysisFactory saFactory = new SecurityAnalysisMockFactory(); SecurityAnalysis sa = saFactory.create(null, cm, 1); SecurityAnalysisExecutionBuilder builder = new SecurityAnalysisExecutionBuilder(ExternalSecurityAnalysisConfig::new, () -> saFactory, executionInput -> new SecurityAnalysisInput(executionInput.getNetworkVariant())); tool.run(cl, context, builder, SecurityAnalysisParameters::new, new ImportersLoaderList(new NetworkImporterMock()), TableFormatterConfig::new); verify(sa, never()).run(any(), any(), any()); verify(sa, times(1)).runWithLog(any(), any(), any()); when(cl.hasOption("log-file")).thenReturn(false); tool.run(cl, context, builder, SecurityAnalysisParameters::new, new ImportersLoaderList(new NetworkImporterMock()), TableFormatterConfig::new); verify(sa, times(1)).run(any(), any(), any()); SecurityAnalysisFactory saFactory2 = new SecurityAnalysisMockFactory(true); SecurityAnalysisExecutionBuilder builder2 = new SecurityAnalysisExecutionBuilder(ExternalSecurityAnalysisConfig::new, () -> saFactory2, executionInput -> new SecurityAnalysisInput(executionInput.getNetworkVariant())); try { tool.run(cl, context, builder2, SecurityAnalysisParameters::new, new ImportersLoaderList(new NetworkImporterMock()), TableFormatterConfig::new); fail(); } catch (CompletionException exception) { assertTrue(exception.getCause() instanceof ComputationException); } } }