@Test
public void testCharsetDetectionWithShortSnipet() throws Exception {

    final String text = "Hello, World!";
    Metadata metadata = new Metadata();
    parser.parse(
            new ByteArrayInputStream(text.getBytes(UTF_8)),
            new BodyContentHandler(), metadata, new ParseContext());
    assertEquals("text/plain; charset=ISO-8859-1", metadata.get(Metadata.CONTENT_TYPE));
    // Now verify that if we tell the parser the encoding is UTF-8, that's what
    // we get back (see TIKA-868)
    metadata.set(Metadata.CONTENT_TYPE, "application/binary; charset=UTF-8");
    parser.parse(
            new ByteArrayInputStream(text.getBytes(UTF_8)),
            new BodyContentHandler(), metadata, new ParseContext());
    assertEquals("application/binary; charset=UTF-8", metadata.get(Metadata.CONTENT_TYPE));
}