Package net.jadler.matchers
Class RequestMatcher<T>
- java.lang.Object
-
- org.hamcrest.BaseMatcher<Request>
-
- net.jadler.matchers.RequestMatcher<T>
-
- Type Parameters:
T- type of the value retrieved from the given request to be matched
- All Implemented Interfaces:
org.hamcrest.Matcher<Request>,org.hamcrest.SelfDescribing
- Direct Known Subclasses:
BodyRequestMatcher,HeaderRequestMatcher,MethodRequestMatcher,ParameterRequestMatcher,PathRequestMatcher,QueryStringRequestMatcher,RawBodyRequestMatcher
public abstract class RequestMatcher<T> extends org.hamcrest.BaseMatcher<Request>
Convenient base class for all Jadler request matchers.
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedRequestMatcher(org.hamcrest.Matcher<? super T> pred)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voiddescribeMismatch(Object item, org.hamcrest.Description description)voiddescribeTo(org.hamcrest.Description description)booleanmatches(Object o)Checks whether the givenRequestobject matches this matcher.protected abstract StringprovideDescription()Provides a description of this matcher in form of a string consisting of "noun verb", where noun describes the value retrieved usingretrieveValue(net.jadler.Request)and verb is usually a correct form of to be.protected abstract TretrieveValue(Request req)Reads a value of the given request object (the value can be anything retrievable from the request object: method, header, body,...).
-
-
-
Field Detail
-
pred
protected final org.hamcrest.Matcher<? super T> pred
-
-
Constructor Detail
-
RequestMatcher
protected RequestMatcher(org.hamcrest.Matcher<? super T> pred)
- Parameters:
pred- predicate to be applied on the value retrieved from the given request (cannot benull)
-
-
Method Detail
-
describeMismatch
public void describeMismatch(Object item, org.hamcrest.Description description)
-
describeTo
public void describeTo(org.hamcrest.Description description)
-
matches
public boolean matches(Object o)
Checks whether the givenRequestobject matches this matcher.- Parameters:
o-Requestobject to be matched by this matcher. If this param is not of typeRequestthis method will always returnfalse.- Returns:
trueif the value retrieved usingretrieveValue(net.jadler.Request)from the givenRequestobject matches the predicate registered by theRequestMatcher(org.hamcrest.Matcher), otherwisefalse.
-
retrieveValue
protected abstract T retrieveValue(Request req) throws Exception
Reads a value of the given request object (the value can be anything retrievable from the request object: method, header, body,...).- Parameters:
req- request object to read a value from- Returns:
- a value retrieved from the given request object.
- Throws:
Exception- when something goes wrong. This exception will be handler correctly by Jadler.
-
provideDescription
protected abstract String provideDescription()
Provides a description of this matcher in form of a string consisting of "noun verb", where noun describes the value retrieved using
retrieveValue(net.jadler.Request)and verb is usually a correct form of to be.If the
retrieveValue(net.jadler.Request)provided a request method, this method would return method is string for example.- Returns:
- matcher description
-
-