Skip to content

Commit 76bcfc1

Browse files
authored
Merge pull request #96 from Adyen/apiexception-tostring
Implement ApiException.toString to become more verbose
2 parents 528927a + b7fb703 commit 76bcfc1

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

src/main/java/com/adyen/service/exception/ApiException.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/**
1+
/*
22
* ######
33
* ######
44
* ############ ####( ###### #####. ###### ############ ############
@@ -52,4 +52,9 @@ public int getStatusCode() {
5252
public void setStatusCode(int statusCode) {
5353
this.statusCode = statusCode;
5454
}
55+
56+
@Override
57+
public String toString() {
58+
return "ApiException{" + "error=" + error + ", statusCode=" + statusCode + ", message=" + getMessage() + '}';
59+
}
5560
}

src/test/java/com/adyen/PaymentTest.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import static org.junit.Assert.assertNotNull;
4444
import static org.junit.Assert.assertNull;
4545
import static org.junit.Assert.assertTrue;
46+
import static org.junit.Assert.fail;
4647
import static org.mockito.ArgumentMatchers.any;
4748
import static org.mockito.Mockito.mock;
4849
import static org.mockito.Mockito.when;
@@ -96,8 +97,8 @@ public void TestAuthoriseError010Mocked() throws Exception {
9697
PaymentRequest paymentRequest = createFullCardPaymentRequest();
9798

9899
try {
99-
PaymentResult paymentResult = payment.authorise(paymentRequest);
100-
assertTrue("Exception expected", false);
100+
payment.authorise(paymentRequest);
101+
fail("Exception expected");
101102
} catch (ApiException e) {
102103
String errorCode = e.getError().getErrorCode();
103104
assertEquals("010", errorCode);
@@ -211,18 +212,17 @@ public void TestError401Mocked() throws Exception {
211212
PaymentRequest paymentRequest = createFullCardPaymentRequest();
212213

213214
try {
214-
PaymentResult paymentResult = payment.authorise(paymentRequest);
215-
assertTrue("Exception expected", false);
215+
payment.authorise(paymentRequest);
216+
fail("Exception expected");
216217
} catch (ApiException e) {
218+
assertTrue(e.toString().contains("401"));
217219
assertEquals(401, e.getStatusCode());
218220
assertNull(e.getError());
219221
}
220222
}
221223

222224
/**
223225
* Test OpenInvoice API flow for klarna
224-
*
225-
* @throws Exception
226226
*/
227227
@Test
228228
public void TestOpenInvoice() throws Exception {

0 commit comments

Comments
 (0)