FileManager { @SuppressWarnings("SameParameterValue") public static String read(@NonNull String path) { return read(new File(path)); }  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 readFileNotFound() throws Exception { mockStatic(AppCenterLog.class); FileReader fileReader = mock(FileReader.class, new ThrowsException(new FileNotFoundException())); whenNew(FileReader.class).withAnyArguments().thenReturn(fileReader); assertNull(FileManager.read(new File(""))); verify(fileReader).close(); verifyStatic(); AppCenterLog.error(anyString(), anyString(), any(IOException.class)); }
@Test public void readError() throws Exception { mockStatic(AppCenterLog.class); BufferedReader reader = mock(BufferedReader.class); whenNew(BufferedReader.class).withAnyArguments().thenReturn(reader); whenNew(FileReader.class).withAnyArguments().thenReturn(mock(FileReader.class)); when(reader.readLine()).thenReturn("incomplete"); when(reader.readLine()).thenThrow(new EOFException()); assertNull(FileManager.read(new File(""))); verify(reader).close(); verifyStatic(); AppCenterLog.error(anyString(), anyString(), any(IOException.class)); }
@Test public void readErrorAndCloseError() throws Exception { mockStatic(AppCenterLog.class); FileReader fileReader = mock(FileReader.class, new ThrowsException(new IOException())); whenNew(FileReader.class).withAnyArguments().thenReturn(fileReader); assertNull(FileManager.read(new File(""))); verify(fileReader).close(); verifyStatic(); AppCenterLog.error(anyString(), anyString(), any(IOException.class)); }
@Test public void readEmptyFile() throws Exception { mockStatic(AppCenterLog.class); BufferedReader reader = mock(BufferedReader.class); whenNew(BufferedReader.class).withAnyArguments().thenReturn(reader); whenNew(FileReader.class).withAnyArguments().thenReturn(mock(FileReader.class)); when(reader.readLine()).thenReturn(null); assertEquals("", FileManager.read(new File(""))); verify(reader).close(); }