我想比较2所列出:Hamcrest比较集合
assertThat(actual.getList(), is(Matchers.containsInAnyOrder(expectedList)));
但想法
java: no suitable method found for assertThat(java.util.List<Agent>,org.hamcrest.Matcher<java.lang.Iterable<? extends model.Agents>>)
method org.junit.Assert.<T>assertThat(T,org.hamcrest.Matcher<T>) is not applicable
(no instance(s) of type variable(s) T exist so that argument type org.hamcrest.Matcher<java.lang.Iterable<? extends model.Agents>> conforms to formal parameter type org.hamcrest.Matcher<T>)
method org.junit.Assert.<T>assertThat(java.lang.String,T,org.hamcrest.Matcher<T>) is not applicable
(cannot instantiate from arguments because actual and formal argument lists differ in length)
我应该怎么写呢?
对于“如果你真的想用列表的内容调用同样的方法”+1。可悲的是,我无法让自己解决。特别是有一个构造函数需要一个集合。 –
@Tim不完全; 'containsInAnyOrder'要求* all *元素存在,所以第一个断言将失败。如果您想检查*至少*这些元素是否存在,请参阅'hasItems'。 – Joe
是的,你是对的 – Tim