{
@Test
public void mostSpecific()
{
ServerDrivenNegotiation negotiation = new ServerDrivenNegotiation();
negotiation.setAcceptHeaders(Arrays.asList("text/plain"));
negotiation.setAcceptCharsetHeaders(Arrays.asList("UTF-8"));
negotiation.setAcceptEncodingHeaders(Arrays.asList("gzip"));
negotiation.setAcceptLanguageHeaders(Arrays.asList("en-gb"));
MediaType mediaTypeWithCharset = MediaType.valueOf("text/plain; charset=UTF-8");
MediaType mediaType = MediaType.valueOf("text/plain");
String encoding = "gzip";
Locale locale = Locale.UK;
List<Variant> available = new ArrayList<Variant>();
available.add(new Variant(mediaTypeWithCharset, (String)null, (String)null));
available.add(new Variant(mediaTypeWithCharset, locale, null));
available.add(new Variant(mediaTypeWithCharset, (String)null, encoding));
available.add(new Variant(mediaTypeWithCharset, locale, encoding));
available.add(new Variant(mediaType, (String)null, (String)null));
available.add(new Variant(mediaType, locale, null));
available.add(new Variant(mediaType, (String)null, encoding));
available.add(new Variant(mediaType, locale, encoding));
available.add(new Variant(null, locale, null));
available.add(new Variant(null, locale, encoding));
available.add(new Variant((MediaType)null,(String)null, encoding));
// Assert all acceptable:
for (Variant variant : available)
assertEquals(variant, negotiation.getBestMatch(Arrays.asList(variant)));
Variant best = negotiation.getBestMatch(available);
assertNotNull(best);
assertEquals(mediaTypeWithCharset, best.getMediaType());
assertEquals(encoding, best.getEncoding());
assertEquals(locale, best.getLanguage());
}