FileManager { public static void write(@NonNull String path, @NonNull String contents) throws IOException { write(new File(path), contents); }  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(expected = IOException.class) public void writeError() throws Exception { mockStatic(TextUtils.class); when(TextUtils.isEmpty(anyString())).thenReturn(false); when(TextUtils.getTrimmedLength(anyString())).thenReturn(4); BufferedWriter writer = mock(BufferedWriter.class); whenNew(BufferedWriter.class).withAnyArguments().thenReturn(writer); whenNew(FileWriter.class).withAnyArguments().thenReturn(mock(FileWriter.class)); doThrow(new IOException("mock")).when(writer).write(anyString()); FileManager.write(mock(File.class), "test"); verify(writer).close(); }