@Test
    public void testDetect() {
        assertDetect(MediaType.TEXT_PLAIN, "text.txt");
        assertDetect(MediaType.TEXT_PLAIN, "text.txt ");    // trailing space
        assertDetect(MediaType.TEXT_PLAIN, "text.txt\n");   // trailing newline
        assertDetect(MediaType.TEXT_PLAIN, "text.txt?a=b"); // URL query
        assertDetect(MediaType.TEXT_PLAIN, "text.txt#abc"); // URL fragment
        assertDetect(MediaType.TEXT_PLAIN, "text%2Etxt");   // URL encoded
        assertDetect(MediaType.TEXT_PLAIN, "text.TXT");     // case insensitive
        assertDetect(MediaType.OCTET_STREAM, "text.txt.gz");

        assertDetect(MediaType.TEXT_PLAIN, "README");
        assertDetect(MediaType.TEXT_PLAIN, " README ");     // space around
        assertDetect(MediaType.TEXT_PLAIN, "\tREADME\n");   // other whitespace
        assertDetect(MediaType.TEXT_PLAIN, "/a/README");    // leading path
        assertDetect(MediaType.TEXT_PLAIN, "\\b\\README");  // windows path
        assertDetect(MediaType.OCTET_STREAM, "ReadMe");     // case sensitive
        assertDetect(MediaType.OCTET_STREAM, "README.NOW");

        // TIKA-1928 # in the filename
        assertDetect(MediaType.TEXT_PLAIN, "text.txt");
        assertDetect(MediaType.TEXT_PLAIN, "text#.txt");   // # before extension
        assertDetect(MediaType.TEXT_PLAIN, "text#123.txt");// # before extension
        assertDetect(MediaType.TEXT_PLAIN, "text.txt#pdf");// # after extension

        // TIKA-3783 # before the final .
        assertDetect(MediaType.TEXT_PLAIN, "ABC#192.168.0.1#2.txt");

        // Check # as URL fragment too
        assertDetect(MediaType.TEXT_PLAIN, "http://foo/test.txt?1=2#pdf");
        assertDetect(MediaType.TEXT_PLAIN, "http://foo/test.txt#pdf");

        // tough one
        assertDetect(MediaType.TEXT_PLAIN, " See http://www.example.com:1234/README.txt?a=b#c \n");
        assertDetect(MediaType.TEXT_PLAIN, "See README.txt"); // even this!
        assertDetect(MediaType.OCTET_STREAM, "See README");   // but not this

        assertDetect(MediaType.application("envi.hdr"), "ang20150420t182050_corr_v1e_img.hdr");

        // test also the zero input cases
        assertDetect(MediaType.OCTET_STREAM, "");
        assertDetect(MediaType.OCTET_STREAM, null);
        try {
            assertEquals(MediaType.OCTET_STREAM, detector.detect(null, new Metadata()));
        } catch (IOException e) {
            fail("NameDetector should never throw an IOException");
        }
    }
Test cases for the {@link NameDetector} class.
tika-core/src/test/java/org/apache/tika/detect/NameDetectorTest.java