@Test
public void selectsVariant() throws Exception {

    List<Variant> variantList = Variant.mediaTypes(MediaType.valueOf("image/jpeg")).add()
                                       .mediaTypes(MediaType.valueOf("text/xml")).languages(new Locale("en", "gb")).add()
                                       .mediaTypes(MediaType.valueOf("text/xml;charset=utf-8")).languages(new Locale("en", "us")).add()
                                       .mediaTypes(MediaType.valueOf("text/xml;charset=utf-8")).languages(new Locale("en", "us")).encodings("gzip").add()
                                       .build();
    MultivaluedMap<String, String> headers = new MultivaluedMapImpl();
    headers.putSingle(ACCEPT, Joiner.on(',').join("text/xml", "image/png", "text/html;q=0.9", "text/plain;q=0.8", "application/xml", "*/*;q=0.5"));
    headers.putSingle(ACCEPT_LANGUAGE, "en-us,en;q=0.5");
    headers.putSingle(ACCEPT_CHARSET, "utf-8,koi8;q=0.7");
    headers.putSingle(ACCEPT_ENCODING, "gzip");
    ContainerRequest request = new ContainerRequest("GET", null, null, null, headers, null);
    Variant variant = variantsHandler.handleVariants(request, variantList);
    assertNotNull(variant);
    assertEquals(new MediaType("text", "xml", ImmutableMap.of("charset", "utf-8")), variant.getMediaType());
    assertEquals(new Locale("en", "us"), variant.getLanguage());
    assertEquals("gzip", variant.getEncoding());
}