### Question:
Utils { static int capFileCount(File directory, int maxAllowed, Comparator<File> sortComparator) { return capFileCount(directory, ALL_FILES_FILTER, maxAllowed, sortComparator); } private  Utils(); static Task<T> race(Task<T> t1, Task<T> t2); static Task<T> callTask(Executor executor, Callable<Task<T>> callable); static T awaitEvenIfOnMainThread(Task<T> task);  }### Answer:
@Test public void testCapFileCount_returnsNumberOfRetainedFilesIfLessThanMax() throws Exception { folder.newFile(); folder.newFile(); final int numRetained = Utils.capFileCount(folder.getRoot(), ALL_FILES, 3, SMALLEST_FILENAME_FIRST); assertEquals(2, numRetained); }
@Test public void testCapFileCount_returnsNumberOfRetainedFilesIfMoreThanMax() throws Exception { folder.newFile(); folder.newFile(); folder.newFile(); folder.newFile(); final int numRetained = Utils.capFileCount(folder.getRoot(), ALL_FILES, 3, SMALLEST_FILENAME_FIRST); assertEquals(3, numRetained); }
@Test public void testCapFileCount_returnsNumberOfRetainedFilesIfSameAsMax() throws Exception { folder.newFile(); folder.newFile(); folder.newFile(); final int numRetained = Utils.capFileCount(folder.getRoot(), ALL_FILES, 3, SMALLEST_FILENAME_FIRST); assertEquals(3, numRetained); }
@Test public void testCapFileCount_returnsZeroRetainedIfFolderEmpty() throws Exception { final int numRetained = Utils.capFileCount(folder.getRoot(), ALL_FILES, 3, SMALLEST_FILENAME_FIRST); assertEquals(0, numRetained); }
@Test public void testCapFileCount_returnsZeroRetainedIfFolderMissing() throws Exception { final int numRetained = Utils.capFileCount(new File(""), ALL_FILES, 3, SMALLEST_FILENAME_FIRST); assertEquals(0, numRetained); }