假设我有

@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"))

09-09 21:48