new Preference<Language>(Language.FRENCH_FRANCE, 0.9F));
ci.getAcceptedMediaTypes().add(
new Preference<MediaType>(MediaType.TEXT_XML, 1.0F));
List<Variant> variants = new ArrayList<Variant>();
variants.add(new Variant(MediaType.TEXT_XML, Language.ENGLISH_US));
variants.add(new Variant(MediaType.TEXT_XML, Language.FRENCH_FRANCE));
Variant pv = ci.getPreferredVariant(variants, ms);
assertEquals(MediaType.TEXT_XML, pv.getMediaType());
assertEquals(Language.ENGLISH_US, pv.getLanguages().get(0));
// Leveraging parent languages
variants.clear();
variants.add(new Variant(MediaType.TEXT_XML, Language.ENGLISH));
variants.add(new Variant(MediaType.TEXT_XML, Language.FRENCH));
pv = ci.getPreferredVariant(variants, ms);
assertEquals(MediaType.TEXT_XML, pv.getMediaType());
assertEquals(Language.ENGLISH, pv.getLanguages().get(0));
// Testing quality priority over parent metadata
variants.clear();
variants.add(new Variant(MediaType.TEXT_PLAIN, Language.ENGLISH));
variants.add(new Variant(MediaType.TEXT_XML, Language.FRENCH_FRANCE));
pv = ci.getPreferredVariant(variants, ms);
assertEquals(MediaType.TEXT_XML, pv.getMediaType());
assertEquals(Language.FRENCH_FRANCE, pv.getLanguages().get(0));
// Testing quality priority over parent metadata
variants.clear();
variants.add(new Variant(MediaType.APPLICATION_XML, Language.ENGLISH_US));
variants.add(new Variant(MediaType.TEXT_XML, Language.FRENCH_FRANCE));
pv = ci.getPreferredVariant(variants, ms);
assertEquals(MediaType.TEXT_XML, pv.getMediaType());
assertEquals(Language.FRENCH_FRANCE, pv.getLanguages().get(0));
// Leveraging parent media types
variants.clear();
variants.add(new Variant(MediaType.APPLICATION_XML, Language.ENGLISH_US));
variants.add(new Variant(MediaType.APPLICATION_XML,
Language.FRENCH_FRANCE));
pv = ci.getPreferredVariant(variants, ms);
assertEquals(MediaType.APPLICATION_XML, pv.getMediaType());
assertEquals(Language.ENGLISH_US, pv.getLanguages().get(0));
}