### Question:
Parser { public ParsedOutput parse(List<String> args) { final Command commandName = this.findCommand(args); fillShortAndLongOptions(commandName); final Map<CommandFlag, Object> options = this.findOptions(args); return new ParsedOutput(commandName, args, options); } Parser(final Map<Command, ? extends Collection<CommandFlag>> commandToFlags); ParsedOutput parse(List<String> args);  }### Answer:
@Test void testEmptyArgumentsIsEmpty() { ParsedOutput output = testParser.parse(new ArrayList<>(List.of("log"))); Assertions.assertEquals(output.getOptions().size(), 0); Assertions.assertEquals(output.getArguments().size(), 0); }
@Test void testOneArgument() { ParsedOutput output = testParser.parse(new ArrayList<>(List.of("log", "foo"))); Assertions.assertEquals(output.getOptions().size(), 0); Assertions.assertEquals(output.getArguments().size(), 1); Assertions.assertEquals(output.getArguments().get(0), "foo"); }
@Test void testOneBoolOpt() { ParsedOutput output = testParser.parse(new ArrayList<>(List.of("up", "--update"))); Assertions.assertEquals(output.getOptions().size(), 1); Assertions.assertEquals(output.getArguments().size(), 0); Assertions.assertEquals(output.getOptions().get(flagTwo), true); }
@Test void testOneStrOpt() { ParsedOutput output = testParser.parse(new ArrayList<>(List.of("sync", "--user", "disparse"))); Assertions.assertEquals(output.getOptions().size(), 1); Assertions.assertEquals(output.getArguments().size(), 0); Assertions.assertEquals(output.getOptions().get(flagFive), "disparse"); }
@Test void testNoFlagForCommand() { ParsedOutput output = testParser.parse(new ArrayList<>(List.of("init", "--read-only"))); Assertions.assertEquals(output.getOptions().size(), 0); Assertions.assertEquals(output.getArguments().size(), 1); Assertions.assertEquals(output.getArguments().get(0), "--read-only"); }
@Test void testNoCommandFound() { assertThrows( NoCommandNameFound.class, () -> { ParsedOutput output = testParser.parse(new ArrayList<>(List.of("--update"))); }); }
@Test void testNoValueProvidedForStrOpt() { assertThrows( OptionRequiresValue.class, () -> { ParsedOutput output = testParser.parse(new ArrayList<>(List.of("sync", "--user"))); }); }
@Test void testListOptMultipleValues() { ParsedOutput output = testParser.parse( new ArrayList<>( List.of("init", "--create", "foo", "--create", "bar", "--create", "baz"))); Assertions.assertEquals(output.getOptions().size(), 1); Assertions.assertEquals(output.getArguments().size(), 0); Assertions.assertEquals(output.getOptions().get(flagOne), List.of("foo", "bar", "baz")); }
@Test void testListOptWithShortAndLongNames() { ParsedOutput output = testParser.parse( new ArrayList<>(List.of("init", "-c", "foo", "--create", "bar", "-c", "baz"))); Assertions.assertEquals(output.getOptions().size(), 1); Assertions.assertEquals(output.getArguments().size(), 0); Assertions.assertEquals(output.getOptions().get(flagOne), List.of("foo", "bar", "baz")); }