FilenameUtils { public static String makeFilename(final String name, final String ext) { if (null == name || null == ext) { return null; } if (isEmpty(ext)) { return name; } final StringBuilder buffer = new StringBuilder(); if (!isEmpty(name)) { buffer.append(nvl(name)); } buffer.append('.'); buffer.append(ext); return buffer.toString(); }  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 testMakeFilename() { final Object[][] testParameters = new Object[][] {{"HelloWorld", "", "HelloWorld"}, {"HelloWorld", " ", "HelloWorld"}, {"HelloWorld", "\n", "HelloWorld"}, {"", "png", ".png"}, {" ", "jpg", ".jpg"}, {"\n", "gif", ".gif"}, {"HelloWorld", "cgm", "HelloWorld.cgm"}, {"Hello.World", "svg", "Hello.World.svg"}}; assertNull(FilenameUtils.makeFilename(null, "png")); assertNull(FilenameUtils.makeFilename("HelloWorld", null)); for (final Object[] testParameter : testParameters) { String expected = (String) testParameter[2]; String name = (String) testParameter[0]; String ext = (String) testParameter[1]; assertEquals(expected, FilenameUtils.makeFilename(name, ext)); } }