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 and Description |
---|
HttpStub(Collection<org.hamcrest.Matcher<? super Request>> predicates,
Responder responder) |
Modifier and Type | Method and Description |
---|---|
String |
describeMismatch(Request request)
Returns a reason why the given request doesn't match this rule.
|
boolean |
matches(Request request) |
StubResponse |
nextResponse(Request request) |
String |
toString() |
public HttpStub(Collection<org.hamcrest.Matcher<? super Request>> predicates, Responder responder)
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 responsespublic boolean matches(Request request)
request
- an http request to be checked whether it matches this stub rule.true
if and only if all predicates defined in this rule were evaluated to true
by the given request.public StubResponse nextResponse(Request request)
request
- an http request the stub response will be generated forResponder
instance provided in
HttpStub(java.util.Collection, net.jadler.stubbing.Responder)
public String describeMismatch(Request request)
matches(net.jadler.Request)
would return false
. However, this is not checked.request
- an http request to describe the mismatch forCopyright © 2016. All Rights Reserved.