mockftp serverfake FakeFtpServer;检查函数是否被调用

时间:2012-02-01 14:33:05

标签: java mocking mockito ftp-client

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

    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);

0 个答案:

没有答案