Clone wiki

fakehttpserver / Request_Matchers

Request Matchers

What is it

A RequestMatcher is an object which decides whether a request matches a specific expectation. It could be the request path, content-type, or anything else you can get from a HttpServletRequest.

How do I use it

When you add an expectation, you do the following:

new Expectations() {{
  oneOf(server).post().with(...);
}};

where ... is where you add all your RequestMatchers.

se.dannej.fakehttpserver.expect.matcher.RequestMatchers has a few standard RequestMatchers.

How do I write my own

All you have to do is extend abstract class se.dannej.fakehttpserver.expect.matcher.RequestMatcher. RequestMatcher is a hamcrest Matcher that matches FakeHttpServletRequest objects.

Note on the request inputstream: since the inputstream can only be read ones, a method called getContent has been added to the given request. This method will give you the content as a byte array, and allows for multiple input stream matchers.

Updated