ContentTypeResolver { public static Set<ContentType> resolveConsumes(Element element) { return resolveConsumes(element, DEFAULT_FALLBACK); }  static Set<ContentType> resolveConsumes(Element element); static Set<ContentType> resolveConsumes(Element element, Set<ContentType> fallback); static Set<ContentType> resolveProduces(Element element); static Set<ContentType> resolveProduces(Element element, Set<ContentType> fallback);  }
@Test public void resolveConsumes_missing_defaultsToWildCard() { Element element = stubElementWithoutAnnotations(); Set<ContentType> contentTypes = ContentTypeResolver.resolveConsumes(element); assertThat(contentTypes).containsOnly(ContentType.valueOf(MediaType.WILDCARD)); }
@Test public void resolveConsumes_missing_defaultsToSpecifiedFallback() { Element element = stubElementWithoutAnnotations(); Set<ContentType> fallbacks = Sets.newHashSet( ContentType.valueOf("text/html"), ContentType.valueOf("application/json") ); Set<ContentType> contentTypes = ContentTypeResolver.resolveConsumes(element, fallbacks); assertThat(contentTypes).containsExactlyElementsOf(fallbacks); }
@Test public void resolveConsumes_multipleValues() { String type1 = "text/*"; String type2 = "application/*"; Consumes consumes = mock(Consumes.class); given(consumes.value()).willReturn(new String[]{type1, type2}); Element element = new AnnotatedElementBuilder(consumes).getElement(); Set<ContentType> contentTypes = ContentTypeResolver.resolveConsumes(element); assertThat(contentTypes).containsOnly(ContentType.valueOf(type1), ContentType.valueOf(type2)); }
@Test public void resolveConsumes_multipleValuesWithinMultipleValues() { String type1 = "text/*;q=0.1"; String type2 = "application/*;q=0.6"; String type3 = "audio/*;q=0.8"; Consumes consumes = mock(Consumes.class); given(consumes.value()).willReturn(new String[]{type1, type2 + "," + type3}); Element element = new AnnotatedElementBuilder(consumes).getElement(); Set<ContentType> contentTypes = ContentTypeResolver.resolveConsumes(element); assertThat(contentTypes).containsOnly( ContentType.valueOf(type1), ContentType.valueOf(type2), ContentType.valueOf(type3) ); }