SharedFileWriter extends AbstractFormatPatternWriter { @Override public void close() throws IOException { try { writer.close(); } finally { if (lockFile != null) { try { lock.release(); } finally { lockFile.close(); } } } } SharedFileWriter();  SharedFileWriter(final Map<String, String> properties); @Override void write(final LogEntry logEntry); @Override void flush(); @Override void close();  }
@Test public void invalidCharset() throws IOException { String file = FileSystem.createTemporaryFile(); new SharedFileWriter(doubletonMap("file", file, "charset", "UTF-42")).close(); assertThat(systemStream.consumeErrorOutput()).containsOnlyOnce("ERROR").containsOnlyOnce("charset").containsOnlyOnce("UTF-42"); }
@Test @PrepareForTest(SharedFileWriter.class) public void unsupportedSharedLocks() throws IOException, Exception { FileLock mockedLock = mock(FileLock.class); when(mockedLock.isShared()).thenReturn(false); FileChannel mockedChannel = mock(FileChannel.class); when(mockedChannel.lock(anyLong(), anyLong(), eq(true))).thenReturn(mockedLock); RandomAccessFile mockedFile = mock(RandomAccessFile.class); when(mockedFile.getChannel()).thenReturn(mockedChannel); whenNew(RandomAccessFile.class).withAnyArguments().thenReturn(mockedFile); String file = FileSystem.createTemporaryFile(); new SharedFileWriter(doubletonMap("file", file, "append", "false")).close(); assertThat(systemStream.consumeErrorOutput()).containsOnlyOnce("WARN").contains("shared"); }