我有以下收藏: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.*做到这一点? (adsbygoogle = window.adsbygoogle || []).push({}); 最佳答案 您可以使用CombinableMatcher来both(matcher1).and(matcher2)匹配器。这样您会得到类似以下内容的信息:assertThat(parentDecisionGroups, hasItem( both(hasProperty("id", equalTo(decisionGroup1.getId()))). and(hasProperty("ownerDecision", equalTo("decision1"))));关于java - JUnit声明,匹配器和嵌套对象,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/47133052/ (adsbygoogle = window.adsbygoogle || []).push({}); 10-10 04:11