HttpClientMock icon indicating copy to clipboard operation
HttpClientMock copied to clipboard

Ability to set no Response Entity

Open ipichris opened this issue 1 year ago • 0 comments

We migrated to HttpClient 5 and HttpClientMock 2.1.1 and found an issue we already had for HttpClient 4 with HttpClientMock 1.9.0, see issue #39 -> For HttpClientMock 1.10.0 there was a new method doReturnWithStatus which didn't create a response object (an doReturnStatus was deprecated), however this method is not available in 2.1.1

Reproduce: We have several webservices that return a response without responseContent, usually there are responses with http 204 (NO CONTENT) If I'm specifying "null" as value for "doReturn" we get an exception from HttpClient 5: httpClientMock.onGet("http://localhost:3333").doReturn(204, null);

java.lang.NullPointerException: Source string
 at java.base/java.util.Objects.requireNonNull([Objects.java:235](vscode-file://vscode-app/c:/ige/ipi-vscode/versions/2024-06-27T15_08_36_stable/resources/app/out/vs/code/electron-sandbox/workbench/workbench.html))
 at org.apache.hc.core5.util.Args.notNull([Args.java:165](vscode-file://vscode-app/c:/ige/ipi-vscode/versions/2024-06-27T15_08_36_stable/resources/app/out/vs/code/electron-sandbox/workbench/workbench.html))
 at org.apache.hc.core5.http.io.entity.StringEntity.([StringEntity.java:69](vscode-file://vscode-app/c:/ige/ipi-vscode/versions/2024-06-27T15_08_36_stable/resources/app/out/vs/code/electron-sandbox/workbench/workbench.html))
 at com.github.paweladamski.httpclientmock.action.StringResponse.getResponse([StringResponse.java:24](vscode-file://vscode-app/c:/ige/ipi-vscode/versions/2024-06-27T15_08_36_stable/resources/app/out/vs/code/electron-sandbox/workbench/workbench.html))
 at com.github.paweladamski.httpclientmock.Rule.nextResponse([Rule.java:44](vscode-file://vscode-app/c:/ige/ipi-vscode/versions/2024-06-27T15_08_36_stable/resources/app/out/vs/code/electron-sandbox/workbench/workbench.html))
 at com.github.paweladamski.httpclientmock.HttpClientMock.getHttpResponse([HttpClientMock.java:297](vscode-file://vscode-app/c:/ige/ipi-vscode/versions/2024-06-27T15_08_36_stable/resources/app/out/vs/code/electron-sandbox/workbench/workbench.html))
 at com.github.paweladamski.httpclientmock.HttpClientMock.doExecute([HttpClientMock.java:251](vscode-file://vscode-app/c:/ige/ipi-vscode/versions/2024-06-27T15_08_36_stable/resources/app/out/vs/code/electron-sandbox/workbench/workbench.html))
 at org.apache.hc.client5.http.impl.classic.CloseableHttpClient.execute([CloseableHttpClient.java:123](vscode-file://vscode-app/c:/ige/ipi-vscode/versions/2024-06-27T15_08_36_stable/resources/app/out/vs/code/electron-sandbox/workbench/workbench.html))
 [...]

ipichris avatar Oct 03 '24 13:10 ipichris