5

私はFESTを使用して JUnit でアサーションを記述しています。

リストにいくつかの要素が含まれていると主張するのは簡単です。

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

しかし、リストに何かが含まれていないと断言するにはどうすればよいでしょうか? お気に入り:

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

1 に答える 1

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

containsおそらく、このような無茶な仮定をするべきではありませんが、それはあなたのメソッド ( ) と同じクラスにObjectGroupAssertあり、Javadoc はあなたが探している機能を説明しているようです。

だから私は、あなただけが必要だと思います:

assertThat(list).excludes(5,7);
于 2014-05-15T15:50:19.160 に答える