PawelAdamski / HttpClientMock

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

Ability to set no Response Entity #39

Closed ipichris closed 3 years ago

ipichris commented 3 years ago

https://hc.apache.org/httpcomponents-core-ga/httpcore/apidocs/org/apache/http/HttpResponse.html#getEntity() => Returns: the response entity, or null if there is none

I couldn't find a way to use HttpClientMock to create an response without entity so i would get an null reponse from this method. I tried "doReturn(200, null)" but this results in an exception in Apache HttpClient

java.lang.IllegalArgumentException: Source string may not be null at org.apache.http.util.Args.notNull(Args.java:54) at org.apache.http.entity.StringEntity.<init>(StringEntity.java:65) at org.apache.http.entity.StringEntity.<init>(StringEntity.java:132) at com.github.paweladamski.httpclientmock.action.StringResponse.getResponse(StringResponse.java:40) at com.github.paweladamski.httpclientmock.Rule.nextResponse(Rule.java:43) at com.github.paweladamski.httpclientmock.HttpClientMock.getHttpResponse(HttpClientMock.java:273) at com.github.paweladamski.httpclientmock.HttpClientMock.doExecute(HttpClientMock.java:248)

PawelAdamski commented 3 years ago

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

PawelAdamski commented 3 years ago

I've added new method doReturnWithStatus which will set response status and no response entity. Old one doReturnStatus is marked as deprected.

PawelAdamski commented 3 years ago

New versions should be visible in Maven this week.

ipichris commented 3 years ago

Thank you very much, i will update when the new version is released.

ipichris commented 3 years ago

I just updated to 1.10.0 and it works as expected, thx again.