FileUtil { public static boolean hasExtension(String filename, String extension) { if (Util.isBlank(extension)) { return false; } String fileExtension = getExtension(filename); if (Util.isBlank(fileExtension)) { return false; } return fileExtension.equalsIgnoreCase(extension.replace(".", "")); }  static String stripExtension(String filename); static String getExtension(String filename); static boolean hasExtension(String filename, String extension);  }
@Test public void testHasExtensionNullFilename() { assertEquals(false, FileUtil.hasExtension(null, "ext")); }
@Test public void testHasExtensionNullExtension() { assertEquals(false, FileUtil.hasExtension("some/file/with/an/extension.ext", null)); }
@Test public void testHasExtensionEmptyFilename() { assertEquals(false, FileUtil.hasExtension("", "ext")); }
@Test public void testHasExtensionEmptyExtension() { assertEquals(false, FileUtil.hasExtension("some/file/with/an/extension.ext", "")); }
@Test public void testHasExtensionNonMatchingExtension() { assertEquals(false, FileUtil.hasExtension("some/file/with/an/extension.ext1", "ext2")); }
@Test public void testHasExtensionMatchingExtensionSameCase() { assertEquals(true, FileUtil.hasExtension("some/file/with/an/extension.ext1", "ext1")); }
@Test public void testHasExtensionMatchingExtensionMixedCase() { assertEquals(true, FileUtil.hasExtension("some/file/with/an/extension.exT1", "eXt1")); }
@Test public void testHasExtensionMatchingExtensionWithPeriod() { assertEquals(true, FileUtil.hasExtension("some/file/with/an/extension.exT1.Ext2", ".eXt2")); }