Skip to content

Commit eaa48de

Browse files
committed
Test response headers in exception
1 parent 9e072d4 commit eaa48de

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

src/test/java/com/adyen/service/ResourceTest.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import java.io.IOException;
3838
import java.util.Collections;
3939
import java.util.HashMap;
40+
import java.util.List;
4041
import java.util.Map;
4142
import org.junit.Before;
4243
import org.junit.Test;
@@ -199,4 +200,30 @@ public void testValidationExceptionWithInvalidJsonResponse() throws IOException
199200
assertNull(e.getError());
200201
}
201202
}
203+
204+
@Test
205+
public void testRequestException401WithWWWAuthenticateHeader()
206+
throws IOException, HTTPClientException {
207+
try {
208+
Map<String, List<String>> responseHeaders = new HashMap<>();
209+
responseHeaders.put("WWW-Authenticate", Collections.singletonList("abcd-1234-xywx-5678"));
210+
211+
when(clientInterfaceMock.request(
212+
"", "request", null, false, null, ApiConstants.HttpMethod.POST, null))
213+
.thenThrow(new HTTPClientException("Unauthorized", 401, responseHeaders, null));
214+
215+
Resource resource = new Resource(serviceMock, "", null);
216+
resource.request("request");
217+
218+
fail("Expected exception");
219+
} catch (ApiException e) {
220+
assertEquals(401, e.getStatusCode());
221+
assertNotNull(e.getResponseHeaders());
222+
assertTrue(e.getResponseHeaders().containsKey("WWW-Authenticate"));
223+
assertEquals(
224+
Collections.singletonList("abcd-1234-xywx-5678"),
225+
e.getResponseHeaders().get("WWW-Authenticate"));
226+
assertNull(e.getError());
227+
}
228+
}
202229
}

0 commit comments

Comments
 (0)