ArgumentParser { @SuppressFBWarnings(value = "UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR", justification = "This is a false positive. A null check is present.") public String getStringValue(Option option) throws IllegalStateException { ensureCommandLineNotNull(); return commandLine.getOptionValue(option.getOpt()); } ArgumentParser(String applicationName); String getApplicationName(); Option addArgument(Option option, boolean required); Option addArgument(String opt, String longOpt, boolean hasArg, String description, boolean required); Collection getConfiguredOptions(); void parseArguments(String[] args, boolean failOnMissingRequiredOptions); void parseArguments(String[] args); String getUsageInformation(); @SuppressFBWarnings(value = "UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR", justification = "This is a false positive. A null check is present.") Boolean getBooleanValue(Option option); @SuppressFBWarnings(value = "UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR", justification = "This is a false positive. A null check is present.") Boolean getStringValueAsBoolean(Option option, Boolean defaultValue); @SuppressFBWarnings(value = "UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR", justification = "This is a false positive. A null check is present.") String getStringValue(Option option); String getStringValue(Option option, String defaultValue); Integer getIntegerValue(Option option); Integer getIntegerValue(Option option, Integer defaultValue); Integer getIntegerValue(Option option, Integer defaultValue, Integer minValue, Integer maxValue); File getFileValue(Option option); File getFileValue(Option option, File defaultValue);  }
@Test public void testGetStringValue() throws ParseException { final String testDefaultValue = "default_str_value"; ArgumentParser argParser = new ArgumentParser(""); Option strOpt = argParser.addArgument("s", "str", true, "Some string input parameter", false); String inputValue; String resultValue; final String shortStrOpt = String.format("-%s", strOpt.getOpt()); final String longStrOpt = String.format("--%s", strOpt.getLongOpt()); argParser.parseArguments(new String[] {}); assertNull(argParser.getStringValue(strOpt)); assertEquals(testDefaultValue, argParser.getStringValue(strOpt, testDefaultValue)); inputValue = "my_string_value_1"; argParser.parseArguments(new String[] {shortStrOpt, inputValue}); resultValue = argParser.getStringValue(strOpt); assertNotNull(resultValue); assertEquals(inputValue, resultValue); inputValue = "my_string_value_2"; argParser.parseArguments(new String[] {shortStrOpt, inputValue}); resultValue = argParser.getStringValue(strOpt, testDefaultValue); assertNotNull(resultValue); assertEquals(inputValue, resultValue); inputValue = "my_string_value_3"; argParser.parseArguments(new String[] {longStrOpt, inputValue}); resultValue = argParser.getStringValue(strOpt); assertNotNull(resultValue); assertEquals(inputValue, resultValue); }