@Test public void testCloseAndFlushOutputStreamAfterCreatingHashCode() throws IOException { mockStatic(Closeables.class); doNothing().when(Closeables.class); Closeables.close(any(ObjectOutputStream.class), Matchers.eq(false)); mockStatic(Flushables.class); doNothing().when(Flushables.class); Flushables.flush(any(ObjectOutputStream.class), Matchers.eq(false)); final Configuration config = new DefaultConfiguration("myName"); final PropertyCacheFile cache = new PropertyCacheFile(config, "fileDoesNotExist.txt"); cache.load(); verifyStatic(times(1)); Closeables.close(any(ObjectOutputStream.class), Matchers.eq(false)); verifyStatic(times(1)); Flushables.flush(any(ObjectOutputStream.class), Matchers.eq(false)); }
@Test public void testFlushAndCloseCacheFileOutputStream() throws IOException { mockStatic(Closeables.class); doNothing().when(Closeables.class); Closeables.close(any(FileOutputStream.class), Matchers.eq(false)); mockStatic(Flushables.class); doNothing().when(Flushables.class); Flushables.flush(any(FileOutputStream.class), Matchers.eq(false)); final Configuration config = new DefaultConfiguration("myName"); final PropertyCacheFile cache = new PropertyCacheFile(config, temporaryFolder.newFile().getPath()); cache.put("CheckedFileName.java", System.currentTimeMillis()); cache.persist(); verifyStatic(times(1)); Closeables.close(any(FileOutputStream.class), Matchers.eq(false)); verifyStatic(times(1)); Flushables.flush(any(FileOutputStream.class), Matchers.eq(false)); }
/** * Flushes and closes output stream. * @param stream the output stream * @throws IOException when there is a problems with file flush and close */ private static void flushAndCloseOutStream(OutputStream stream) throws IOException { if (stream != null) { Flushables.flush(stream, false); } Closeables.close(stream, false); }