次の行は、2 つのリストを比較しようとすると失敗します。
import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.MatcherAssert.assertThat;
assertThat(
actualDealSummary.getDeals(),
hasItems(expectedDealSummary.getDeals().toArray(new Deal[expectedDealSummary.getDeals().size()])));
JUnit 4.11 と hamcrest-all (1.3) を使用:
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-all</artifactId>
<version>1.3</version>
</dependency>
実際のリストに期待されるリストの値があることを確認したいだけですが、次のエラーが発生します。
java.lang.AssertionError: 予想: (<SIXRxrImUE> を含むコレクション、<RQjVbVRlyG> を含むコレクション、および <avnKxogdyN> を含むコレクション) しかし: <SIXRxrImUE> を含むコレクションは <SIXRxrImUE>、<RQjVbVRlyG>、<avnKxogdyN> でした org.hamcrest.MatcherAssert.assertThat (MatcherAssert.java:20) で org.hamcrest.MatcherAssert.assertThat (MatcherAssert.java:8) で で
hamcrest のビルトイン Matchers を使用して 2 つの pojos のリストを比較するにはどうすればよいですか?