在 DocInfoServiceImpl 中,我有以下方法,我正在尝试使用 easymock 进行模拟。但我不清楚如何返回使用随机 uuid 值(相关性和 docfamily)创建并从私有方法返回的 docInfo 对象?
public void saveDocInfo(String docId)
{
**DocInfo docInfo = createDocInfo(docId);**
LOG.debug("Attempting to persist the doc info object for docId [" + docId + "]");
docInfoDao.save(docInfo);
LOG.debug("Persisted the doc info object for docId [" + docId + "]");
}
private DocInfo createDocInfo(String docId)
{
final DocInfo docInfo = new DocInfo();
docInfo.setId(docId);
docInfo.setDocFamilyUuid(UUIDGenerator.getInstance().getUuidAsString());
docInfo.setCorrelationId(UUIDGenerator.getInstance().getUuidAsString());
return docInfo;
}
在我正在使用的测试中,mockDocInfoDao.save 在第 3 行的服务的 saveDocInfo 中被调用。
void testSave()
{
def String docId = 'I19292800fe1911e0a849005056932b99'
mockDocInfoDao.save(expectedDocInfo)
replay(mockDocInfoDao)
docInfoServiceImpl.saveDocInfo(docId)
verify(mockDocInfoDao)
}