ShellCommandParser { public static Result parse(String line) throws IntrospectionException, InvalidOptionException { return parse(line, Collections.emptyList()); } private  ShellCommandParser(); static String[] split(String line); static Result parse(String line); static Result parse(String line,
            Collection<Class<? extends Command>> excluded); static Result parse(String[] args,
            Collection<Class<? extends Command>> excluded);  }
@Test public void commands() throws Exception { Result pr = ShellCommandParser.parse("bibliography"); assertEquals(0, pr.getRemainingArgs().length); assertEquals(BibliographyCommand.class, pr.getFirstCommand()); assertEquals(BibliographyCommand.class, pr.getLastCommand()); pr = ShellCommandParser.parse(" list "); assertEquals(0, pr.getRemainingArgs().length); assertEquals(ListCommand.class, pr.getFirstCommand()); }
@Test public void subcommands() throws Exception { Result pr = ShellCommandParser.parse("get style"); assertEquals(0, pr.getRemainingArgs().length); assertEquals(ShellGetCommand.class, pr.getFirstCommand()); assertEquals(ShellGetStyleCommand.class, pr.getLastCommand()); pr = ShellCommandParser.parse(" get style "); assertEquals(0, pr.getRemainingArgs().length); assertEquals(ShellGetCommand.class, pr.getFirstCommand()); assertEquals(ShellGetStyleCommand.class, pr.getLastCommand()); }
@Test public void incomplete() throws Exception { Result pr = ShellCommandParser.parse(""); assertEquals(1, pr.getRemainingArgs().length); assertEquals("", pr.getRemainingArgs()[0]); assertNull(pr.getFirstCommand()); assertNull(pr.getLastCommand()); pr = ShellCommandParser.parse("bibl"); assertEquals(1, pr.getRemainingArgs().length); assertEquals("bibl", pr.getRemainingArgs()[0]); assertNull(pr.getFirstCommand()); assertNull(pr.getLastCommand()); pr = ShellCommandParser.parse("get s"); assertEquals(1, pr.getRemainingArgs().length); assertEquals("s", pr.getRemainingArgs()[0]); assertEquals(ShellGetCommand.class, pr.getFirstCommand()); assertEquals(ShellGetCommand.class, pr.getLastCommand()); }
@Test public void excluded() throws Exception { Result pr = ShellCommandParser.parse("shell"); assertEquals(0, pr.getRemainingArgs().length); assertEquals(ShellCommand.class, pr.getFirstCommand()); List<Class<? extends Command>> excluded = new ArrayList<>(); excluded.add(ShellCommand.class); pr = ShellCommandParser.parse("bibliography", excluded); assertEquals(0, pr.getRemainingArgs().length); assertEquals(BibliographyCommand.class, pr.getFirstCommand()); pr = ShellCommandParser.parse("shell", excluded); assertEquals(1, pr.getRemainingArgs().length); assertEquals("shell", pr.getRemainingArgs()[0]); assertNull(pr.getFirstCommand()); assertNull(pr.getLastCommand()); }