包含的相反之处是什么?
List<String> list = Arrays.asList("b", "a", "c");
// should fail, because "d" is not in the list
expectedInList = new String[]{"a","b", "c", "d"};
Assert.assertThat(list, Matchers.contains(expectedInList));
// should fail, because a IS in the list
shouldNotBeInList = Arrays.asList("a","e", "f", "d");
Assert.assertThat(list, _does_not_contains_any_of_(shouldNotBeInList)));
Run Code Online (Sandbox Code Playgroud)
应该是_does_not_contains_any_of_什么?
eee*_*eee 12
您可以通过以下方式组合三个内置匹配器:
import static org.hamcrest.Matchers.everyItem;
import static org.hamcrest.Matchers.isIn;
import static org.hamcrest.Matchers.not;
@Test
public void hamcrestTest() throws Exception {
List<String> list = Arrays.asList("b", "a", "c");
List<String> shouldNotBeInList = Arrays.asList("a", "e", "f", "d");
Assert.assertThat(list, everyItem(not(isIn(shouldNotBeInList))));
}
Run Code Online (Sandbox Code Playgroud)
执行此测试将为您提供:
预期:每个项目都不是{"a","e","f","d"}之一
但是:项目是"a"
| 归档时间: |
|
| 查看次数: |
6706 次 |
| 最近记录: |