FileTypeDetectorTest.java revision 9cf1c400b2a675276c4d03c0d541ea1ab869801c
1684f65f8602d1e1a79170984acc18421fb8f4c98Todd Kjospackage libcore.java.nio.file.spi;
2684f65f8602d1e1a79170984acc18421fb8f4c98Todd Kjos
3684f65f8602d1e1a79170984acc18421fb8f4c98Todd Kjosimport org.junit.Test;
4684f65f8602d1e1a79170984acc18421fb8f4c98Todd Kjos
5684f65f8602d1e1a79170984acc18421fb8f4c98Todd Kjosimport java.nio.file.Paths;
6684f65f8602d1e1a79170984acc18421fb8f4c98Todd Kjosimport java.nio.file.spi.FileTypeDetector;
7684f65f8602d1e1a79170984acc18421fb8f4c98Todd Kjos
8684f65f8602d1e1a79170984acc18421fb8f4c98Todd Kjosimport static org.junit.Assert.assertEquals;
9ae1f93cc3cef9c8c790330dd09f2ff87bf38eabcTodd Kjos
10ae1f93cc3cef9c8c790330dd09f2ff87bf38eabcTodd Kjospublic class FileTypeDetectorTest {
11ae1f93cc3cef9c8c790330dd09f2ff87bf38eabcTodd Kjos
12ae1f93cc3cef9c8c790330dd09f2ff87bf38eabcTodd Kjos    @Test
13ae1f93cc3cef9c8c790330dd09f2ff87bf38eabcTodd Kjos    public void test_probeFileType() throws Exception {
14ae1f93cc3cef9c8c790330dd09f2ff87bf38eabcTodd Kjos        FileTypeDetector defaultFileTypeDetector = sun.nio.fs.DefaultFileTypeDetector.create();
15ae1f93cc3cef9c8c790330dd09f2ff87bf38eabcTodd Kjos        // The method uses file extensions to deduce mime type, therefore, it doesn't check for
16ae1f93cc3cef9c8c790330dd09f2ff87bf38eabcTodd Kjos        // file existence.
17ae1f93cc3cef9c8c790330dd09f2ff87bf38eabcTodd Kjos        assertEquals("text/plain",
18ae1f93cc3cef9c8c790330dd09f2ff87bf38eabcTodd Kjos                defaultFileTypeDetector.probeContentType(Paths.get("file.txt")));
19684f65f8602d1e1a79170984acc18421fb8f4c98Todd Kjos        assertEquals("text/x-java",
20ae1f93cc3cef9c8c790330dd09f2ff87bf38eabcTodd Kjos                defaultFileTypeDetector.probeContentType(Paths.get("file.java")));
21ae1f93cc3cef9c8c790330dd09f2ff87bf38eabcTodd Kjos    }
22ae1f93cc3cef9c8c790330dd09f2ff87bf38eabcTodd Kjos}
23ae1f93cc3cef9c8c790330dd09f2ff87bf38eabcTodd Kjos