我正在尝试使用Mockito框架为以下方法编写JUnit测试用例。
方法:
public EmplInfo getMetaData(String objectId) {
objectId = new StringBuffer(objectId).reverse().toString();
try{
BasicDBObject whereClauseCondition = getMetaDataWhereClause(objectId);
EmplInfo emplinfo= new EmplInfo ();
emplinfo.set_id(objectId);
FindIterable<Document> cursorPersonDoc = personDocCollection.find(whereClauseCondition);
for (Document doc : cursorPersonDoc) {
emplinfo.setEmplFirstName(doc.getString("firstname"));
emplinfo.setEmplLastName(doc.getString("lastname"));
break;
}
return emplinfo;
}catch(Exception e){
e.printstacktrace();
}
朱尼特:
@Test
public void testGetMetaData() throws Exception {
String docObjectId = "f2da8044b29f2e0a35c0a2b5";
BasicDBObject dbObj = personDocumentRepo.getMetaDataWhereClause(docObjectId);
FindIterable<Document> findIterable = null;
Mockito.when(collection.find(dbObj)).thenReturn(findIterable);
personDocumentRepo.getMetaData(docObjectId);
}
在“ personDocumentRepo.getMetaData(docObjectId)”中获得空值期望,因为“返回”为NULL的findIterable。不确定如何将虚拟/测试值分配给findIterable。
海绵宝宝撒
素胚勾勒不出你
慕森卡
相关分类