我想比较2个列表:
assertThat(actual.getList(), is(Matchers.containsInAnyOrder(expectedList)));
Run Code Online (Sandbox Code Playgroud)
但想法
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)
Run Code Online (Sandbox Code Playgroud)
我该怎么写呢?
我认为这应该是一个非常简单的问题.但不知何故,我无法在谷歌找到答案.
假设我有2个字符串列表.首先包含"字符串A"和"字符串B",第二个包含"字符串B"和"字符串A"(按顺序通知差异).我想用JUnit测试它们以检查它们是否包含完全相同的字符串.
是否有任何断言检查忽略顺序的字符串的相等性?对于给定的示例org.junit.Assert.assertEquals抛出AssertionError
java.lang.AssertionError: expected:<[String A, String B]> but was:<[String B, String A]>
Run Code Online (Sandbox Code Playgroud)
解决方法是首先对列表进行排序,然后将它们传递给断言.但我希望我的代码尽可能简单和干净.
我使用Hamcrest 1.3,JUnit 4.11,Mockito 1.9.5.