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;
関数 indexFile(...) が呼び出された時間をカウントできるように、偽の FTP ファイルを生成できます。のようなもので
verify(ftpFolderTest,times(1)).indexFile(file, localFolder);