MockClient: allow fine grained request verification or "un-expected" routes
JamesBoon opened this issue · 2 comments
Is your feature request related to a problem? Please describe.
I am using the MockClient in integration tests and have to mock multiple routes that are not part of the actual test. They should not be part of the verification when calling mockClient.verifyAll()
.
Using mockClient.defaultResponse()
is not an option, as different calls return different responses.
Describe the solution you'd like
Allow to mock routes like mockClient.expect(...)
but do not include them in mockClient.verifyAll()
.
Something like:
// required by tested service
mockClient.route(HttpMethod.POST, "http://localhost/auth")
.thenReturn(...)
.withStatus(200);
// only this will be part of "verifyAll"
mockClient.expect(HttpMethod.GET, "http://localhost/something")
.thenReturn(...)
.withStatus(200);
// ... call to tested service
mockClient.verifyAll();
Describe alternatives you've considered
Allow to verify a specific request.
Something like:
Assert clientAssert = mockClient.expect(...)
.thenReturn(...)
.getAssert();
// ... call to tested service
clientAssert.verifyAll();
the good news is, these methods already exist, they just were not exposed on the interfaces. So I've exposed the singular "verify" method on both the Expectation and ExpectedResponse interfaces. See the commit tagged in this issue for some tests showing usage.
I just released 4.2.1 that has this change, it should show up in Maven Central in the next hour or so.
Thanks, that works as expected 🙂