I could with following code check if a list has a item, which greater than 30.
//Using Hamcrest
List<Integer> ints= Arrays.asList(22,33,44,55);
assertThat(ints,hasItem(greaterThan(30)));
But how could I assert if a list has at least 2 items, which are greater than 30?
With AssertJ
, there is a solution I know. But I have no idea how to realize that with Hamcrest
.
//Using AssertJ
List<Integer> ints= Arrays.asList(22,33,44,55);
Condition<Integer> greaterThanCondition = new Condition<Integer>("greater") {
@Override
public boolean matches (Integer i){
return i>30;
}
} ;
assertThat(ints).haveatLeast(2,greaterThanCondition);