我有以下系列:
Set<DecisionGroup> parentDecisionGroups
首先,在我的测试中,我需要检查此集合是否包含两个具有给定ID的对象:
assertThat(parentDecisionGroups, hasItem(hasProperty("id", equalTo(decisionGroup1.getId()))));
assertThat(parentDecisionGroups, hasItem(hasProperty("id", equalTo(decisionGroup2.getId()))));
到目前为止一直很好......
现在我需要检查parentDecisionGroups.get(0).getOwnerDecision()
(其中parentDecisionGroup.id == decisionGroup1.getId())是否等于decision1
和parentDecisionGroups.get(1).getOwnerDecision()
(其中parentDecisionGroup.id == decisionGroup2) .getId())等于decision2
如何使用org.hamcrest.*
和org.junit.Assert.*
?
答案 0 :(得分:4)
您可以使用 public List<Product> getAllProduct() {
List<Product> products = new ArrayList<Product>();
Cursor cursor = database.rawQuery("SELECT SUM(count) From shirts ORDER BY id DESC ", null);
cursor.moveToFirst();
while (!cursor.isAfterLast()) {
int id = cursor.getInt(0);
String title = cursor.getString(1);
String price = cursor.getString(2);
String quantity = cursor.getString(3);
int count = cursor.getInt(4);
products.add(new Product(id, title, price, quantity, count));
cursor.moveToNext();
}
cursor.close();
return products;
}
CombinableMatcher
匹配器。
所以你会得到类似的东西:
both(matcher1).and(matcher2)