Java 如何使用FEST断言列表不包含某些内容?
我使用JUnit编写断言 很容易断言列表包含一些元素:Java 如何使用FEST断言列表不包含某些内容?,java,testing,fest,Java,Testing,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. *
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);
它起作用了!方法名
excludes
对meHuzzah来说有点意外!:)是的,excludes
对我来说也是新事物,我希望不包含
变体。但仔细想想,我喜欢排除,但它可能更适合包含,因为它是相对的部分,而不是包含。