MediaType { public static MediaType from(String value) { Parser parser = new Parser(value); parser.parse(); return new MediaType(parser.expression(), parser.type, parser.subtype, parser.parameters); } private  MediaType(String value, String type, String subtype, Map<String, String> parameters); static MediaType from(String value); static boolean isJson(String mediaType); String getType(); String getSubtype(); String getSubtypeWithoutSuffix(); Map<String, String> getParameters(); Optional<String> getSuffix(); @Override String toString(); @Override boolean equals(Object o); @Override int hashCode();  }
@Test public void requiresNonEmptyString() { Assertions.assertThrows(RuntimeException.class, () -> MediaType.from("")); }
@Test public void requiresValidTypeToken() { Assertions.assertThrows(RuntimeException.class, () -> MediaType.from(",")); }
@Test public void requiresSubtype() { RuntimeException e = Assertions.assertThrows(RuntimeException.class, () -> MediaType.from("application")); assertThat(e.getMessage(), containsString("Expected: '/'")); }
@Test public void requiresSubtypeToken() { Assertions.assertThrows(RuntimeException.class, () -> MediaType.from("application/")); }
@Test public void requiresParametersAfterSemicolon() { Assertions.assertThrows(RuntimeException.class, () -> MediaType.from("application/json;")); }
@Test public void requiresValidParameterName() { Assertions.assertThrows(RuntimeException.class, () -> MediaType.from("application/json; \\")); }
@Test public void requiresEqualsAfterParameterName() { RuntimeException e = Assertions.assertThrows( RuntimeException.class, () -> MediaType.from("application/json; foo")); assertThat(e.getMessage(), containsString("Expected: '='")); }
@Test public void requiresParameterValueAfterEquals() { Assertions.assertThrows(RuntimeException.class, () -> MediaType.from("application/json; foo=")); }
@Test public void requiresParameterValueClosingQuote() { Assertions.assertThrows(RuntimeException.class, () -> MediaType.from("application/json; foo=\"baz")); }
@Test public void requiresParameterValueAfterOtherParamsAndSemicolon() { Assertions.assertThrows(RuntimeException.class, () -> MediaType.from("application/json; foo=\"baz\"; ")); }
@Test public void detectsInvalidQuotedEscapes() { RuntimeException e = Assertions.assertThrows( RuntimeException.class, () -> MediaType.from("application/json; foo=\"bar\\")); assertThat(e.getMessage(), containsString("Expected character after escape")); }