Class HttpStub


  • public class HttpStub
    extends Object

    An http stub is a WHEN-THEN pair (when an http request with specific properties arrives, then respond with a defined response).

    The WHEN part is a list of predicates (in form of Hamcrest matchers) applicable to a request. All of these matchers must be evaluated to true in order to apply the THEN part.

    The THEN part is defined by an instance of the Responder interface. This instance is capable of constructing stub http responses to be returned to the client.

    Instances of this class are thread-safe if and only if the provided Responder instance is thread-safe.

    One should never create new instances of this class directly,see Jadler for explanation and tutorial.

    • Constructor Detail

      • HttpStub

        public HttpStub​(Collection<org.hamcrest.Matcher<? super Request>> predicates,
                        Responder responder)
        Parameters:
        predicates - list of predicates. Cannot be null, however can be empty (which means this rule will match every request)
        responder - an instance to provide stub http responses
    • Method Detail

      • matches

        public boolean matches​(Request request)
        Parameters:
        request - an http request to be checked whether it matches this stub rule.
        Returns:
        true if and only if all predicates defined in this rule were evaluated to true by the given request.
      • describeMismatch

        public String describeMismatch​(Request request)
        Returns a reason why the given request doesn't match this rule. This method should be called if and only if matches(net.jadler.Request) would return false. However, this is not checked.
        Parameters:
        request - an http request to describe the mismatch for
        Returns:
        a human readable mismatch reason