### Question:
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();  }### Answer:
@Test public void getChannel_shouldReturnAResultWithAChannelAndAssociatedWriter() 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(); assertSame(testFileChannel, result.channel); ensureAssociated(result.writer, result.channel); ensureUtf8Charset(result.writer); assertTrue(testFileChannel.isOpen()); }
@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)); }