@Test public void close_shouldCloseTheFileChannelAndAssociatedWriter_givenAResultReturnedByGetChannel() throws Exception { FileChannel testFileChannel = FileChannel.open(tempFiles.createTempFile(null), CREATE); when(mockPath.getFileSystem().provider().newFileChannel(same(mockPath), eq(CREATE_AND_APPEND))).thenReturn(testFileChannel); FileChannelProvider.Result result = provider.getChannel(); assertThat(result, instanceOf(Closeable.class)); assertTrue("precondition: FileChannel should be open", result.channel.isOpen()); assertTrue("precondition: Writer should be open", isOpen(result.writer)); result.close(); assertFalse(result.channel.isOpen()); assertFalse(isOpen(result.writer)); }
public Result getChannel() throws IOException { FileChannel fileChannel = FileChannel.open(path, CREATE, APPEND); Writer writer = Channels.newWriter(fileChannel, "UTF-8"); return new Result(fileChannel, writer); }
FileChannelProvider { public Result getChannel() throws IOException { FileChannel fileChannel = FileChannel.open(path, CREATE, APPEND); Writer writer = Channels.newWriter(fileChannel, "UTF-8"); return new Result(fileChannel, writer); } }
FileChannelProvider { public Result getChannel() throws IOException { FileChannel fileChannel = FileChannel.open(path, CREATE, APPEND); Writer writer = Channels.newWriter(fileChannel, "UTF-8"); return new Result(fileChannel, writer); } FileChannelProvider(Path path); }
FileChannelProvider { public Result getChannel() throws IOException { FileChannel fileChannel = FileChannel.open(path, CREATE, APPEND); Writer writer = Channels.newWriter(fileChannel, "UTF-8"); return new Result(fileChannel, writer); } FileChannelProvider(Path path); Result getChannel(); Path getPath(); }
FileChannelProvider { public Result getChannel() throws IOException { FileChannel fileChannel = FileChannel.open(path, CREATE, APPEND); Writer writer = Channels.newWriter(fileChannel, "UTF-8"); return new Result(fileChannel, writer); } FileChannelProvider(Path path); Result getChannel(); Path getPath();  }