### Question:
FileUtil { public static String uniqueName(File source, Set<String> taken) { String name = source.getName(); for (int i = 1; taken.contains(name); i++) { name = getFileNameWithoutExtention(source) + "_" + i; final String extension = getFileExtension(source); if (!extension.isEmpty()) { name += "." + extension; } } return name; } private  FileUtil(); static void write(String text, File target); static Uri getUri(Context context, String authority, File file); static void saveBitmap(Bitmap bitmap, File targetFile, int quality); static void saveBitmap(Bitmap bitmap, File targetFile, Bitmap.CompressFormat format, int quality); static void zip(List<File> sources, File target); static List<File> walk(File source); static List<File> walk(List<File> sources); static String uniqueName(File source, Set<String> taken); static String getFileExtension(File file); static String getFileNameWithoutExtention(File file);  }### Answer:
@Test public void uniqueName_returns_same_if_not_taken() { final File file = new File("f.txt"); Assert.assertEquals("f.txt", FileUtil.uniqueName(file, new HashSet<>())); }
@Test public void uniqueName_returns_new_name_if_taken() { final File file = new File("f.txt"); Assert.assertEquals("f_2.txt", FileUtil.uniqueName(file, CollectionUtils.asSet("f.txt", "f_1.txt"))); }
@Test public void uniqueName_returns_new_name_if_taken_file_without_extension() { final File file = new File("f"); Assert.assertEquals("f_2", FileUtil.uniqueName(file, CollectionUtils.asSet("f", "f_1"))); }
@Test public void uniqueName_returns_new_name_if_taken_file_starts_with_dot() { final File file = new File(".ignore"); Assert.assertEquals(".ignore_2", FileUtil.uniqueName(file, CollectionUtils.asSet(".ignore", ".ignore_1"))); }