org.springframework.test.web.servlet.result

Class HeaderResultMatchers

  • java.lang.Object
    • org.springframework.test.web.servlet.result.HeaderResultMatchers


  • public class HeaderResultMatchers
    extends java.lang.Object
    Factory for response header assertions.

    An instance of this class is available via MockMvcResultMatchers.header().

    Since:
    3.2
    Author:
    Rossen Stoyanchev, Sam Brannen, Brian Clozel
    • Constructor Summary

      Constructors 
      Modifier Constructor and Description
      protected HeaderResultMatchers()
      Protected constructor.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method and Description
      ResultMatcher dateValue(java.lang.String name, long value)
      Assert the primary value of the named response header as a date String, using the preferred date format described in RFC 7231.
      ResultMatcher doesNotExist(java.lang.String name)
      Assert that the named response header does not exist.
      ResultMatcher exists(java.lang.String name)
      Assert that the named response header exists.
      ResultMatcher longValue(java.lang.String name, long value)
      Assert the primary value of the named response header as a long.
      ResultMatcher string(java.lang.String name, org.hamcrest.Matcher<? super java.lang.String> matcher)
      Assert the primary value of the response header with the given Hamcrest String Matcher.
      ResultMatcher string(java.lang.String name, java.lang.String value)
      Assert the primary value of the response header as a String value.
      <T> ResultMatcher stringValues(java.lang.String name, org.hamcrest.Matcher<java.lang.Iterable<java.lang.String>> matcher)
      Assert the values of the response header with the given Hamcrest Iterable Matcher.
      ResultMatcher stringValues(java.lang.String name, java.lang.String... values)
      Assert the values of the response header as String values.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • string

        public ResultMatcher string(java.lang.String name,
                                    org.hamcrest.Matcher<? super java.lang.String> matcher)
        Assert the primary value of the response header with the given Hamcrest String Matcher.
      • stringValues

        public <T> ResultMatcher stringValues(java.lang.String name,
                                              org.hamcrest.Matcher<java.lang.Iterable<java.lang.String>> matcher)
        Assert the values of the response header with the given Hamcrest Iterable Matcher.
        Since:
        4.3
      • string

        public ResultMatcher string(java.lang.String name,
                                    java.lang.String value)
        Assert the primary value of the response header as a String value.
      • stringValues

        public ResultMatcher stringValues(java.lang.String name,
                                          java.lang.String... values)
        Assert the values of the response header as String values.
        Since:
        4.3
      • exists

        public ResultMatcher exists(java.lang.String name)
        Assert that the named response header exists.
        Since:
        5.0.3
      • doesNotExist

        public ResultMatcher doesNotExist(java.lang.String name)
        Assert that the named response header does not exist.
        Since:
        4.0
      • longValue

        public ResultMatcher longValue(java.lang.String name,
                                       long value)
        Assert the primary value of the named response header as a long.

        The ResultMatcher returned by this method throws an AssertionError if the response does not contain the specified header, or if the supplied value does not match the primary value.

      • dateValue

        public ResultMatcher dateValue(java.lang.String name,
                                       long value)
        Assert the primary value of the named response header as a date String, using the preferred date format described in RFC 7231.

        The ResultMatcher returned by this method throws an AssertionError if the response does not contain the specified header, or if the supplied value does not match the primary value.

        Since:
        4.2
        See Also:
        Section 7.1.1.1 of RFC 7231