ArgumentParser { public File getFileValue(Option option) { String value = getStringValue(option); return (value != null) ? new File(value) : null; } 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 testGetFileValue() throws ParseException { File testDefaultValue = new File("default_file_name"); ArgumentParser argParser = new ArgumentParser(""); Option fileOpt = argParser.addArgument("f", "file", true, "Source file name", false); File inputValue; File resultValue; final String shortFileOpt = String.format("-%s", fileOpt.getOpt()); final String longFileOpt = String.format("--%s", fileOpt.getLongOpt()); argParser.parseArguments(new String[] {""}); assertNull(argParser.getFileValue(fileOpt)); assertEquals(testDefaultValue, argParser.getFileValue(fileOpt, testDefaultValue)); inputValue = new File("folder/file_name_1"); argParser.parseArguments(new String[] {shortFileOpt, inputValue.toString()}); resultValue = argParser.getFileValue(fileOpt); assertNotNull(resultValue); assertEquals(inputValue, resultValue); inputValue = new File("folder/file_name_2"); argParser.parseArguments(new String[] {shortFileOpt, inputValue.toString()}); resultValue = argParser.getFileValue(fileOpt, testDefaultValue); assertNotNull(resultValue); assertEquals(inputValue, resultValue); inputValue = new File("file_name_3"); argParser.parseArguments(new String[] {longFileOpt, inputValue.toString()}); resultValue = argParser.getFileValue(fileOpt); assertNotNull(resultValue); assertEquals(inputValue, resultValue); }