AbstractRenderer implements ODataRenderer { protected int scoreByMediaType(List<MediaType> mediaTypes, MediaType requiredMediaType) { int score = MAXIMUM_HEADER_SCORE; boolean match = false; boolean matchWildCard = false; for (MediaType mediaType : mediaTypes) { if (mediaType.matches(requiredMediaType)) { if (mediaType.isWildCardMediaType()) { matchWildCard = true; } match = true; break; } score -= 2; } return match && !matchWildCard ? score : matchWildCard ? WILDCARD_MATCH_SCORE : DEFAULT_SCORE; }  @Override ChunkedActionRenderResult renderStart(ODataRequestContext requestContext, QueryResult result,
                                                 OutputStream outputStream); @Override ChunkedActionRenderResult renderBody(ODataRequestContext requestContext, QueryResult result,
                                                ChunkedActionRenderResult previousResult); @Override void renderEnd(ODataRequestContext requestContext, QueryResult result,
                          ChunkedActionRenderResult previousResult); static final int WILDCARD_MATCH_SCORE; static final int DEFAULT_SCORE; static final int CONTENT_TYPE_HEADER; static final int MAXIMUM_FORMAT_SCORE; static final int MAXIMUM_HEADER_SCORE; static final int DELETE_LINK_SCORE; static final int ERROR_EXTRA_SCORE; static final int PRIORITY_SCORE; }
@Test public void testScoreByMediaType() { assertThat(renderer.scoreByMediaType(Arrays.asList( new MediaType("text", "html"), new MediaType("application", "xml", ImmutableMap.of("q", "0.8")), new MediaType("*", "*", ImmutableMap.of("q", "0.1")) ), XML), is(MAXIMUM_HEADER_SCORE - 2)); assertThat(renderer.scoreByMediaType(Arrays.asList( new MediaType("text", "html"), new MediaType("application", "json", ImmutableMap.of("q", "0.8")), new MediaType("*", "*", ImmutableMap.of("q", "0.8")) ), XML), CoreMatchers.is(AbstractRenderer.WILDCARD_MATCH_SCORE)); assertThat(renderer.scoreByMediaType(Arrays.asList( new MediaType("text", "html"), new MediaType("application", "xml", ImmutableMap.of("q", "0.8")), new MediaType("*", "*", ImmutableMap.of("q", "0.8")) ), JSON), CoreMatchers.is(AbstractRenderer.WILDCARD_MATCH_SCORE)); assertThat(renderer.scoreByMediaType( Collections.singletonList(ATOM_XML), ATOM_XML), is(MAXIMUM_HEADER_SCORE)); assertThat(renderer.scoreByMediaType( Collections.<MediaType>emptyList(), JSON), is(DEFAULT_SCORE)); }