Hamcrest boolean statement with getter prefix by "is" method

We would like to state that the list of user objects contains an object with some of its fields having certain values, with a number of statements like this

assertThat(customObjectList, hasItem(hasProperty("someField", equalTo(someValue))));

However, the user object also has boolean fields, where the getter method has the prefix "is" instead of "get", and there the statement seems to fail with

java.lang.AssertionError: Expected: a collection containing hasProperty("booleanField", <true>) but: property "booleanField" is not readable

Is there a ready-made solution to overcome this, or should it be handled with some kind of user match?

+4
source share
2 answers

(moving commentary to answer as Ivo Mori suggested)

Hamcrest java.beans.PropertyDescriptor, JavaBean, is .

, Matcher (- hasGetterValue)

+4

FYI: Hamcrest shazamcrest sameBeanAs (DiagnosingCustomisableMatcher), Boolean types;)

+1

Source: https://habr.com/ru/post/1610549/


All Articles