FileLogTarget implements LogTarget { public synchronized OutputStream open() { try { close(); fileOutputStream = new FileOutputStream(file, true); } catch (FileNotFoundException e) { throw new RuntimeException("Unable to open output stream", e); } return fileOutputStream; } FileLogTarget(File target); synchronized OutputStream open(); synchronized void close(); @Override String toString();  }
@Test(expected = RuntimeException.class) public void requireThatExceptionIsThrowIfFileNotFound() throws IOException { File file = new File("mydir1"); file.delete(); assertTrue(file.mkdir()); new FileLogTarget(file).open(); }
@Test public void requireThatFileCanOpened() throws IOException { FileLogTarget logTarget = new FileLogTarget(File.createTempFile("logfile", ".log")); assertNotNull(logTarget.open()); }
@Test public void requireThatFileIsReopened() throws IOException { FileLogTarget logTarget = new FileLogTarget(File.createTempFile("logfile", ".log")); OutputStream out1 = logTarget.open(); assertNotNull(out1); OutputStream out2 = logTarget.open(); assertNotNull(out2); assertNotEquals(out1, out2); }