SingleWriterMultipleReaderFile { public void failWrite(FileOutputStream stream) throws IOException { FileHelper.closeOrWarn(stream, "SingleWriterMultipleReaderFile", "Cannot close working file"); if (!workFile.delete()) throw new IOException("Cannot delete working file"); } SingleWriterMultipleReaderFile(File file); InputStream openRead(); FileOutputStream startWrite(); void finishWrite(FileOutputStream stream); void failWrite(FileOutputStream stream);  }
@Test public void testFailWrite() throws Exception { doCallRealMethod().when(reader).finishWrite(any(FileOutputStream.class)); doCallRealMethod().when(reader).failWrite(any(FileOutputStream.class)); when(workFile.delete()).thenReturn(true); try { reader.failWrite(fos); } catch (Exception e) { fail("Should not throw"); } when(workFile.delete()).thenReturn(false); try { reader.failWrite(fos); fail("Should throw"); } catch (Exception e) { } }