1

我想测试我的函数 indexFolder(...) ,它负责从 FTP 检索文件。文件必须比要下载的本地版本更新。

    private void indexFolder(FTPClient ftp, FTPFile[] listFiles, File localFolder, FTPFolderAssetSource ftpFolderAssetSource)
{
    try
    {
        for (FTPFile currentFile : listFiles)
        {
            if (currentFile.isDirectory())
            {
                if (getAssetSource().getIncludeSubDirectories())
                {
                    ftp.changeWorkingDirectory(currentFile.getName());

                    File localSubFolder = new File(localFolder.getPath() + "\\" + currentFile.getName());
                    localSubFolder.mkdir();

                    indexFolder(ftp, ftp.listFiles(), localSubFolder, assetSource);
                    ftpCodeGestion(ftp, ftp.getReplyCode());

                    ftp.cdup();
                    ftpCodeGestion(ftp, ftp.getReplyCode());
                }// if
            }// if
            else
            {
                File localFile = new File(localFolder.getPath(), currentFile.getName());

                long FTPTimeStamp = currentFile.getTimestamp().getTimeInMillis();
                long localTimeStamp = localFile.lastModified();

                if (FTPTimeStamp > localTimeStamp)
                {
                    downloadFromFTP(ftp, currentFile, localFile);
                    indexFile(localFile, localFolder);
                }
            }// else
        }// for
    }
    catch (SocketException e)
    {
        connectionSuccess = false;
        connectionRetry(ftp);
    }
    catch (Exception e)
    {
        e.printStackTrace();
        logger.error("Error indexing folder: " + localFolder.getAbsolutePath(), e);
    }
}

我想知道图书馆是否

import org.mockftpserver.fake.FakeFtpServer;

可以生成伪造的 FTP 文件,以允许我计算调用函数 indexFile(...) 的时间量。有类似的东西

verify(ftpFolderTest,times(1)).indexFile(file, localFolder);
4

0 回答 0