SecurityAnalysisTool implements Tool { static void updateInput(ToolOptions options, SecurityAnalysisExecutionInput inputs) { options.getPath(PARAMETERS_FILE_OPTION) .ifPresent(f -> JsonSecurityAnalysisParameters.update(inputs.getParameters(), f)); options.getPath(CONTINGENCIES_FILE_OPTION) .map(p -> FileUtil.asByteSource(p)) .ifPresent(inputs::setContingenciesSource); options.getValues(LIMIT_TYPES_OPTION) .map(types -> types.stream().map(LimitViolationType::valueOf).collect(Collectors.toList())) .ifPresent(inputs::addViolationTypes); options.getValues(WITH_EXTENSIONS_OPTION) .ifPresent(inputs::addResultExtensions); }  @Override Command getCommand(); @Override void run(CommandLine line, ToolRunningContext context);  }
@Test public void parseInputs() throws IOException { ToolOptions options = emptyOptions(); SecurityAnalysisExecutionInput input = new SecurityAnalysisExecutionInput(); SecurityAnalysisTool.updateInput(options, input); assertThat(input.getViolationTypes()).isEmpty(); assertThat(input.getResultExtensions()).isEmpty(); assertThat(input.getContingenciesSource()).isNotPresent(); options = mockOptions(ImmutableMap.of(SecurityAnalysisToolConstants.LIMIT_TYPES_OPTION, "HIGH_VOLTAGE,CURRENT")); SecurityAnalysisTool.updateInput(options, input); assertThat(input.getViolationTypes()).containsExactly(LimitViolationType.CURRENT, LimitViolationType.HIGH_VOLTAGE); options = mockOptions(ImmutableMap.of(SecurityAnalysisToolConstants.WITH_EXTENSIONS_OPTION, "ext1,ext2")); SecurityAnalysisTool.updateInput(options, input); assertThat(input.getResultExtensions()).containsExactly("ext1", "ext2"); ToolOptions invalidOptions = mockOptions(ImmutableMap.of(SecurityAnalysisToolConstants.CONTINGENCIES_FILE_OPTION, "contingencies")); assertThatIllegalArgumentException().isThrownBy(() -> SecurityAnalysisTool.updateInput(invalidOptions, input)); Files.write(fileSystem.getPath("contingencies"), "test".getBytes()); options = mockOptions(ImmutableMap.of(SecurityAnalysisToolConstants.CONTINGENCIES_FILE_OPTION, "contingencies")); SecurityAnalysisTool.updateInput(options, input); assertThat(input.getContingenciesSource()).isPresent(); if (input.getContingenciesSource().isPresent()) { assertEquals("test", new String(input.getContingenciesSource().get().read())); } else { fail(); } }