CommandLineParser { public Map<String, String> extractExtraArgs(String argument) throws IllegalArgumentException { final Map<String, String> extraArgData = new HashMap<>(); argument = argument.trim().substring(1, argument.length() - 1); if (argument.indexOf("{") > -1 || argument.indexOf("}") > -1) { if (debug) { System.err.println("Found invalid nested data"); } throw new IllegalArgumentException("Nested JSON athuments not supprted"); } final String[] pairs = argument.split(entrySeparator); for (String pair : pairs) { String[] values = pair.split(keyValueSeparator); if (debug) { System.err.println("Collecting: " + pair); } extraArgData.put(values[0].trim(), values[1].trim()); } return extraArgData; }  boolean isDebug(); void setDebug(boolean debug); String[] getArguments(); Set<String> getFlags(); String getFlagValue(String flagName); int getNumberOfArguments(); int getNumberOfFlags(); boolean hasFlag(String flagName); void parse(String[] args); void saveFlagValue(String flagName); Map<String, String> extractExtraArgs(String argument);  }
@Test public void extractExtraArgsTest() { final String[] argsArray = new String[] { "-a", "{count:0, type: navigate, size:100.1, flag:true}" }; commandLineParser.saveFlagValue("a"); commandLineParser.parse(argsArray); assertThat(commandLineParser.getFlagValue("a"), notNullValue()); assertThat( commandLineParser.extractExtraArgs(commandLineParser.getFlagValue("a")), notNullValue()); final Map<String, String> extraArgData = commandLineParser .extractExtraArgs(commandLineParser.getFlagValue("a")); assertThat(extraArgData.containsKey("count"), is(true)); assertThat(extraArgData.containsKey("type"), is(true)); assertThat(extraArgData.containsKey("size"), is(true)); assertThat(extraArgData.containsKey("flag"), is(true)); assertThat(extraArgData.containsKey("missing"), is(false)); }