gpt4 book ai didi

java - 与 hamcrest 中的内容相反

转载 作者:行者123 更新时间:2023-12-02 09:21:23 25 4
gpt4 key购买 nike

包含的反义词是什么?

    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)));

_does_not_contains_any_of_应该是什么?

最佳答案

您可以通过以下方式组合三个内置匹配器:

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))));
}

执行此测试将为您提供:

Expected: every item is not one of {"a", "e", "f", "d"}
but: an item was "a"

关于java - 与 hamcrest 中的内容相反,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40001431/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com