### Question:
GlusterFileSystemProvider extends FileSystemProvider { void copyFileContent(Path path, Path path2) throws IOException { Set<StandardOpenOption> options = new HashSet<>(); options.add(StandardOpenOption.READ); byte[] readBytes = new byte[8192]; FileChannel channel = newFileChannel(path, options); ByteBuffer readBuffer = ByteBuffer.wrap(readBytes); boolean writtenTo = false; int read = channel.read(readBuffer); while (read > 0) { byte[] writeBytes = Arrays.copyOf(readBytes, read); if (!writtenTo) { Files.write(path2, writeBytes, StandardOpenOption.TRUNCATE_EXISTING); writtenTo = true; } else { Files.write(path2, writeBytes, StandardOpenOption.APPEND); } read = channel.read(readBuffer); } channel.close(); }  @Override String getScheme(); @Override FileSystem newFileSystem(URI uri, Map<String, ?> stringMap); @Override FileSystem getFileSystem(URI uri); @Override Path getPath(URI uri); @Override SeekableByteChannel newByteChannel(Path path, Set<? extends OpenOption> openOptions, FileAttribute<?>... fileAttributes); @Override FileChannel newFileChannel(Path path, Set<? extends OpenOption> options, FileAttribute<?>... attrs); @Override DirectoryStream<Path> newDirectoryStream(Path path, DirectoryStream.Filter<? super Path> filter); @Override void createDirectory(Path path, FileAttribute<?>... fileAttributes); @Override void delete(Path path); @Override void copy(Path path, Path path2, CopyOption... copyOptions); @Override void move(Path path, Path path2, CopyOption... copyOptions); @Override boolean isSameFile(Path path, Path path2); @Override boolean isHidden(Path path); @Override FileStore getFileStore(Path path); @Override void checkAccess(Path path, AccessMode... accessModes); @Override V getFileAttributeView(Path path, Class<V> vClass, LinkOption... linkOptions); @Override A readAttributes(Path path, Class<A> type, LinkOption... linkOptions); @Override Map<String, Object> readAttributes(Path path, String s, LinkOption... linkOptions); @Override void setAttribute(Path path, String s, Object o, LinkOption... linkOptions); @Override Path readSymbolicLink(Path link); @Override void createSymbolicLink(Path link, Path target, FileAttribute<?>... attrs); static final String GLUSTER; static final int GLUSTERD_PORT; static final String TCP; }### Answer:
@Test public void testCopyFileContent() throws IOException { Set<StandardOpenOption> options = new HashSet<>(); options.add(StandardOpenOption.READ); byte[] bytes = new byte[8192]; doReturn(mockChannel).when(provider).newFileChannel(mockPath, options); when(mockChannel.read(any(ByteBuffer.class))).thenReturn(10, 10, 0); mockStatic(Arrays.class); when(Arrays.copyOf(bytes, 10)).thenReturn(bytes); mockStatic(Files.class); when(Files.write(mockPath, bytes, StandardOpenOption.TRUNCATE_EXISTING)).thenReturn(mockPath); when(Files.write(mockPath, bytes, StandardOpenOption.APPEND)).thenReturn(mockPath); doNothing().when(mockChannel).close(); provider.copyFileContent(mockPath, mockPath); verify(mockChannel).close(); verifyStatic(); Files.write(mockPath, bytes, StandardOpenOption.APPEND); verifyStatic(); Files.write(mockPath, bytes, StandardOpenOption.TRUNCATE_EXISTING); verifyStatic(times(2)); Arrays.copyOf(bytes, 10); verify(mockChannel, times(3)).read(any(ByteBuffer.class)); verify(provider).newFileChannel(mockPath, options); }