|
40 | 40 | import java.util.Map; |
41 | 41 |
|
42 | 42 | import static org.junit.Assert.*; |
| 43 | +import static org.mockito.ArgumentMatchers.any; |
| 44 | +import static org.mockito.ArgumentMatchers.anyBoolean; |
43 | 45 | import static org.mockito.Mockito.verify; |
44 | 46 | import static org.mockito.Mockito.when; |
45 | 47 |
|
@@ -82,6 +84,20 @@ public void testRequestQueryString() throws Exception { |
82 | 84 | verify(clientInterfaceMock).request("/companies/adyen/merchants", null, null, false, null, ApiConstants.HttpMethod.GET, queryString); |
83 | 85 | } |
84 | 86 |
|
| 87 | + @Test |
| 88 | + public void testNonJsonError() throws Exception { |
| 89 | + Map<String, String> pathParams = Collections.singletonMap("companyId", "adyen"); |
| 90 | + Map<String, String> queryString = Collections.singletonMap("pageSize", "10"); |
| 91 | + Resource resource = new Resource(serviceMock, "/companies/{companyId}/merchants", null); |
| 92 | + |
| 93 | + HTTPClientException error = new HTTPClientException(500, "error", Collections.emptyMap(), "not JSON"); |
| 94 | + when(clientInterfaceMock.request(any(), any(), any(), anyBoolean(), any(), any(), any())).thenThrow(error); |
| 95 | + |
| 96 | + ApiException thrown = assertThrows(ApiException.class, () -> resource.request(null, null, ApiConstants.HttpMethod.GET, pathParams, queryString)); |
| 97 | + assertEquals("not JSON", thrown.getResponseBody()); |
| 98 | + assertNull(thrown.getError()); |
| 99 | + } |
| 100 | + |
85 | 101 | @Test |
86 | 102 | public void testRequestExceptionEmpty() throws IOException, HTTPClientException { |
87 | 103 | try { |
|
0 commit comments