@SuppressWarnings("unchecked")
    @Test
    public void testRecursiveDeleteWithDeletedFile() throws IOException {
        // Test recursive deletes, where the FileWalk is supplied with a deleted file path.
        File rootDir = TestUtils.tempDirectory();
        File subDir = TestUtils.tempDirectory(rootDir.toPath(), "a");

        DirectoryStream<Path> mockDirectoryStream = (DirectoryStream<Path>) mock(DirectoryStream.class);
        FileSystemProvider mockFileSystemProvider = mock(FileSystemProvider.class);
        FileSystem mockFileSystem = mock(FileSystem.class);
        Path mockRootPath = mock(Path.class);
        BasicFileAttributes mockBasicFileAttributes = mock(BasicFileAttributes.class);
        Iterator<Path> mockIterator = mock(Iterator.class);
        File spyRootFile = spy(rootDir);

        when(spyRootFile.toPath()).thenReturn(mockRootPath);
        when(mockRootPath.getFileSystem()).thenReturn(mockFileSystem);
        when(mockFileSystem.provider()).thenReturn(mockFileSystemProvider);
        when(mockFileSystemProvider.readAttributes(any(), (Class<BasicFileAttributes>) any(), any())).thenReturn(mockBasicFileAttributes);
        when(mockBasicFileAttributes.isDirectory()).thenReturn(true);
        when(mockFileSystemProvider.newDirectoryStream(any(), any())).thenReturn(mockDirectoryStream);
        when(mockDirectoryStream.iterator()).thenReturn(mockIterator);
        // Here we pass the rootDir to the FileWalk which removes all Files recursively,
        // and then we pass the subDir path again which is already deleted by this point.
        when(mockIterator.next()).thenReturn(rootDir.toPath()).thenReturn(subDir.toPath());
        when(mockIterator.hasNext()).thenReturn(true).thenReturn(true).thenReturn(false);

        assertDoesNotThrow(() -> {
            Utils.delete(spyRootFile);
        });
        assertFalse(Files.exists(rootDir.toPath()));
        assertFalse(Files.exists(subDir.toPath()));
    }
Expectation setter for multiple reads where each one reads random bytes to the buffer.

@param channelMock           The mocked FileChannel object
@param bufferSize            The buffer size
@return Expected buffer string
@throws IOException          If an I/O error occurs
clients/src/test/java/org/apache/kafka/common/utils/UtilsTest.java