我以为很简单
Assert.assertThat(
iterator.next(),
Matchers.either(Matchers.nullValue()).or(
Matchers.instanceOf(Double.class)));
所以我想 ensre next() 返回两个之一,NULL 或 Double 的实例。某事喜欢
Assert.assertTrue(next == null || next instanceof Double);
测试运行 ( assertThat
) 结果...
java.lang.NoSuchMethodError: org.hamcrest.Matcher.describeMismatch(Ljava/lang/Object;Lorg/hamcrest/Description;)V
at org.hamcrest.core.CombinableMatcher.matchesSafely(CombinableMatcher.java:17)
at org.hamcrest.TypeSafeDiagnosingMatcher.matches(TypeSafeDiagnosingMatcher.java:55)
at org.junit.Assert.assertThat(Assert.java:772)
at org.junit.Assert.assertThat(Assert.java:738
为什么?以及如何解决?
编辑
你是对的,与来自 Mockito 的 hamcrest lib 发生了冲突。我已经修好了。没有错误,但断言奇怪地失败了,看看:
java.lang.AssertionError:
Expected: (null or an instance of java.lang.Double)
got: null
at org.junit.Assert.assertThat(Assert.java:780)
at org.junit.Assert.assertThat(Assert.java:738)
Null 是预期的,得到 null 并且测试失败。