### Question:
ArgumentParser { public static Map<String, String> getArguments(String input, String pattern) { if (input == null || pattern == null) { return Collections.emptyMap(); } input = cutNotFullyEnteredToken(input); Map<String, String> arguments = Maps.newHashMap(); List<String> patternTokens = Parser.parsePattern(pattern); List<String> inputTokens = Parser.parseInput(input); while (!patternTokens.isEmpty() && !inputTokens.isEmpty()) { String patternPart = patternTokens.get(0); String inputPart = inputTokens.get(0); if (patternPart.startsWith((Character.toString(OPTIONAL_PART_BEGINNING))) && patternPart.endsWith((Character.toString(OPTIONAL_PART_ENDING)))) { arguments.putAll(parseOptional(inputTokens, getEntry(patternPart))); } else { if (patternPart.startsWith((Character.toString(MANDATORY_ARG_BEGINNING))) && patternPart.endsWith((Character.toString(MANDATORY_ARG_ENDING)))) { arguments.put(getEntry(patternPart), tryGetInputEntry(inputPart)); } else if (!patternPart.equals(inputPart)) { return Collections.emptyMap(); } inputTokens.remove(0); } patternTokens.remove(0); } return arguments; }  static Map<String, String> parseMap(String mapString, String description); static Map<String, Integer> parseStringIntegerMap(String mapString, String description); static ProgramIdArgument parseProgramId(String programId); static Map<String, String> getArguments(String input, String pattern);  }### Answer:
@Test public void basicTest1() { Map<String, String> expected = Maps.newHashMap(); expected.put("param1", "some input1"); expected.put("param2", "some input2"); expected.put("param3", "some input3"); String pattern = "test command <param1> and <param2> with <param3>"; String input = "test command \"some input1\" and 'some input2' with \"some input3\" "; Map<String, String> actual = ArgumentParser.getArguments(input, pattern); Assert.assertEquals(expected, actual); }
@Test public void basicTest2() { Map<String, String> expected = Maps.newHashMap(); expected.put("param1", "some input1"); String pattern = "test command <param1>"; String input = "test command \"some input1\" and 'some input2' "; Map<String, String> actual = ArgumentParser.getArguments(input, pattern); Assert.assertEquals(expected, actual); }
@Test public void testNotFullyEnteredLastParam() { Map<String, String> expected = Maps.newHashMap(); expected.put("param1", "input1"); expected.put("param2", "input2"); String pattern = "test command <param1> and <param2> with <param3>"; String input = "test command input1 and 'input2' with notFullyInput3"; Map<String, String> actual = ArgumentParser.getArguments(input, pattern); Assert.assertEquals(expected, actual); }
@Test public void testPatternDoNotMatchInput() { String pattern = "test command <param1> and <param2> with <param3>"; String input = "test command input1 and 'input 2' and with \"input 3\" "; Map<String, String> actual = ArgumentParser.getArguments(input, pattern); Assert.assertEquals(0, actual.size()); }