FileManager { @SuppressWarnings("WeakerAccess") @Nullable public static File lastModifiedFile(@NonNull String path, @Nullable FilenameFilter filter) { return lastModifiedFile(new File(path), filter); }  static synchronized void initialize(Context context); @SuppressWarnings("SameParameterValue") static String read(@NonNull String path); static String read(@NonNull File file); static byte[] readBytes(@NonNull File file); static void write(@NonNull String path, @NonNull String contents); static void write(@NonNull File file, @NonNull String contents); @SuppressWarnings("WeakerAccess") @NonNull static String[] getFilenames(@NonNull String path, @Nullable FilenameFilter filter); @SuppressWarnings("WeakerAccess") @Nullable static File lastModifiedFile(@NonNull String path, @Nullable FilenameFilter filter); @Nullable static File lastModifiedFile(@NonNull File dir, @Nullable FilenameFilter filter); static boolean delete(@NonNull String path); static boolean delete(@NonNull File file); static boolean deleteDirectory(@NonNull File file); static void cleanDirectory(@NonNull File directory); @SuppressWarnings("ResultOfMethodCallIgnored") static void mkdir(@NonNull String path);  }
@Test public void lastModifiedFile() { File dir = mock(File.class); FilenameFilter filter = mock(FilenameFilter.class); when(dir.exists()).thenReturn(true); when(dir.listFiles(any(FilenameFilter.class))).thenReturn(null); assertNull(FileManager.lastModifiedFile(dir, filter)); File file1 = mock(File.class); File file2 = mock(File.class); File file3 = mock(File.class); when(file1.lastModified()).thenReturn(1L); when(file2.lastModified()).thenReturn(2L); when(file3.lastModified()).thenReturn(3L); when(dir.listFiles(filter)).thenReturn(new File[]{file1, file3, file2}); assertEquals(file3, FileManager.lastModifiedFile(dir, filter)); }