@Test public void testCommandProcessor() throws ParseException { final List<String> results = new ArrayList<>(); results.add("foo1"); results.add("foo2"); final CommandA command = new CommandA(results); final Context context = Mockito.mock(Context.class); Mockito.when(context.getOutput()).thenReturn(System.out); final CommandProcessor processor = new CommandProcessor(Collections.emptyMap(), Collections.emptyMap(), context); processor.processCommand(new String[] {}, command); processor.processCommand( new String[] { "-" + CommandOption.BUCKET_ID.getShortName(), "&1" } , command); final CommandLine cli1 = command.getCli(); Assert.assertEquals("foo1", cli1.getOptionValue(CommandOption.BUCKET_ID.getShortName())); processor.processCommand( new String[] { "-" + CommandOption.BUCKET_ID.getShortName(), "&2" }, command); final CommandLine cli2 = command.getCli(); Assert.assertEquals("foo2", cli2.getOptionValue(CommandOption.BUCKET_ID.getShortName())); processor.processCommand( new String[] { "-" + CommandOption.BUCKET_ID.getShortName(), "b1", "-" + CommandOption.FLOW_ID.getShortName(), "&1" }, command); final CommandLine cli3 = command.getCli(); Assert.assertEquals("foo1", cli3.getOptionValue(CommandOption.FLOW_ID.getShortName())); }
public CommandProcessor(final Map<String,Command> topLevelCommands, final Map<String,CommandGroup> commandGroups, final Context context) { this.topLevelCommands = topLevelCommands; this.commandGroups = commandGroups; this.context = context; this.out = context.getOutput(); Validate.notNull(this.topLevelCommands); Validate.notNull(this.commandGroups); Validate.notNull(this.context); Validate.notNull(this.out); }
CommandProcessor { public CommandProcessor(final Map<String,Command> topLevelCommands, final Map<String,CommandGroup> commandGroups, final Context context) { this.topLevelCommands = topLevelCommands; this.commandGroups = commandGroups; this.context = context; this.out = context.getOutput(); Validate.notNull(this.topLevelCommands); Validate.notNull(this.commandGroups); Validate.notNull(this.context); Validate.notNull(this.out); } }
CommandProcessor { public CommandProcessor(final Map<String,Command> topLevelCommands, final Map<String,CommandGroup> commandGroups, final Context context) { this.topLevelCommands = topLevelCommands; this.commandGroups = commandGroups; this.context = context; this.out = context.getOutput(); Validate.notNull(this.topLevelCommands); Validate.notNull(this.commandGroups); Validate.notNull(this.context); Validate.notNull(this.out); } CommandProcessor(final Map<String,Command> topLevelCommands, final Map<String,CommandGroup> commandGroups, final Context context); }
CommandProcessor { public CommandProcessor(final Map<String,Command> topLevelCommands, final Map<String,CommandGroup> commandGroups, final Context context) { this.topLevelCommands = topLevelCommands; this.commandGroups = commandGroups; this.context = context; this.out = context.getOutput(); Validate.notNull(this.topLevelCommands); Validate.notNull(this.commandGroups); Validate.notNull(this.context); Validate.notNull(this.out); } CommandProcessor(final Map<String,Command> topLevelCommands, final Map<String,CommandGroup> commandGroups, final Context context); void printBasicUsage(String errorMessage); void printBasicUsage(String errorMessage, boolean verbose); int process(String[] args); }
CommandProcessor { public CommandProcessor(final Map<String,Command> topLevelCommands, final Map<String,CommandGroup> commandGroups, final Context context) { this.topLevelCommands = topLevelCommands; this.commandGroups = commandGroups; this.context = context; this.out = context.getOutput(); Validate.notNull(this.topLevelCommands); Validate.notNull(this.commandGroups); Validate.notNull(this.context); Validate.notNull(this.out); } CommandProcessor(final Map<String,Command> topLevelCommands, final Map<String,CommandGroup> commandGroups, final Context context); void printBasicUsage(String errorMessage); void printBasicUsage(String errorMessage, boolean verbose); int process(String[] args); static final String BACK_REF_INDICATOR; }