### Question:
MediaType { public Charset charsetOrDefault(Charset defaultCharset) { requireNonNull(defaultCharset); try { return charset().orElse(defaultCharset); } catch (UnsupportedCharsetException ignored) { return defaultCharset; } } private  MediaType(String type, String subtype); private  MediaType(String type, String subtype, Map<String, String> parameters); String type(); String subtype(); Map<String, String> parameters(); Optional<Charset> charset(); Charset charsetOrDefault(Charset defaultCharset); boolean hasWildcard(); boolean includes(MediaType other); boolean isCompatibleWith(MediaType other); MediaType withCharset(Charset charset); MediaType withParameter(String name, String value); MediaType withParameters(Map<String, String> parameters); @Override boolean equals(@Nullable Object obj); @Override int hashCode(); @Override String toString(); static MediaType of(String type, String subtype); static MediaType of(String type, String subtype, Map<String, String> parameters); static MediaType parse(String value); static final MediaType ANY; static final MediaType APPLICATION_ANY; static final MediaType IMAGE_ANY; static final MediaType TEXT_ANY; static final MediaType APPLICATION_FORM_URLENCODED; static final MediaType APPLICATION_JSON; static final MediaType APPLICATION_OCTET_STREAM; static final MediaType APPLICATION_XHTML_XML; static final MediaType APPLICATION_XML; static final MediaType APPLICATION_X_PROTOBUF; static final MediaType IMAGE_GIF; static final MediaType IMAGE_JPEG; static final MediaType IMAGE_PNG; static final MediaType TEXT_HTML; static final MediaType TEXT_MARKDOWN; static final MediaType TEXT_PLAIN; static final MediaType TEXT_XML; }### Answer:
@Test void charsetOrDefault() { var textPlain = MediaType.of("text", "plain"); var textPlainAscii = textPlain.withCharset(US_ASCII); assertEquals(textPlain.charsetOrDefault(UTF_8), UTF_8); assertEquals(textPlainAscii.charsetOrDefault(UTF_8), US_ASCII); }