OperationParser { public CommandLineOperationParams parse(final Operation operation, final String[] args) { final CommandLineOperationParams params = new CommandLineOperationParams(args); final OperationEntry topLevelEntry = registry.getOperation(operation.getClass()); params.getOperationMap().put(topLevelEntry.getOperationNames()[0], operation); parseInternal(params, topLevelEntry); return params; } OperationParser(final OperationRegistry registry);  OperationParser(); CommandLineOperationParams parse(final Operation operation, final String[] args); CommandLineOperationParams parse(
      final Class<? extends Operation> topLevel,
      final String[] args); CommandLineOperationParams parse(final String[] args); Set<Object> getAdditionalObjects(); void addAdditionalObject(final Object obj); OperationRegistry getRegistry();  }
@Test public void testParseOperation() { final OperationEntry op1Entry = new OperationEntry(Op1.class); final OperationEntry op2Entry = new OperationEntry(Op2.class); op1Entry.addChild(op2Entry); final List<OperationEntry> entries = new ArrayList<>(); entries.add(op1Entry); entries.add(op2Entry); final OperationParser parser = new OperationParser(new OperationRegistry(entries)); final Op2 op2 = new Op2(); parser.parse(op2, new String[] {"--username", "user", "--password", "blah"}); Assert.assertEquals("blah", op2.args.passWord); Assert.assertEquals("user", op2.args.userName); }
@Test public void testParseTopLevel() { final OperationEntry op1Entry = new OperationEntry(Op1.class); final OperationEntry op2Entry = new OperationEntry(Op2.class); op1Entry.addChild(op2Entry); final List<OperationEntry> entries = new ArrayList<>(); entries.add(op1Entry); entries.add(op2Entry); final OperationParser parser = new OperationParser(new OperationRegistry(entries)); final CommandLineOperationParams params = parser.parse(Op1.class, new String[] {"op", "--username", "user", "--password", "blah"}); final Op2 op2 = (Op2) params.getOperationMap().get("op"); Assert.assertEquals("blah", op2.args.passWord); Assert.assertEquals("user", op2.args.userName); }