gpt4 book ai didi

java - 如何使用 FEST 断言列表不包含某些内容?

转载 作者:搜寻专家 更新时间:2023-10-31 19:33:17 24 4
gpt4 key购买 nike

我正在使用 FEST在 JUnit 中编写断言。

断言列表包含一些元素很容易:

assertThat(list).contains(2,4);

但是如何断言列表不包含某些东西呢?喜欢:

assertThat(list).doesnotContain(3); // !!! no such method

最佳答案

我刚刚浏览了版本 1 分支的源代码,发现了这个:

/**
* Verifies that the actual group of objects does not contain the given objects.
*
* @param objects the objects that the group of objects should exclude.
* @return this assertion object.
* @throws AssertionError if the actual group of objects is {@code null}.
* @throws NullPointerException if the given array is {@code null}.
* @throws AssertionError if the actual group of objects contains any of the given objects.
*/
public final @Nonnull S excludes(@Nonnull Object... objects) {
assertExcludes(objects);
return myself();
}

我可能不应该做出这样的疯狂假设,但它与您的 contains 方法 (ObjectGroupAssert) 在同一个类中并且 Javadoc 似乎描述了您的功能正在寻找。

所以我认为,您只需要:

assertThat(list).excludes(5,7);

关于java - 如何使用 FEST 断言列表不包含某些内容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23681419/

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