### Question:
JCommanderWrapper implements CommandBuilder<T> { public Optional<T> parse(String... args) { String[] expandedArgs = expand(args); try { root.commander.parse(expandedArgs); } catch (ParameterException e) { Optional.ofNullable(findCommander()).ifPresent(e::setJCommander); throw e; } JCommander commander = findCommander(); @SuppressWarnings("unchecked") T cmd = (T) getActiveCommand(commander); if (cmd != null) { validate(commander, expandedArgs); return Optional.of(cmd); } return Optional.empty(); } JCommanderWrapper(String programName, Object command); @Override JCommanderWrapper<T> configure(Consumer<? super CommandBuilder<T>> configurator); @Override JCommanderWrapper<T> addCommand(T command); @Override JCommanderWrapper<T> addCommand(String name, T command); @Override JCommanderWrapper<T> addGroup(T command, Consumer<? super CommandBuilder<T>> configurator); @Override JCommanderWrapper<T> addGroup(String name, T command, Consumer<? super CommandBuilder<T>> configurator); Optional<T> parse(String... args); static void handle(ParameterException exception, Consumer<? super String> sink);  }### Answer:
@Test public void simple() { JCommanderWrapper<Supplier<String>> commander = new JCommanderWrapper<>("PG", new Cmd("R")); Optional<String> result = commander.parse().map(Supplier::get); assertThat(result, is(Optional.of("R"))); }
@Test public void expand_dynamic() { JCommanderWrapper<Supplier<String>> commander = new JCommanderWrapper<>("PG", new Exp()); Optional<String> result = commander.parse("-ac", "-De=f").map(Supplier::get); assertThat(result, is(Optional.of("ace=f"))); }
@Test public void expand_main() { JCommanderWrapper<Supplier<String>> commander = new JCommanderWrapper<>("PG", new Exp()); Optional<String> result = commander.parse("-abc", "MAIN").map(Supplier::get); assertThat(result, is(Optional.of("abcMAIN"))); }
@Test public void expand_escape() { JCommanderWrapper<Supplier<String>> commander = new JCommanderWrapper<>("PG", new Exp()); Optional<String> result = commander.parse("-a", "--", "-bc").map(Supplier::get); assertThat(result, is(Optional.of("a-bc"))); }
@Test(expected = ParameterException.class) public void expand_fail() { JCommanderWrapper<Supplier<String>> commander = new JCommanderWrapper<>("PG", new ExpPrevent()); commander.parse("-aabb", "HELLO"); }