### Question:
HashRequestHeaders extends ReadOnlyParameters implements RequestHeaders { @Override public Optional<MediaType> bestAccepted(MediaType... mediaTypes) { if (mediaTypes == null || mediaTypes.length == 0) { return Optional.empty(); } List<MediaType> accepts = acceptedTypes(); if (accepts == null || accepts.isEmpty()) { return Optional.ofNullable(mediaTypes[0]); } double best = 0; MediaType result = null; for (MediaType mt : mediaTypes) { if (mt != null) { for (MediaType acc : accepts) { double q = acc.qualityFactor(); if (q > best && acc.test(mt)) { if (q == 1) { return Optional.of(mt); } else { best = q; result = mt; } } } } } return Optional.ofNullable(result); } HashRequestHeaders();   HashRequestHeaders(Map<String, List<String>> initialContent); @Override Optional<MediaType> contentType(); @Override OptionalLong contentLength(); @Override Parameters cookies(); @Override List<MediaType> acceptedTypes(); @Override boolean isAccepted(MediaType mediaType); @Override Optional<MediaType> bestAccepted(MediaType... mediaTypes); @Override Optional<ZonedDateTime> acceptDatetime(); @Override Optional<ZonedDateTime> date(); @Override Optional<ZonedDateTime> ifModifiedSince(); @Override Optional<ZonedDateTime> ifUnmodifiedSince(); @Override Optional<URI> referer();  }### Answer:
@Test public void bestAccepted() { HashRequestHeaders hs = withHeader(Http.Header.ACCEPT, "text/*;q=0.3, text/html;q=0.7, text/xml;q=0.4"); assertThat(hs.bestAccepted(MediaType.APPLICATION_JSON, MediaType.TEXT_PLAIN, null, MediaType.TEXT_XML).orElse(null), is(MediaType.TEXT_XML)); assertThat(hs.bestAccepted(MediaType.APPLICATION_JSON, MediaType.TEXT_HTML, MediaType.TEXT_XML).orElse(null), is(MediaType.TEXT_HTML)); assertThat(hs.bestAccepted(MediaType.APPLICATION_JSON, MediaType.TEXT_PLAIN).orElse(null), is(MediaType.TEXT_PLAIN)); assertThat(hs.bestAccepted(MediaType.APPLICATION_JSON).isPresent(), is(false)); assertThat(hs.bestAccepted().isPresent(), is(false)); }