jjzjj

hasItems

全部标签

java - 滥用 hamcrest hasItems

我有一个整数列表(当前),我想检查这个列表是否包含预期列表中的所有元素,甚至不包含列表notExpected中的一个元素,所以代码如下:Listexpected=newArrayList();expected.add(1);expected.add(2);ListnotExpected=newArrayList();notExpected.add(3);notExpected.add(4);Listcurrent=newArrayList();current.add(1);current.add(2);assertThat(current,not(hasItems(notExpecte

java - hamcrest hasItem 和 hasProperty,断言是否存在具有属性值的对象

importstaticorg.hamcrest.MatcherAssert.assertThat;importstaticorg.hamcrest.Matchers.hasItem;importstaticorg.hamcrest.Matchers.equalTo;assertThat(actual,hasItem(hasProperty("id",equalTo(1L))));其中actual是一个ID为Long的POJO。我明白了,ThemethodassertThat(T,Matcher)inthetypeMatcherAssertisnotapplicableforthear