FilenameUtils { public static String getExtension(final String filename) { return getExtension(filename, false); }  static String getExtension(final String filename); static String getExtension(final String filename, final boolean isGreedy); static String stripExtension(final String filename); static String makeFilename(final String name, final String ext);  }
@Test public void testGetExtensionOnFilename() { final Object[][] testParameters = new Object[][] {{"HelloWorld.png", "png"}, {"Hello.World.jpg", "jpg"}, {"Hello_World.gif", "gif"}}; assertNull(FilenameUtils.getExtension(null)); for (final Object[] testParameter : testParameters) { String expected = (String) testParameter[1]; String filename = (String) testParameter[0]; assertEquals(expected, FilenameUtils.getExtension(filename)); } }
@Test public void testGetExtensionOnFilenameAndIsGreedy() { final Object[][] testParameters = new Object[][] {{"HelloWorld.png", false, "png"}, {"HelloWorld.jpg", true, "jpg"}, {"Hello.World.gif", false, "gif"}, {"Hello.World.bmp", true, "World.bmp"}}; assertNull(FilenameUtils.getExtension(null, false)); assertNull(FilenameUtils.getExtension(null, true)); for (final Object[] testParameter : testParameters) { String expected = (String) testParameter[2]; String filename = (String) testParameter[0]; boolean isGreedy = (Boolean) testParameter[1]; assertEquals(expected, FilenameUtils.getExtension(filename, isGreedy)); } }