예제 #1
0
 private void assertIllegalParameter(Class<?> type) throws IntrospectionException {
   try {
     CommandFactory.DEFAULT.create(type);
     fail();
   } catch (IllegalParameterException e) {
   }
 }
예제 #2
0
  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);
  }
예제 #3
0
  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);
  }
예제 #4
0
  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);
  }
예제 #5
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());
 }
예제 #6
0
 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());
 }
예제 #7
0
 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());
 }
예제 #8
0
  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);
  }
예제 #9
0
  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);
  }
예제 #10
0
  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);
  }
예제 #11
0
  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);
  }
예제 #12
0
  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);
  }
예제 #13
0
  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);
  }