test the new mime type detection

This commit is contained in:
bgamard 2022-01-17 14:37:22 +01:00
parent ee56cfe2b4
commit 3637b832e5
2 changed files with 5 additions and 1 deletions

View File

@ -27,7 +27,8 @@ public class MimeTypeUtil {
* @throws IOException e
*/
public static String guessMimeType(Path file, String name) throws IOException {
String mimeType = URLConnection.getFileNameMap().getContentTypeFor(name);
String mimeType = name == null ?
null : URLConnection.getFileNameMap().getContentTypeFor(name);
if (mimeType == null) {
try (InputStream is = Files.newInputStream(file)) {
final byte[] headerBytes = new byte[64];

View File

@ -27,5 +27,8 @@ public class TestMimeTypeUtil {
// Detect PPTX files
path = Paths.get(ClassLoader.getSystemResource("file/apache.pptx").toURI());
Assert.assertEquals(MimeType.OFFICE_PRESENTATION, MimeTypeUtil.guessMimeType(path, "apache.pptx"));
// Detect TXT files
Assert.assertEquals(MimeType.TEXT_PLAIN, MimeTypeUtil.guessMimeType(path, "file.txt"));
}
}