How to claim that Set has an element with an exact property with hamcrest

I tried to claim that my Set has a collection with this hamcrest property using this solution , but I have:

java.lang.NoSuchMethodError: org.hamcrest.Matcher.describeMismatch (Ljava / languages ​​/ object; Lorg / Hamcrest / Description;) V, at org.hamcrest.Condition $ Matched.matching (Condition.java:52)

Import

import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasProperty;
import static org.junit.Assert.assertThat;

the code:

assertThat(mySet, contains(hasProperty("id", equalTo("expectedId"))));

Do you have any ideas how to state this well?

+4
source share
1 answer

Well, you should try to let it be argued that it does the work for you.

Set<WhateverPropertyTypeYouAreUsing> expectedSet = Collections.singleton( ... create a property object with that id/value);

assertThat(mySet, is(expectedSet))

: , .

:

assertThat(mySet.contains(someProperty), is(true))

(, , ).

Prereq: equals() .

+1

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


All Articles