CommandsJs { public static CommandsJs load() { Parser parser = new Parser(); try (BufferedReader r = new BufferedReader(new InputStreamReader(CommandsJs.class.getResourceAsStream(COMMANDS_JS), StandardCharsets.UTF_8))) { r.lines().forEach(parser::parseLine); } catch (IOException e) { throw new RuntimeException(e); } CommandsJs commandJs = new CommandsJs(); parser.getTargetTypes().forEach((key, value) -> { if (value instanceof Number && ((Number) value).intValue() == 0) commandJs.targetTypes.put(key, ""); else commandJs.targetTypes.put(key, (String) value); }); parser.getCommands().forEach(item -> { String key = (String) item.get(0); @SuppressWarnings("unchecked") Map<String, String> value = (Map<String, String>) item.get(1); switch (key) { case "assertConfirmation": case "assertPrompt": if (!value.containsKey("target")) value.put("target", "ArgTypes.alertText"); break; case "storeTitle": if (!value.containsKey("value")) value.put("value", "ArgTypes.variableName"); break; } commandJs.commands.put(key, value); }); return commandJs; } private  CommandsJs(); Map<String, String> getTargetTypes(); Map<String, Map<String, String>> getCommands(); static CommandsJs load(); @Override String toString();  }
@Test public void testLoad() { CommandsJs commandsJs = CommandsJs.load(); Map<String, String> targetTypes = commandsJs.getTargetTypes(); Map<String, Map<String, String>> commands = commandsJs.getCommands(); assertThat(targetTypes.get("NONE"), isEmptyString()); assertThat(targetTypes.get("LOCATOR"), is("locator")); assertThat(commands.get("addSelection").get("name"), is("add selection")); assertThat(commands.get("echo").get("description"), is("Prints the specified message into the third table cell in your Selenese tables. Useful for debugging.")); assertThat(commands.get("echo").get("target"), is("ArgTypes.message")); }