private void assertIllegalParameter(Class<?> type) throws IntrospectionException { try { CommandFactory.DEFAULT.create(type); fail(); } catch (IllegalParameterException e) { } }
public void testSatisfyAllMethodArgumentList() throws Exception { class A { @Command public void main(@Argument(name = "args") List<String> args) {} } CommandDescriptor<Instance<A>> cmd = CommandFactory.DEFAULT.create(A.class); // Tester<A> tester = new Tester<A>(cmd, "a", Mode.INVOKE); tester.assertArgument("args", "a"); tester.assertEnd(Event.Stop.Done.class, 1); // tester = new Tester<A>(cmd, "a ", Mode.INVOKE); tester.assertArgument("args", "a"); tester.assertSeparator(); tester.assertEnd(Event.Stop.Done.class, 2); // tester = new Tester<A>(cmd, "a b", Mode.INVOKE); tester.assertArgument("args", "a", "b"); tester.assertEnd(Event.Stop.Done.class, 3); // tester = new Tester<A>(cmd, "a b ", Mode.INVOKE); tester.assertArgument("args", "a", "b"); tester.assertSeparator(); tester.assertEnd(Event.Stop.Done.class, 4); }
public void testOptions2() throws Exception { class A { @Option(names = "o") String o; @Command public void main(@Option(names = "p") String p) {} } CommandDescriptor<Instance<A>> cmd = CommandFactory.DEFAULT.create(A.class); // Tester<A> tester = new Tester<A>(cmd, "-o"); tester.assertOption("o"); tester.assertEnd(Event.Stop.Done.class, 2); tester = new Tester<A>(cmd, "-o a"); tester.assertOption("o", "a"); tester.assertEnd(Event.Stop.Done.class, 4); tester = new Tester<A>(cmd, "-o a b"); tester.assertOption("o", "a"); tester.assertSeparator(); tester.assertEnd(Event.Stop.Unresolved.TooManyArguments.class, 5); // tester = new Tester<A>(cmd, "-p"); tester.assertOption("p"); tester.assertEnd(Event.Stop.Done.class, 2); tester = new Tester<A>(cmd, "-p a"); tester.assertOption("p", "a"); tester.assertEnd(Event.Stop.Done.class, 4); tester = new Tester<A>(cmd, "-p a b"); tester.assertOption("p", "a"); tester.assertSeparator(); tester.assertEnd(Event.Stop.Unresolved.TooManyArguments.class, 5); // tester = new Tester<A>(cmd, "-o a -p"); tester.assertOption("o", "a"); tester.assertSeparator(); tester.assertOption("p"); tester.assertEnd(Event.Stop.Done.class, 7); tester = new Tester<A>(cmd, "-o a -p b"); tester.assertOption("o", "a"); tester.assertSeparator(); tester.assertOption("p", "b"); tester.assertEnd(Event.Stop.Done.class, 9); // tester = new Tester<A>(cmd, "-o a -p"); tester.assertOption("o", "a"); tester.assertSeparator(); tester.assertOption("p"); tester.assertEnd(Event.Stop.Done.class, 7); tester = new Tester<A>(cmd, "-o a -p b"); tester.assertOption("o", "a"); tester.assertSeparator(); tester.assertOption("p", "b"); tester.assertEnd(Event.Stop.Done.class, 9); }
public void testUnkownClassOption() throws Exception { class A {} CommandDescriptor<Instance<A>> cmd = CommandFactory.DEFAULT.create(A.class); // Tester<A> tester = new Tester<A>(cmd, "-o"); tester.assertEnd(Event.Stop.Unresolved.NoSuchOption.class, 0); }
public void testOptionIntListType() throws IntrospectionException { class A { @Option(names = "o") List<Integer> o; } CommandDescriptor<A, ?> c = CommandFactory.DEFAULT.create(A.class); OptionDescriptor i = c.getOption("-o"); assertEquals(Multiplicity.MULTI, i.getMultiplicity()); assertEquals(ValueType.INTEGER, i.getType()); }
public void testOptionIntWrapperType() throws IntrospectionException { class A { @Option(names = "o") Integer o; } CommandDescriptor<A, ?> c = CommandFactory.DEFAULT.create(A.class); OptionDescriptor i = c.getOption("-o"); assertEquals(Multiplicity.SINGLE, i.getMultiplicity()); assertEquals(false, i.isRequired()); assertEquals(ValueType.INTEGER, i.getType()); }
public void testOptionEnumType() throws IntrospectionException { class A { @Option(names = "o") RetentionPolicy o; } CommandDescriptor<A, ?> c = CommandFactory.DEFAULT.create(A.class); OptionDescriptor i = c.getOption("-o"); assertEquals(Multiplicity.SINGLE, i.getMultiplicity()); assertEquals(false, i.isRequired()); assertEquals(ValueType.ENUM, i.getType()); }
public void testImplicitSubordinateOption() throws Exception { class A { @Command public void main(@Option(names = "o") String o) {} } CommandDescriptor<Instance<A>> cmd = CommandFactory.DEFAULT.create(A.class); // Tester<A> tester = new Tester<A>(cmd, "-o foo"); tester.assertOption("o", "foo"); tester.assertEnd(Event.Stop.Done.class, 6); }
public void testMixedMethodArguments() throws Exception { class A { @Command public void main( @Argument(name = "arg1") List<String> arg1, @Argument(name = "arg2") String arg2) {} } CommandDescriptor<Instance<A>> cmd = CommandFactory.DEFAULT.create(A.class); // Tester<A> tester = new Tester<A>(cmd, "a"); tester.assertArgument("arg1", "a"); tester.assertEnd(Event.Stop.Done.class, 1); // tester = new Tester<A>(cmd, "a b"); tester.assertArgument("arg1", "a", "b"); tester.assertEnd(Event.Stop.Done.class, 3); }
public void testMethodArgument() throws Exception { class A { @Command public void main(@Argument(name = "arg") String arg) {} } CommandDescriptor<Instance<A>> cmd = CommandFactory.DEFAULT.create(A.class); // Tester<A> tester = new Tester<A>(cmd, "a"); tester.assertArgument("arg", "a"); tester.assertEnd(Event.Stop.Done.class, 1); // tester = new Tester<A>(cmd, "a b"); tester.assertArgument("arg", "a"); tester.assertSeparator(); tester.assertEnd(Event.Stop.Unresolved.TooManyArguments.class, 2); }
public void testMethodOptionList() throws Exception { class A { @Command public void main(@Option(names = "o") List<String> o) {} } CommandDescriptor<Instance<A>> cmd = CommandFactory.DEFAULT.create(A.class); // Tester<A> tester = new Tester<A>(cmd, "-o"); tester.assertOption("o"); tester.assertEnd(Event.Stop.Done.class, 2); tester = new Tester<A>(cmd, "-o a"); tester.assertOption("o", "a"); tester.assertEnd(Event.Stop.Done.class, 4); tester = new Tester<A>(cmd, "-o a -o b"); tester.assertOption("o", "a"); tester.assertSeparator(); tester.assertOption("o", "b"); tester.assertEnd(Event.Stop.Done.class, 9); }
public void testSatisfyAllRequiredMethodArguments() throws Exception { class A { @Command public void main( @Required @Argument(name = "arg1") String arg1, @Required @Argument(name = "arg2") String arg2) {} } CommandDescriptor<Instance<A>> cmd = CommandFactory.DEFAULT.create(A.class); // Tester<A> tester = new Tester<A>(cmd, "a", Mode.INVOKE); tester.assertArgument("arg1", "a"); tester.assertEnd(Event.Stop.Done.class, 1); // tester = new Tester<A>(cmd, "a b"); tester.assertArgument("arg1", "a"); tester.assertSeparator(); tester.assertArgument("arg2", "b"); tester.assertEnd(Event.Stop.Done.class, 3); }
public void testSatisfyAllDoubleDash() throws Exception { class A { @Command public void main(@Option(names = "o") String o, @Argument(name = "arg") String arg) {} } CommandDescriptor<Instance<A>> cmd = CommandFactory.DEFAULT.create(A.class); // Tester<A> tester = new Tester<A>(cmd, "--", Mode.INVOKE); tester.assertEnd(Event.Stop.Done.class, 2); // tester = new Tester<A>(cmd, "-- ", Mode.INVOKE); tester.assertSeparator(); tester.assertEnd(Event.Stop.Done.class, 3); // tester = new Tester<A>(cmd, "-- foo", Mode.INVOKE); tester.assertSeparator(); tester.assertArgument("arg", "foo"); tester.assertEnd(Event.Stop.Done.class, 6); }