MediaType mediaType = MediaType.valueOf("text/plain");
String encoding = "gzip";
Locale locale = Locale.UK;
List<Variant> available = new ArrayList<Variant>();
available.add(new Variant(mediaTypeWithCharset, null, null));
available.add(new Variant(mediaTypeWithCharset, locale, null));
available.add(new Variant(mediaTypeWithCharset, null, encoding));
available.add(new Variant(mediaTypeWithCharset, locale, encoding));
available.add(new Variant(mediaType, null, null));
available.add(new Variant(mediaType, locale, null));
available.add(new Variant(mediaType, 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(null, 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());
}