HttpClientMock icon indicating copy to clipboard operation
HttpClientMock copied to clipboard

Feature: Reuse HttpClientResponseBuilder for verification

Open ipichris opened this issue 5 years ago • 3 comments

Currently i have to rewrite the mock rule to verify the number of calls. I.e.:

mock.onPost().withPath(Matchers.containsString("/something")).doReturn(HttpStatus.SC_OK, "777");
[...]
mock.verify().post().withPath(Matchers.containsString("/something")).called(1);

Especially when using complex rules this is time consuming and a maintenance issue. I would like to reuse the rule, for example like this:

HttpClientResponseBuilder builder = mock.onPost().withPath(Matchers.containsString("/something")).doReturn(HttpStatus.SC_OK, "777");;
[...]
mock.verify(builder).called(1);

ipichris avatar Jan 19 '21 12:01 ipichris

Hi @ipichris Thanks for finding that issues. I will try to look on it during the weekend.

PawelAdamski avatar Jan 27 '21 06:01 PawelAdamski

Using HttpClientResponseBuilder in the way as you presented is not possible because it contains a definition of all the rules and actions. So if you would pass it to verify you don't know which rule should be verified.

I have a different proposition.

Rule something = Rule.onPost().withPath(Matchers.containsString("/something"))
mock.on(something).doReturn(HttpStatus.SC_OK, "777")
[...]
mock.verifiy(something).called(1)

What do you think about it @ipichris ?

PawelAdamski avatar Feb 03 '21 20:02 PawelAdamski

Hi @PawelAdamski

Thx for your reply. Your proposition looks perfectly fine for me.

Keep up the good work!

ipichris avatar Feb 04 '21 07:02 ipichris