PawelAdamski / HttpClientMock

Library for mocking Apache HttpClient.
MIT License
44 stars 9 forks source link

How can reture HTTP status message #29

Closed abhikt48 closed 3 years ago

abhikt48 commented 4 years ago

Hi Team,

I need to return specific HTTP status message instead of default ok.

E.g - 1. 409 - Conflict

  1. 400 Bad Request

i tried wth below code snippet but is returning 'ok' instead of 'conflict' while calling getStatusText() operation,.

httpClientMock.onPost("testUlr").doReturn(409, "some message");

Could you please suggest any way to set status text as well?

abhikt48 commented 4 years ago

I got one alternative for this problem to use Action. It is working fine for me.

Recomendation - I must recommend you to provide one doReturn override method which should accept status text as well.

PawelAdamski commented 4 years ago

Hi @abhikt48 You are right currently the only way to set statusText is by using "Action". To make that easier I will extend the method withStatus to accept reason parameter.

So the full usage will look like that: httpClientMock.onPost("testUlr").doReturn("some message").withStatus(409,"reason");

PawelAdamski commented 3 years ago

Will be fixed in the scope of https://github.com/PawelAdamski/HttpClientMock/issues/33