为什么在比较项目而不是列表时,我会得到'实际和正式的参数列表长度不同'?

时间:2015-11-07 15:58:02

标签: java junit equals hamcrest

我尝试运行这个最终断言的junit测试:

ResponseExample responseExample = new ResponseExample();
responseExample.value = 4;

assertThat(comparisonResult.latencyDelta.best.get(0),equalTo(responseExample));

,其中

public List<ResponseExample> best;

为什么我会收到equalTo()的错误?

最好的第一项是ResponseExample

类型
Error:(62, 9) java: no suitable method found for assertThat(com.w.routing.automation.dataModel.examples.ResponseExample,com.google.common.base.Predicate<com.w.routing.automation.dataModel.examples.ResponseExample>)
    method org.junit.Assert.<T>assertThat(java.lang.String,T,org.hamcrest.Matcher<? super T>) is not applicable
      (cannot infer type-variable(s) T
        (actual and formal argument lists differ in length))
    method org.junit.Assert.<T>assertThat(T,org.hamcrest.Matcher<? super T>) is not applicable
      (no instance(s) of type variable(s) T exist so that com.google.common.base.Predicate<T> conforms to org.hamcrest.Matcher<? super T>)

1 个答案:

答案 0 :(得分:0)

我导入了“CoreMatchers”,我应该导入“Matcher”