public void testParse_empty() { try { MediaType.parse(""); fail(); } catch (IllegalArgumentException expected) { } }
public void testWithParameter() { assertEquals( MediaType.parse("text/plain; a=1"), MediaType.parse("text/plain").withParameter("a", "1")); assertEquals( MediaType.parse("text/plain; a=1"), MediaType.parse("text/plain; a=1; a=2").withParameter("a", "1")); assertEquals( MediaType.parse("text/plain; a=3"), MediaType.parse("text/plain; a=1; a=2").withParameter("a", "3")); assertEquals( MediaType.parse("text/plain; a=1; a=2; b=3"), MediaType.parse("text/plain; a=1; a=2").withParameter("b", "3")); }
public void testWithParametersIterable() { assertEquals( MediaType.parse("text/plain"), MediaType.parse("text/plain; a=1; a=2").withParameters("a", ImmutableSet.<String>of())); assertEquals( MediaType.parse("text/plain; a=1"), MediaType.parse("text/plain").withParameters("a", ImmutableSet.of("1"))); assertEquals( MediaType.parse("text/plain; a=1"), MediaType.parse("text/plain; a=1; a=2").withParameters("a", ImmutableSet.of("1"))); assertEquals( MediaType.parse("text/plain; a=1; a=3"), MediaType.parse("text/plain; a=1; a=2").withParameters("a", ImmutableSet.of("1", "3"))); assertEquals( MediaType.parse("text/plain; a=1; a=2; b=3; b=4"), MediaType.parse("text/plain; a=1; a=2").withParameters("b", ImmutableSet.of("3", "4"))); }
public void testWithParametersIterable_invalidAttribute() { MediaType mediaType = MediaType.parse("text/plain"); try { mediaType.withParameters("@", ImmutableSet.of("2")); fail(); } catch (IllegalArgumentException expected) { } }
public void testWithParametersIterable_nullValue() { MediaType mediaType = MediaType.parse("text/plain"); try { mediaType.withParameters("a", Arrays.asList((String) null)); fail(); } catch (NullPointerException expected) { } }
public void testWithParameter_invalidAttribute() { MediaType mediaType = MediaType.parse("text/plain"); try { mediaType.withParameter("@", "2"); fail(); } catch (IllegalArgumentException expected) { } }
public void testGetCharset_illegalCharset() { MediaType mediaType = MediaType.parse("text/plain; charset=\"!@#$%^&*()\""); try { mediaType.charset(); fail(); } catch (IllegalCharsetNameException expected) { } }
public void testGetCharset_unsupportedCharset() { MediaType mediaType = MediaType.parse("text/plain; charset=utf-wtf"); try { mediaType.charset(); fail(); } catch (UnsupportedCharsetException expected) { } }
public void testGetCharset_tooMany() { MediaType mediaType = MediaType.parse("text/plain; charset=utf-8; charset=utf-16"); try { mediaType.charset(); fail(); } catch (IllegalStateException expected) { } }
@GwtIncompatible // Non-UTF-8 Charset public void testGetCharset_utf16() { assertThat(MediaType.parse("text/plain; charset=utf-16").charset()).hasValue(UTF_16); }
public void testGetParameters() { assertEquals(ImmutableListMultimap.of(), MediaType.parse("text/plain").parameters()); assertEquals( ImmutableListMultimap.of("charset", "utf-8"), MediaType.parse("application/atom+xml; charset=utf-8").parameters()); assertEquals(PARAMETERS, MediaType.parse("application/atom+xml; a=1; a=2; b=3").parameters()); }
public void testWithParameters_invalidAttribute() { MediaType mediaType = MediaType.parse("text/plain"); ImmutableListMultimap<String, String> parameters = ImmutableListMultimap.of("a", "1", "@", "2", "b", "3"); try { mediaType.withParameters(parameters); fail(); } catch (IllegalArgumentException expected) { } }
@GwtIncompatible // reflection public void testParse_useConstants() throws Exception { for (MediaType constant : getConstants()) { assertSame(constant, MediaType.parse(constant.toString())); } }
@GwtIncompatible // com.google.common.testing.NullPointerTester public void testNullPointer() { NullPointerTester tester = new NullPointerTester(); tester.testAllPublicConstructors(MediaType.class); tester.testAllPublicStaticMethods(MediaType.class); tester.testAllPublicInstanceMethods(MediaType.parse("text/plain")); }