### Question:
CLIMainArgs { public static CLIMainArgs parse(String[] args, Options options) { List<String> optionsPart = Lists.newArrayList(); List<String> commandPart = Lists.newArrayList(); boolean inOptionsPart = true; for (int i = 0; i < args.length; i++) { String token = args[i]; if (inOptionsPart) { if (!token.startsWith("-")) { inOptionsPart = false; } else if (!options.hasOption(token)) { inOptionsPart = true; } else if (!options.getOption(token).hasArg()) { inOptionsPart = true; } else if (options.getOption(token).hasArg() && i + 1 < args.length) { inOptionsPart = true; optionsPart.add(token); optionsPart.add(args[++i]); continue; } else { inOptionsPart = false; } } if (inOptionsPart) { optionsPart.add(token); } else { commandPart.add(token); } } return new CLIMainArgs(optionsPart.toArray(new String[optionsPart.size()]), commandPart.toArray(new String[commandPart.size()])); } CLIMainArgs(String[] optionTokens, String[] commandTokens); String[] getOptionTokens(); String[] getCommandTokens(); @Override int hashCode(); @Override boolean equals(Object obj); @Override String toString(); static CLIMainArgs parse(String[] args, Options options);  }### Answer:
@Test public void testParse() { String noArgFlag = "-" + CLIMain.HELP_OPTION.getOpt(); String withArgFlag = "-" + CLIMain.AUTOCONNECT_OPTION.getOpt(); Assert.assertEquals(true, CLIMain.AUTOCONNECT_OPTION.hasArg()); Assert.assertEquals( new CLIMainArgs(new String[] {}, new String[] {"hello", "world"}), CLIMainArgs.parse(new String[]{"hello", "world"}, CLIMain.getOptions())); Assert.assertEquals( new CLIMainArgs(new String[] {noArgFlag}, new String[] {"hello", "world"}), CLIMainArgs.parse(new String[]{noArgFlag, "hello", "world"}, CLIMain.getOptions())); Assert.assertEquals( new CLIMainArgs(new String[] {}, new String[] {"hello", noArgFlag, "world"}), CLIMainArgs.parse(new String[]{"hello", noArgFlag, "world"}, CLIMain.getOptions())); Assert.assertEquals( new CLIMainArgs(new String[] {}, new String[] {"hello", "world", noArgFlag}), CLIMainArgs.parse(new String[]{"hello", "world", noArgFlag}, CLIMain.getOptions())); Assert.assertEquals( new CLIMainArgs(new String[] {withArgFlag, "somevalue"}, new String[] {"hello", "world"}), CLIMainArgs.parse(new String[]{withArgFlag, "somevalue", "hello", "world"}, CLIMain.getOptions())); Assert.assertEquals( new CLIMainArgs(new String[] {}, new String[] {"hello", withArgFlag, "world"}), CLIMainArgs.parse(new String[]{"hello", withArgFlag, "world"}, CLIMain.getOptions())); Assert.assertEquals( new CLIMainArgs(new String[] {}, new String[] {"hello", "world", withArgFlag}), CLIMainArgs.parse(new String[]{"hello", "world", withArgFlag}, CLIMain.getOptions())); Assert.assertEquals( new CLIMainArgs(new String[] {"--sdflkjsdlkfjsjdlf"}, new String[] {}), CLIMainArgs.parse(new String[]{"--sdflkjsdlkfjsjdlf"}, CLIMain.getOptions())); }