HeaderParameterParser { public Map<String, String> parse(String header) throws ParseException { init(header); Map<String, String> parameters = new HashMap<>(); pos++; while (hasRemainingChars()) { String name = readToken(NAME_TERMINATORS); String value = null; if (charAtIs(source, pos, '=')) { pos++; if (charAtIs(source, pos, '"')) { value = readQuotedString(); } else if (hasRemainingChars()) { value = readToken(VALUE_TERMINATORS); } } if (charAtIs(source, pos, PARAMS_SEPARATOR)) { pos++; } if (!isNullOrEmpty(name)) { parameters.put(name, value); } } return parameters; }  Map<String, String> parse(String header);  }
@UseDataProvider("forParses") @Test public void parses(String header, Map<String, String> expectedParsedParameters) throws Exception { assertEquals(expectedParsedParameters, headerParameterParser.parse(header)); }
@Test(expected = ParseException.class) public void throwsExceptionWhenStringContainsUnclosedQuote() throws Exception { headerParameterParser.parse("text/plain;foo=\"bar"); }
@Test(expected = ParseException.class) public void throwsExceptionWhenStringContainsIllegalCharacter() throws Exception { headerParameterParser.parse("text/plain;fo[o=\"bar\""); }