### Question:
ArgumentsParser { List<String> parse(String args) { if (args == null || "null".equals(args) || args.isEmpty()) { return Collections.emptyList(); } final List<String> arguments = new LinkedList<>(); final StringBuilder argumentBuilder = new StringBuilder(); Character quote = null; for (int i = 0, l = args.length(); i < l; i++) { char c = args.charAt(i); if (Character.isWhitespace(c) && quote == null) { addArgument(argumentBuilder, arguments); continue; } else if (c == '"' || c == '\'') { Character currentQuote = Character.valueOf(c); if (quote == null) { quote = currentQuote; } else if (quote.equals(currentQuote)){ quote = null; } } argumentBuilder.append(c); } addArgument(argumentBuilder, arguments); for (String argument : this.additionalArguments) { addArgument(argument, arguments); } return new ArrayList<>(arguments); } ArgumentsParser();   ArgumentsParser(List<String> additionalArguments);   }### Answer:
@Test public void testNoArguments() { ArgumentsParser parser = new ArgumentsParser(); assertEquals(0, parser.parse(null).size()); assertEquals(0, parser.parse("null").size()); assertEquals(0, parser.parse(String.valueOf("")).size()); }
@Test public void testMultipleArgumentsNoQuotes() { ArgumentsParser parser = new ArgumentsParser(); assertArrayEquals(new Object[] { "foo" }, parser.parse("foo").toArray()); assertArrayEquals(new Object[] { "foo", "bar" }, parser.parse("foo bar").toArray()); assertArrayEquals(new Object[] { "foo", "bar", "foobar" }, parser.parse("foo bar foobar").toArray()); }
@Test public void testMultipleArgumentsWithQuotes() { ArgumentsParser parser = new ArgumentsParser(); assertArrayEquals(new Object[] { "foo", "\"bar foobar\"" }, parser.parse("foo \"bar foobar\"").toArray()); assertArrayEquals(new Object[] { "\"foo bar\"", "foobar" }, parser.parse("\"foo bar\" foobar").toArray()); assertArrayEquals(new Object[] { "foo", "'bar foobar'" }, parser.parse("foo 'bar foobar'").toArray()); assertArrayEquals(new Object[] { "'foo bar'", "foobar" }, parser.parse("'foo bar' foobar").toArray()); assertArrayEquals(new Object[] { "foo", "\"bar foobar" }, parser.parse("foo \"bar foobar").toArray()); }
@Test public void testArgumentsWithMixedQuotes() { ArgumentsParser parser = new ArgumentsParser(); assertArrayEquals(new Object[] { "foo", "\"bar 'foo bar'\"" }, parser.parse("foo \"bar 'foo bar'\"").toArray()); assertArrayEquals(new Object[] { "foo", "\"bar 'foo\"", "'bar " }, parser.parse("foo \"bar 'foo\" 'bar ").toArray()); }
@Test public void testAdditionalArgumentsNoIntersection() { ArgumentsParser parser = new ArgumentsParser(Arrays.asList("foo", "bar")); assertArrayEquals(new Object[] { "foobar", "foo", "bar" }, parser.parse("foobar").toArray()); }
@Test public void testAdditionalArgumentsWithIntersection() { ArgumentsParser parser = new ArgumentsParser(Arrays.asList("foo", "foobar")); assertArrayEquals(new Object[] { "bar", "foobar", "foo" }, parser.parse("bar foobar").toArray()); }