假设我有
@Test
public void iterable_matches_order () {
List<String> cloths = Lists.newArrayList("shirts", "shoes", "pants", "socks");
assertThat(cloths, containsInAnyOrder("shi", "sho", "pan", "soc"));
}
我希望通过,因为
shi
包含在shirts
中,sho
包含在shoes
中,依此类推。 containsInAnyOrder
仅在每个条目完全匹配时才通过。 最佳答案
根据文档:http://hamcrest.org/JavaHamcrest/javadoc/1.3/org/hamcrest/Matchers.html#containsInAnyOrder(T...)它不匹配子字符串,而是整个字符串assertThat(Arrays.asList("foo", "bar"), containsInAnyOrder("bar", "foo"))