我需要编写Matcher来检查多个属性.对于我使用的单一财产:
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasProperty;
import org.hamcrest.Matcher;
import org.hamcrest.Matchers;
Matcher<Class> matcherName = Matchers.<Class> hasProperty("propertyName",equalTo(expectedValue));
Run Code Online (Sandbox Code Playgroud)
我怎么想在一个匹配器中查看更多属性?
我一直在尝试使用此解决方案断言我的 Set 具有具有 hamcrest 给定属性的集合,但我有:
java.lang.NoSuchMethodError: org.hamcrest.Matcher.describeMismatch(Ljava/lang/Object;Lorg/hamcrest/Description;)V at org.hamcrest.Condition$Matched.matching(Condition.java:52)
进口:
import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasProperty;
import static org.junit.Assert.assertThat;
Run Code Online (Sandbox Code Playgroud)
代码:
assertThat(mySet, contains(hasProperty("id", equalTo("expectedId"))));
Run Code Online (Sandbox Code Playgroud)
您有什么想法如何很好地维护它吗?