diff --git a/src/main/java/org/dsikkema/jamphony/jamphony/App.java b/src/main/java/org/dsikkema/jamphony/jamphony/App.java deleted file mode 100644 index 2fbb755..0000000 --- a/src/main/java/org/dsikkema/jamphony/jamphony/App.java +++ /dev/null @@ -1,13 +0,0 @@ -package org.dsikkema.jamphony.jamphony; - -/** - * Hello world! - * - */ -public class App -{ - public static void main( String[] args ) - { - System.out.println( "Hello World!" ); - } -} diff --git a/src/main/java/org/dsikkema/jamphony/jamphony/CommandRunner.java b/src/main/java/org/dsikkema/jamphony/jamphony/CommandRunner.java index f4906c6..ea72366 100644 --- a/src/main/java/org/dsikkema/jamphony/jamphony/CommandRunner.java +++ b/src/main/java/org/dsikkema/jamphony/jamphony/CommandRunner.java @@ -42,7 +42,7 @@ public CommandRunner( * Output, however, has no special dependency on the command and indeed we * may want to share it with whatever program is calling this runner. */ - public int run(String[] args) { + public int run(String[] entries) { int exitCode = 1; CommandInterface command; String commandName = ""; @@ -50,7 +50,7 @@ public int run(String[] args) { InputData inputData; try { - commandName = this.getCommandName(args); + commandName = this.getCommandName(entries); command = this.commandRegistry.getCommandInstance(commandName); inputDefinition = this.inputDefinitionFactory.create(); command.populateInputDefinition(inputDefinition); @@ -58,7 +58,7 @@ public int run(String[] args) { /** * Note: input validation occurs inside the input data factory */ - inputData = this.inputDataFactory.create(inputDefinition, args); + inputData = this.inputDataFactory.create(inputDefinition, entries); exitCode = command.execute(inputData); } catch (InputException e) { /** @@ -106,12 +106,12 @@ private String[] splitCommandString(String commandString) { return argsWithEscapersRemoved; } - private String getCommandName(String[] args) throws InputException { + private String getCommandName(String[] entries) throws InputException { // check length of args - if (args.length < 1 || args[0].isEmpty()) { + if (entries.length < 1 || entries[0].isEmpty()) { throw new InputException("No command given"); } - return args[0]; + return entries[0]; } } diff --git a/src/main/java/org/dsikkema/jamphony/jamphony/io/ArgumentDefinition.java b/src/main/java/org/dsikkema/jamphony/jamphony/io/ArgumentDefinition.java index afdc95a..64de131 100644 --- a/src/main/java/org/dsikkema/jamphony/jamphony/io/ArgumentDefinition.java +++ b/src/main/java/org/dsikkema/jamphony/jamphony/io/ArgumentDefinition.java @@ -1,25 +1,16 @@ package org.dsikkema.jamphony.jamphony.io; -public class ArgumentDefinition { +public class ArgumentDefinition extends EntryDefinition { private String name; private int index; private Type type; public ArgumentDefinition(String name, int index, Type type) { - this.name = name; - this.index = index; - this.type = type; + super(name, type); + this.index = index; } - public String getName() { - return name; - } - public int getIndex() { - return index; - } - - public Type getType() { - return type; + return this.index; } } diff --git a/src/main/java/org/dsikkema/jamphony/jamphony/io/CommandInputDefinition.java b/src/main/java/org/dsikkema/jamphony/jamphony/io/CommandInputDefinition.java index a0d7735..d765236 100644 --- a/src/main/java/org/dsikkema/jamphony/jamphony/io/CommandInputDefinition.java +++ b/src/main/java/org/dsikkema/jamphony/jamphony/io/CommandInputDefinition.java @@ -9,138 +9,49 @@ * Represents the input required by the command, not actual input data itself */ public class CommandInputDefinition { - private final Map arguments = new HashMap<>(); + private final List< ArgumentDefinition> arguments = new ArrayList<>(); private final Map options = new HashMap<>(); private final List flags = new ArrayList<>(); private int argumentCount = 0; - public void addArgument(String argumentName, Type type) { - this.arguments.put(argumentName, new ArgumentDefinition(argumentName, this.argumentCount, type)); - this.argumentCount++; - } - - public void addOption(String optionName, Type type) { - this.options.put(optionName, new OptionDefinition(optionName, type)); - } - - public void addFlag(String flagName) { - this.flags.add(flagName); - } - - public Map getArguments() { - return arguments; - } - - public Map getOptions() { - return options; - } - - public List getFlags() { - return flags; - } - public int getArgumentCount() { return argumentCount; } - public ArgumentDefinition getArgumentDefinition(String argumentName) { - if (!this.arguments.containsKey(argumentName)) { - throw new RuntimeException("Argument '" + argumentName + "' not defined"); + public ArgumentDefinition getArgumentDefinitionByIndex(int index) throws InputException { + if (index >= this.argumentCount || index < 0) { + throw new InputException("Argument at index " + index + " does not exist"); } - return this.arguments.get(argumentName); + return this.arguments.get(index); } - public OptionDefinition getOptionDefinition(String optionName) { + public OptionDefinition getOptionDefinitionByName(String optionName) throws InputException { if (!this.options.containsKey(optionName)) { - throw new RuntimeException("Option '" + optionName + "' not defined"); + throw new InputException("Option '" + optionName + "' is not defined"); } return this.options.get(optionName); } - public void validate(InputData inputData) throws InputException { - // validate that no arguments are missing or extra - if (inputData.getArguments().size() > this.argumentCount) { - throw new InputException("Too many arguments given"); - } else if (inputData.getArguments().size() < this.argumentCount) { - throw new InputException("Too few arguments given"); - } - - // validate argument types - /** - * For each defined argument, get its index and then get the given value - * at that index. Validate that value against the required type. - */ - for (ArgumentDefinition argumentDefinition : this.arguments.values()) { - String givenArgumentValue = inputData.getRawArgumentByIndex(argumentDefinition.getIndex()); - if (!this.validateInputByType(givenArgumentValue, argumentDefinition.getType())) { - throw new InputException(String.format( - "Argument '%s' with value '%s' does not match expected type '%s'", - argumentDefinition.getName(), - givenArgumentValue, - argumentDefinition.getType().getName() - )); - } - } - - // validate no extra options - /** - * Options are inherently _optional_, therefore only validate that there - * are no extra ones - */ - for (String optionName : inputData.getOptions().keySet()) { - if (!this.options.containsKey(optionName)) { - throw new InputException(String.format("Option '%s' is not defined", optionName)); - } - } - - // validate option types - /** - * Validate that all given options have the correct type - */ - for (OptionDefinition optionDefinition : this.options.values()) { - String optionName = optionDefinition.getName(); - String givenOptionValue = inputData.getOption(optionName); - - // only validate type if option is actually provided - if ( - inputData.isOptionProvided(optionName) - && !this.validateInputByType(givenOptionValue, optionDefinition.getType()) - ) { - throw new InputException(String.format( - "Option '%s' with value '%s' does not match expected type '%s'", - optionDefinition.getName(), - givenOptionValue, - optionDefinition.getType().getName() - )); - } - } - - // validate no extra flags - for (String flag : inputData.getFlags()) { - if (!this.flags.contains(flag)) { - throw new InputException(String.format("Flag '%s' is not defined", flag)); - } - } - - // flags are just present or not present, no type validation required + public boolean isFlagDefined(String name) { + return this.flags.contains(name); } - private boolean validateInputByType(String input, Type type) { - return type != Type.INT || this.isInt(input); + /** + * Called by commands to define their input + */ + public void addArgument(String argumentName, Type type) { + this.arguments.add(new ArgumentDefinition(argumentName, this.argumentCount, type)); + this.argumentCount++; } - /** - * TODO: stop abusing exception handling. Use a regex - */ - private boolean isInt(String in) { - try { - Integer.parseInt(in); - } catch (NumberFormatException e) { - return false; - } - return true; + public void addOption(String optionName, Type type) { + this.options.put(optionName, new OptionDefinition(optionName, type)); + } + + public void addFlag(String flagName) { + this.flags.add(flagName); } } diff --git a/src/main/java/org/dsikkema/jamphony/jamphony/io/EntryData.java b/src/main/java/org/dsikkema/jamphony/jamphony/io/EntryData.java new file mode 100644 index 0000000..c6c0194 --- /dev/null +++ b/src/main/java/org/dsikkema/jamphony/jamphony/io/EntryData.java @@ -0,0 +1,60 @@ +package org.dsikkema.jamphony.jamphony.io; + +/** + * "Entry" means an argument, option, or flag. This serves as a generic way to hold entries and their values, and + * encapsulate retrieving them by type + */ +public class EntryData { + + private final EntryDefinition definition; + private final Object val; + + public EntryData(EntryDefinition definition, String val) throws InputException { + switch (definition.getType()) { + case INT: + if (!this.isInt(val)) { + throw new InputException(String.format( + "Entry '%s' with value '%s' does not match expected type '%s'", + definition.getName(), + val, + definition.getType().getName() + )); + } + this.val = Integer.valueOf(val); + break; + case STRING: + this.val = val; + break; + + default: + throw new RuntimeException("Unhandled argument type"); // just to make this compile. Should never be hit + } + + this.definition = definition; + } + + public String getStringValue() { + if (this.definition.getType() != Type.STRING) { + throw new RuntimeException("Argument '" + definition.getName() + "' is not of type " + Type.STRING.getName()); + } + + return (String)this.val; + } + + public int getIntValue() { + if (this.definition.getType() != Type.INT) { + throw new RuntimeException("Argument '" + definition.getName() + "' is not of type " + Type.INT.getName()); + } + + return (int)this.val; + } + + private boolean isInt(String in) { + try { + Integer.parseInt(in); + } catch (NumberFormatException e) { + return false; + } + return true; + } +} diff --git a/src/main/java/org/dsikkema/jamphony/jamphony/io/EntryDefinition.java b/src/main/java/org/dsikkema/jamphony/jamphony/io/EntryDefinition.java new file mode 100644 index 0000000..96caca8 --- /dev/null +++ b/src/main/java/org/dsikkema/jamphony/jamphony/io/EntryDefinition.java @@ -0,0 +1,19 @@ +package org.dsikkema.jamphony.jamphony.io; + +public class EntryDefinition { + private String name; + private Type type; + + public EntryDefinition(String name, Type type) { + this.name = name; + this.type = type; + } + + public String getName() { + return name; + } + + public Type getType() { + return type; + } +} diff --git a/src/main/java/org/dsikkema/jamphony/jamphony/io/InputData.java b/src/main/java/org/dsikkema/jamphony/jamphony/io/InputData.java index 3267e02..0c2b5a9 100644 --- a/src/main/java/org/dsikkema/jamphony/jamphony/io/InputData.java +++ b/src/main/java/org/dsikkema/jamphony/jamphony/io/InputData.java @@ -15,13 +15,8 @@ */ public class InputData { - /** - * raw whitespace-separated strings given to CLI - */ - private final List rawArgs = new ArrayList<>(); - - private final List argumentValues = new ArrayList<>(); - private final Map optionValues = new HashMap<>(); + private final Map argumentValues = new HashMap<>(); + private final Map optionValues = new HashMap<>(); private final Set flagsProvided = new HashSet<>(); private String commandName = ""; @@ -37,64 +32,78 @@ private InputData( } /** - * This method is taken in by constructors, and guice is not yet configured - * to inject args from the main method in the constructor - * @throws InputException + * An "entry" is either an argument, option, or flag. For option, it means the whole key-value pair */ - private void initialize(String[] args) throws InputException { - // inject raw args - for (String argument : args ) { - this.rawArgs.add(argument); - } + private void initialize(String[] entries) throws InputException { + if (entries.length == 0) { + throw new InputException("Command name not given"); + } // process command name, options, args, and flags - boolean isArgumentAllowed = true; int equalSignIndex; String entry; + int index = 1; + this.commandName = entries[0]; + + for ( ; index < this.inputDefinition.getArgumentCount() + 1 && index < entries.length; index++) { + entry = entries[index]; + if (!this.isArgument(entry)) { + throw new InputException("Too few arguments given"); + } + this.addArgument(index - 1, entry); + } - // get command name - if (this.rawArgs.size() >= 1) { - this.commandName = this.rawArgs.get(0); + if (index != this.inputDefinition.getArgumentCount() + 1) { + // means that there are fewer entries than there are arguments required + throw new InputException("Too few arguments given"); + } else if (index < entries.length && this.isArgument(entries[index])) { + throw new InputException("Too many arguments given"); } - for (int i = 1; i < this.rawArgs.size(); i++) { - entry = this.rawArgs.get(i); - if (this.isArgument(entry)) { - // Add argument - - // check arguments allowed - if (isArgumentAllowed) { - this.argumentValues.add(entry); - } else { - /** - * enforce arguments coming before options and flags to enforce better UX, and - * to catch what is most likely a typo where something that should be an option - * is interpreted as argument, e.g. one dash prefix instead of two - */ - throw new InputException("Argument '" + entry + "' provided after options or flags"); - } - } else if (this.isEntryOption(entry)) { + + for ( ; index < entries.length; index++) { + entry = entries[index]; + if (this.isOption(entry)) { // Add option - - isArgumentAllowed = false; equalSignIndex = entry.indexOf("="); - this.optionValues.put( + this.addOption( entry.substring(2, equalSignIndex), // option name entry.substring(equalSignIndex + 1) // option value ); } else if (this.isFlag(entry)) { // Add flag - isArgumentAllowed = false; - this.flagsProvided.add(entry.substring(2)); + this.addFlag(entry.substring(2)); + } else { + // must be an argument + throw new InputException("Argument '" + entry + "' is not given at the beginning of the input"); } } } - private boolean isEntryOption(String entry) { + public void addArgument(int index, String value) throws InputException { + ArgumentDefinition definition = this.inputDefinition.getArgumentDefinitionByIndex(index); + this.argumentValues.put(definition.getName(), new EntryData(definition, value)); + } + + public void addOption(String name, String value) throws InputException { + OptionDefinition definition = this.inputDefinition.getOptionDefinitionByName(name); + this.optionValues.put(name, new EntryData(definition, value)); + } + + public void addFlag(String name) throws InputException { + if (this.inputDefinition.isFlagDefined(name)) { + this.flagsProvided.add(name); + } else { + throw new InputException("Flag '" + name + "' is not defined"); + } + } + + private boolean isOption(String entry) { return entry.substring(0, 2).equals("--") && entry.indexOf("=") > 2; // equal sign must be present and option name must not be empty } + private boolean isFlag(String entry) { return entry.substring(0, 2).equals("--") && !entry.contains("=") @@ -115,15 +124,16 @@ public String getCommandName() { return commandName; } - public List getRawArgs() { - return rawArgs; - } - - public List getArguments() { + /** + * TODO: remove these three methods because the unnecessarily expose internals. + * They're needed to do state-based unit testing, but we should use reflection + * in the test to expose the variables + */ + public Map getArguments() { return argumentValues; } - public Map getOptions() { + public Map getOptions() { return optionValues; } @@ -131,7 +141,10 @@ public Set getFlags() { return flagsProvided; } - public String getOption(String optionName) { + /** + * Data getters + */ + public EntryData getOption(String optionName) { return this.optionValues.get(optionName); } @@ -143,80 +156,15 @@ public boolean isFlagSet(String flagName) { return this.flagsProvided.contains(flagName); } - private String getArgumentByIndex(int index) { - return this.argumentValues.get(index); - } - - /** - * The following are convenience getters that enforce data types. - * - * Probably the better option would be to use objects that represent - * the supplied values, then for the command itself to get a value it - * would first get the argument object from this class, and call - * argumentObject.getStringValue(), etc, and have the object do type - * validation and throw needed exceptions. This would be similar to - * how you read json documents: jsonObject.getStringValue(), .getIntValue(), - * etc. Will leave this for later. - */ - public int getIntArgument(String argumentName) { - ArgumentDefinition argument; - argument = this.inputDefinition.getArgumentDefinition(argumentName); - if (argument.getType() != Type.INT) { - throw new RuntimeException("Argument '" + argumentName + "' is not of type INT"); - } - - return Integer.parseInt(this.getArgumentByIndex(argument.getIndex())); - } - - public String getStringArgument(String argumentName) { - ArgumentDefinition argument; - argument = this.inputDefinition.getArgumentDefinition(argumentName); - if (argument.getType() != Type.STRING) { - throw new RuntimeException("Argument '" + argumentName + "' is not of type STRING"); - } - - return this.getArgumentByIndex(argument.getIndex()); - } - - public int getIntOption(String optionName) { - OptionDefinition option; - option = this.inputDefinition.getOptionDefinition(optionName); - if (option.getType() != Type.INT) { - throw new RuntimeException("Option '" + optionName + "' is not of type INT"); - } - - return Integer.parseInt(this.getOption(optionName)); - } - - public String getStringOption(String optionName) { - OptionDefinition option; - option = this.inputDefinition.getOptionDefinition(optionName); - if (option.getType() != Type.STRING) { - throw new RuntimeException("Option '" + optionName + "' is not of type STRING"); - } - - return this.getOption(optionName); - } - - public String getRawArgumentByIndex(int index) { - if (this.argumentValues.size() <= index || index < 0) { - throw new RuntimeException("There is no argument at index '" + index + "'"); - } - return this.argumentValues.get(index); - } - - private boolean validate() { - // TODO: implement - return true; + public EntryData getArgument(String name) { + return this.argumentValues.get(name); } public static class Factory { public InputData create(CommandInputDefinition inputDefinition, String[] args) throws InputException { - InputData inputData = new InputData(inputDefinition, args); - inputDefinition.validate(inputData); - + InputData inputData = new InputData(inputDefinition, args); return inputData; } } diff --git a/src/main/java/org/dsikkema/jamphony/jamphony/io/OptionDefinition.java b/src/main/java/org/dsikkema/jamphony/jamphony/io/OptionDefinition.java index 32a502e..ade3b05 100644 --- a/src/main/java/org/dsikkema/jamphony/jamphony/io/OptionDefinition.java +++ b/src/main/java/org/dsikkema/jamphony/jamphony/io/OptionDefinition.java @@ -1,19 +1,10 @@ package org.dsikkema.jamphony.jamphony.io; -public class OptionDefinition { - private String name; - private Type type; +public class OptionDefinition extends EntryDefinition { - public OptionDefinition(String name, Type type) { - this.name = name; - this.type = type; - } - - public String getName() { - return name; - } + public OptionDefinition(String name, Type type) { + super(name, type); + // TODO Auto-generated constructor stub + } - public Type getType() { - return type; - } } diff --git a/src/test/java/org/dsikkema/jamphony/jamphony/io/CommandInputIntegrationTest.java b/src/test/java/org/dsikkema/jamphony/jamphony/io/CommandInputIntegrationTest.java index 2c67cf5..388e704 100644 --- a/src/test/java/org/dsikkema/jamphony/jamphony/io/CommandInputIntegrationTest.java +++ b/src/test/java/org/dsikkema/jamphony/jamphony/io/CommandInputIntegrationTest.java @@ -159,7 +159,7 @@ private Object[] invalidCommandInput() { .addEmptyFlag("emptyFlag"); String argumentAfterFlagCommand = "test-command given 1 --givenFlag illegallyPlacedArg --stringOption=given --intOption=123 "; - testCaseList.add(new Object[] {argumentAfterFlagCommand, argumentAfterFlag, "Argument 'illegallyPlacedArg' provided after options or flags"}); + testCaseList.add(new Object[] {argumentAfterFlagCommand, argumentAfterFlag, "Argument 'illegallyPlacedArg' is not given at the beginning of the input"}); /** * argument illegally placed after option @@ -174,7 +174,7 @@ private Object[] invalidCommandInput() { .addEmptyFlag("emptyFlag"); String argumentAfterOptionCommand = "test-command given 1 --stringOption=given illegallyPlacedArg --intOption=123 --givenFlag"; - testCaseList.add(new Object[] {argumentAfterOptionCommand, argumentAfterOption, "Argument 'illegallyPlacedArg' provided after options or flags"}); + testCaseList.add(new Object[] {argumentAfterOptionCommand, argumentAfterOption, "Argument 'illegallyPlacedArg' is not given at the beginning of the input"}); /** * argument illegally placed between flags and options @@ -189,7 +189,7 @@ private Object[] invalidCommandInput() { .addEmptyFlag("emptyFlag"); String argumentAfterFlagAndOptCommand = "test-command given 1 --stringOption=given --givenFlag illegallyPlacedArg --intOption=123 --givenFlag2"; - testCaseList.add(new Object[] {argumentAfterFlagAndOptCommand, argumentAfterFlagAndOpt, "Argument 'illegallyPlacedArg' provided after options or flags"}); + testCaseList.add(new Object[] {argumentAfterFlagAndOptCommand, argumentAfterFlagAndOpt, "Argument 'illegallyPlacedArg' is not given at the beginning of the input"}); /** * multiple illegally placed arguments @@ -205,7 +205,7 @@ private Object[] invalidCommandInput() { String multipleIllegallyPlacedArgsCommand = "test-command given 1 --stringOption=given illegallyPlacedArg " + "--givenFlag illegallyPlacedArg --intOption=123 --givenFlag2 illegallyPlacedArg"; - testCaseList.add(new Object[] {multipleIllegallyPlacedArgsCommand, multipleIllegallyPlacedArgs, "Argument 'illegallyPlacedArg' provided after options or flags"}); + testCaseList.add(new Object[] {multipleIllegallyPlacedArgsCommand, multipleIllegallyPlacedArgs, "Argument 'illegallyPlacedArg' is not given at the beginning of the input"}); /** * argument has wrong type @@ -214,7 +214,7 @@ private Object[] invalidCommandInput() { argumentWrongType.addIntArgument("intArg", 1); String argumentWrongTypeCommand = "test-command stringValue"; - testCaseList.add(new Object[] {argumentWrongTypeCommand, argumentWrongType, "Argument 'intArg' with value 'stringValue' does not match expected type 'Int'"}); + testCaseList.add(new Object[] {argumentWrongTypeCommand, argumentWrongType, "Entry 'intArg' with value 'stringValue' does not match expected type 'Int'"}); /** * option has wrong type @@ -223,7 +223,7 @@ private Object[] invalidCommandInput() { optionWrongType.addIntOption("intOption", 1); String optionWrongTypeCommand = "test-command --intOption=stringValue"; - testCaseList.add(new Object[] {optionWrongTypeCommand, optionWrongType, "Option 'intOption' with value 'stringValue' does not match expected type 'Int'"}); + testCaseList.add(new Object[] {optionWrongTypeCommand, optionWrongType, "Entry 'intOption' with value 'stringValue' does not match expected type 'Int'"}); return testCaseList.toArray(new Object[testCaseList.size()][]); } diff --git a/src/test/java/testhelper/CommandInputTestData.java b/src/test/java/testhelper/CommandInputTestData.java index 5a26bea..c84fb15 100644 --- a/src/test/java/testhelper/CommandInputTestData.java +++ b/src/test/java/testhelper/CommandInputTestData.java @@ -1,8 +1,6 @@ package testhelper; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.Assert.*; import java.util.AbstractMap; import java.util.ArrayList; @@ -13,6 +11,7 @@ import org.dsikkema.jamphony.jamphony.io.CommandInputDefinition; import org.dsikkema.jamphony.jamphony.io.InputData; +import org.dsikkema.jamphony.jamphony.io.InputException; import org.dsikkema.jamphony.jamphony.io.Type; public class CommandInputTestData { @@ -96,20 +95,20 @@ public CommandInputDefinition createInputDefinition() { return inputDefinition; } - public void verifyProcessedInputData(InputData input) { + public void verifyProcessedInputData(InputData inputData) { // verify args for (Map.Entry entry : this.arguments) { if (entry.getValue().getClass() == Integer.class) { assertEquals( String.format("Integer argument '%s' has the wrong value", entry.getKey()), entry.getValue(), - input.getIntArgument(entry.getKey()) + inputData.getArgument(entry.getKey()).getIntValue() ); } else { assertEquals( String.format("String argument '%s' has the wrong value", entry.getKey()), entry.getValue(), - input.getStringArgument(entry.getKey()) + inputData.getArgument(entry.getKey()).getStringValue() ); } } @@ -117,41 +116,41 @@ public void verifyProcessedInputData(InputData input) { assertEquals( "The wrong number of arguments was processed", this.arguments.size(), - input.getArguments().size() + inputData.getArguments().size() ); // verify options for (Map.Entry entry : this.stringOptions.entrySet()) { - assertEquals(entry.getValue(), input.getStringOption(entry.getKey())); + assertEquals(entry.getValue(), inputData.getOption(entry.getKey()).getStringValue()); } for (Map.Entry entry : this.intOptions.entrySet()) { - assertEquals(entry.getValue(), (Integer)input.getIntOption(entry.getKey())); + assertEquals(entry.getValue(), (Integer)inputData.getOption(entry.getKey()).getIntValue()); } assertEquals( "The wrong number of options was processed", this.intOptions.size() + this.stringOptions.size(), - input.getOptions().size() + inputData.getOptions().size() ); for (String option : this.optionsNotGiven.keySet()) { - assertFalse(input.isOptionProvided(option)); + assertFalse(inputData.isOptionProvided(option)); } // verify flags for (String flag : this.flags) { - assertTrue(input.isFlagSet(flag)); + assertTrue(inputData.isFlagSet(flag)); } assertEquals( "The wrong number of flags was processed", this.flags.size(), - input.getFlags().size() + inputData.getFlags().size() ); for (String flag : this.flagsNotGiven) { - assertFalse(input.isFlagSet(flag)); + assertFalse(inputData.isFlagSet(flag)); } } }