MimeTypes { public static String getMimeTypeForFileName(String fileName) { int extensionPos = fileName.lastIndexOf('.'); if (extensionPos >= 1 && extensionPos < fileName.length() - 1) { String extension = fileName.substring(extensionPos + 1); return getMimeTypeForExtension(extension); } else { return null; } } private  MimeTypes(); static String getMimeTypeForExtension(String fileExtension); static String getMimeTypeForFileName(String fileName); static String getDefaultMimeType();  }
@Test public void testFileNameExtraction() { try { assertNotNull(MimeTypes.getMimeTypeForFileName("test.txt")); assertNotNull(MimeTypes.getMimeTypeForFileName("t.txt")); assertNotNull(MimeTypes.getMimeTypeForFileName("first.second.third.txt")); assertNull(MimeTypes.getMimeTypeForFileName(".txt")); assertNull(MimeTypes.getMimeTypeForFileName("txt")); assertNull(MimeTypes.getMimeTypeForFileName("test.")); } catch (Exception e) { e.printStackTrace(); fail(e.getMessage()); } }