@Test
public void testOpenWrite() throws Exception {

    File file = mock(File.class);
    File file2 = mock(File.class);
    FileOutputStream fos = mock(FileOutputStream.class);
    when(mockContext.getFileStreamPath(eq("filename"))).thenReturn(file);
    when(mockContext.getFileStreamPath(eq("filename.bak"))).thenReturn(file2);
    when(mockContext.openFileOutput(eq("filename"), anyInt())).thenReturn(fos);
    assertSame(fos, FileHelper.openWrite(mockContext, "filename"));
    Mockito.verify(file).renameTo(file2);
    Mockito.verify(mockContext).openFileOutput(eq("filename"), anyInt());
}