MimeType implements Serializable { public static MimeType fromFile(final File file) { Objects.requireNonNull(file, "The file cannot be null!"); final String fileName = file.getName(); return fromFileName(fileName); } MimeType(); private  MimeType(final String mimeTypeString);  MimeType(final String mimeTypeString, final String extension); String getMimeTypeString(); void setMimeTypeString(String mimeTypeString); static MimeType fromFileName(final String fileName); static String getExtension(MimeType mimeType); static String getFileExtension(final String fileName); static MimeType fromFile(final File file); static MimeType fromMimeTypeString(final String mimeTypeString); void defineFileExtension(final String extension); @Override int hashCode(); @Override boolean equals(Object obj); @Override String toString(); static final MimeType BINARY; static final MimeType XML; static final MimeType HTML; static final MimeType PDF; static final MimeType PKCS7; static final MimeType TST; static final MimeType ASICS; static final MimeType ASICE; static final MimeType ODT; static final MimeType ODS; static final MimeType ODP; static final MimeType ODG; static final MimeType TEXT; static final MimeType CRL; static final MimeType CER; static final MimeType PNG; static final MimeType JPEG; static final MimeType SVG; }
@Test public void fromFileTest() { assertEquals(MimeType.BINARY, MimeType.fromFile(new File("src/test/resources/AdobeCA.p7c"))); MimeType certMimeType = new MimeType("application/cert", "p7c"); assertEquals(certMimeType, MimeType.fromFile(new File("src/test/resources/AdobeCA.p7c"))); assertEquals(MimeType.BINARY, MimeType.fromFile(new File("D-TRUST_CA_3-1_2016.cer"))); certMimeType.defineFileExtension("cer"); assertEquals(certMimeType, MimeType.fromFile(new File("D-TRUST_CA_3-1_2016.cer"))); Exception exception = assertThrows(IllegalArgumentException.class, () -> certMimeType.defineFileExtension("")); assertEquals("The extension cannot be null or blank!", exception.getMessage()); exception = assertThrows(IllegalArgumentException.class, () -> certMimeType.defineFileExtension(null)); assertEquals("The extension cannot be null or blank!", exception.getMessage()); exception = assertThrows(NullPointerException.class, () -> MimeType.fromFile(null)); assertEquals("The file cannot be null!", exception.getMessage()); }