### Question:
S3SeekableByteChannel implements SeekableByteChannel { @Override public void close() throws IOException { try { if (!seekable.isOpen()) return; seekable.close(); if (options.contains(StandardOpenOption.DELETE_ON_CLOSE)) { path.getFileSystem().provider().delete(path); return; } if (options.contains(StandardOpenOption.READ) && options.size() == 1) { return; } sync(); } finally { Files.deleteIfExists(tempFile); } } S3SeekableByteChannel(S3Path path, Set<? extends OpenOption> options); @Override boolean isOpen(); @Override void close(); @Override int write(ByteBuffer src); @Override SeekableByteChannel truncate(long size); @Override long size(); @Override int read(ByteBuffer dst); @Override SeekableByteChannel position(long newPosition); @Override long position();  }### Answer:
@Test(expected = RuntimeException.class) public void brokenNetwork() throws IOException { AmazonS3ClientMock client = AmazonS3MockFactory.getAmazonClientMock(); doThrow(new RuntimeException("network broken")).when(client).getObject("buck", "file2"); S3Path file2 = (S3Path) FileSystems.getFileSystem(S3EndpointConstant.S3_GLOBAL_URI_TEST).getPath("/buck/file2"); S3SeekableByteChannel channel = new S3SeekableByteChannel(file2, EnumSet.of(StandardOpenOption.WRITE, StandardOpenOption.READ)); channel.close(); }
@Test(expected = NoSuchFileException.class) public void tempFileDisappeared() throws IOException, NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException { S3Path file2 = (S3Path) FileSystems.getFileSystem(S3EndpointConstant.S3_GLOBAL_URI_TEST).getPath("/buck/file2"); S3SeekableByteChannel channel = new S3SeekableByteChannel(file2, EnumSet.of(StandardOpenOption.WRITE, StandardOpenOption.READ)); Field f = channel.getClass().getDeclaredField("tempFile"); f.setAccessible(true); Path tempFile = (Path) f.get(channel); Files.delete(tempFile); channel.close(); }