如何使用FEST声明列表不包含某些内容?

Fre*_*ind 5 java testing fest

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

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

assertThat(list).contains(2,4);
Run Code Online (Sandbox Code Playgroud)

但是如何断言列表中没有包含某些内容?喜欢:

assertThat(list).doesnotContain(3); // !!! no such method
Run Code Online (Sandbox Code Playgroud)

Dan*_*ple 9

我刚刚浏览了版本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();
}
Run Code Online (Sandbox Code Playgroud)

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

所以我想,你只需要:

assertThat(list).excludes(5,7);
Run Code Online (Sandbox Code Playgroud)