SingleWriterMultipleReaderFile { public void finishWrite(FileOutputStream stream) throws IOException { try { stream.close(); } catch (IOException e) { failWrite(stream); throw e; } if (!workFile.renameTo(activeFile)) { failWrite(stream); throw new IOException("Cannot commit transaction"); } } SingleWriterMultipleReaderFile(File file); InputStream openRead(); FileOutputStream startWrite(); void finishWrite(FileOutputStream stream); void failWrite(FileOutputStream stream);  }
@Test public void testFinishWrite_success() throws Exception { doCallRealMethod().when(reader).finishWrite(any(FileOutputStream.class)); when(workFile.renameTo(activeFile)).thenReturn(true); try { reader.finishWrite(fos); Mockito.verify(fos).close(); } catch (IOException e) { fail("Successful rename commits transaction"); } }