HeaderResultMatchersのメソッド一覧

Pocket

■HandlerResultMatchersのメソッド一覧

public ResultMatcher string(final String name, final Matcher matcher) ヘッダーのキーに含まれる値をMatcherを使って検証する
実行例)headerの言語指定が英語(en)
MockMvcオブジェクト.perform(get("/")
    .andExpect(header().string("Content-Language", is("en")));
public ResultMatcher stringValues(final String name, final Matcher> matcher) ヘッダーのキーに含まれる値を、複数の文字列用Matcherを使って検証する
実行例)headerのコンテンツタイプに"text/html"と"utf-8"が含まれる
MockMvcオブジェクト.perform(get("/")
     .andExpect(header().stringValues("Content-Type", hasItems(containsString("text/html"), containsString("utf-8"))));
public ResultMatcher string(final String name, final String value) ヘッダーのキーに含まれる値を検証する
実行例)headerの言語指定が英語(en)
MockMvcオブジェクト.perform(get("/")
     .andExpect(header().string("Content-Language", "en"));
public ResultMatcher stringValues(final String name, final String… values) ヘッダーのキーに含まれる複数の値を検証する
実行例)headerに名前"key"で"val1"と"val2"の値が含まれる
※"text/html;utf-8"のような区切り文字を含めて1つの文字として扱う
MockMvcオブジェクト.perform(get("/")
    .andExpect(header().stringValues("key", "val1", "val2"));
public ResultMatcher exists(final String name) ヘッダーにキーが含まれるか検証する
実行例)ヘッダーにキー"Content-Type"が含まれる
MockMvcオブジェクト.perform(get("/")
    .andExpect(header().exists("Content-Type"));
public ResultMatcher doesNotExist(final String name) ヘッダーにキーが含まれないか検証する
実行例)ヘッダーにキー"Content-Type"が含まれない
MockMvcオブジェクト.perform(get("/")
    .andExpect(header().exists("Content-Type"));
public ResultMatcher longValue(final String name, final long value) ヘッダーのキーに含まれるlong値を検証する
実行例)ヘッダーにキー"key"で数値"1524331609062L"が含まれる
MockMvcオブジェクト.perform(get("/")
    .andExpect(header().longValue("key", 1524331609062L));
public ResultMatcher dateValue(final String name, final long value) ヘッダーのキーに含まれる日付(long)値を検証する
実行例)ヘッダーにキー"key"で日付"Sat, 21 Apr 2018 17:26:49 GMT"(1524331609062L)が含まれる
MockMvcオブジェクト.perform(get("/")
    .andExpect(header().dateValue("key", 1524331609062L));
広告

Pocket