FileUtilities { public static String getExtension(final String filename) { if (filename == null) { return null; } String filenameNormalized = filename.toLowerCase(); String ext = ""; int positionOfSlash = filenameNormalized.lastIndexOf('/'); if (positionOfSlash != -1) { filenameNormalized = filenameNormalized.substring(positionOfSlash + 1); } int positionOfDot = filenameNormalized.lastIndexOf('.'); if (positionOfDot != -1) { ext = filenameNormalized.substring(positionOfDot + 1); } return ext; } private  FileUtilities(); static String getExtension(final String filename); static void clearDirectory(final String directoryPath); static String fileSizeUnits(final long length);  }
@Test public void shouldReturnValidExtension() { assertThat(FileUtilities.getExtension("file.ext"), is("ext")); assertThat(FileUtilities.getExtension("/path/file.ext"), is("ext")); assertThat(FileUtilities.getExtension("file"), is("")); assertThat(FileUtilities.getExtension(null), is(nullValue())); }