Skip to content

Commit 2d2d92f

Browse files
committed
chore: test coverage for mandates api
1 parent 6095e8b commit 2d2d92f

3 files changed

Lines changed: 213 additions & 0 deletions

File tree

Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
package com.adyen;
2+
3+
import static org.junit.jupiter.api.Assertions.*;
4+
import static org.mockito.ArgumentMatchers.eq;
5+
import static org.mockito.Mockito.verify;
6+
7+
import com.adyen.constants.ApiConstants;
8+
import com.adyen.model.balanceplatform.*;
9+
import com.adyen.service.balanceplatform.DirectDebitMandatesApi;
10+
import java.util.HashMap;
11+
import java.util.Map;
12+
import org.junit.jupiter.api.Test;
13+
import org.mockito.ArgumentCaptor;
14+
15+
public class DirectDebitMandatesTest extends BaseTest {
16+
17+
@Test
18+
public void getMandateByIdTest() throws Exception {
19+
Client client = createMockClientFromFile("mocks/balancePlatform/Mandate.json");
20+
DirectDebitMandatesApi service = new DirectDebitMandatesApi(client);
21+
22+
Mandate response = service.getMandateById("MNDT000000000000000000000001");
23+
24+
assertNotNull(response);
25+
assertEquals("MNDT000000000000000000000001", response.getId());
26+
assertEquals("BA000000000000000000000001", response.getBalanceAccountId());
27+
assertEquals("PI000000000000000000000001", response.getPaymentInstrumentId());
28+
assertEquals(MandateStatus.APPROVED, response.getStatus());
29+
assertEquals(MandateType.BACS, response.getType());
30+
verify(client.getHttpClient())
31+
.request(
32+
"https://balanceplatform-api-test.adyen.com/bcl/v2/mandates/MNDT000000000000000000000001",
33+
null,
34+
client.getConfig(),
35+
false,
36+
null,
37+
ApiConstants.HttpMethod.GET,
38+
null);
39+
}
40+
41+
@Test
42+
public void getMandateCounterpartyTest() throws Exception {
43+
Client client = createMockClientFromFile("mocks/balancePlatform/Mandate.json");
44+
DirectDebitMandatesApi service = new DirectDebitMandatesApi(client);
45+
46+
Mandate response = service.getMandateById("MNDT000000000000000000000001");
47+
48+
assertNotNull(response.getCounterparty());
49+
assertNotNull(response.getCounterparty().getAccountHolder());
50+
assertEquals("Albert Klassens", response.getCounterparty().getAccountHolder().getFullName());
51+
assertNotNull(response.getCounterparty().getAccountIdentification());
52+
}
53+
54+
@Test
55+
public void getListOfMandatesTest() throws Exception {
56+
Client client = createMockClientFromFile("mocks/balancePlatform/ListMandatesResponse.json");
57+
DirectDebitMandatesApi service = new DirectDebitMandatesApi(client);
58+
59+
ListMandatesResponse response = service.getListOfMandates();
60+
61+
assertNotNull(response);
62+
assertNotNull(response.getMandates());
63+
assertEquals(1, response.getMandates().size());
64+
assertEquals("MNDT000000000000000000000001", response.getMandates().get(0).getId());
65+
assertNotNull(response.getLink());
66+
verify(client.getHttpClient())
67+
.request(
68+
"https://balanceplatform-api-test.adyen.com/bcl/v2/mandates",
69+
null,
70+
client.getConfig(),
71+
false,
72+
null,
73+
ApiConstants.HttpMethod.GET,
74+
new HashMap<>());
75+
}
76+
77+
@Test
78+
public void getListOfMandatesWithQueryParamsTest() throws Exception {
79+
Client client = createMockClientFromFile("mocks/balancePlatform/ListMandatesResponse.json");
80+
DirectDebitMandatesApi service = new DirectDebitMandatesApi(client);
81+
82+
ListMandatesResponse response =
83+
service.getListOfMandates(
84+
"BA000000000000000000000001", "PI000000000000000000000001", null, null);
85+
86+
assertNotNull(response);
87+
assertEquals(1, response.getMandates().size());
88+
89+
ArgumentCaptor<Map<String, String>> queryParamsCaptor = ArgumentCaptor.forClass(Map.class);
90+
verify(client.getHttpClient())
91+
.request(
92+
eq("https://balanceplatform-api-test.adyen.com/bcl/v2/mandates"),
93+
eq(null),
94+
eq(client.getConfig()),
95+
eq(false),
96+
eq(null),
97+
eq(ApiConstants.HttpMethod.GET),
98+
queryParamsCaptor.capture());
99+
100+
Map<String, String> queryParams = queryParamsCaptor.getValue();
101+
assertEquals("BA000000000000000000000001", queryParams.get("balanceAccountId"));
102+
assertEquals("PI000000000000000000000001", queryParams.get("paymentInstrumentId"));
103+
}
104+
105+
@Test
106+
public void getListOfMandatesWithCursorTest() throws Exception {
107+
Client client = createMockClientFromFile("mocks/balancePlatform/ListMandatesResponse.json");
108+
DirectDebitMandatesApi service = new DirectDebitMandatesApi(client);
109+
110+
service.getListOfMandates(null, null, "nextCursor", null);
111+
112+
ArgumentCaptor<Map<String, String>> queryParamsCaptor = ArgumentCaptor.forClass(Map.class);
113+
verify(client.getHttpClient())
114+
.request(
115+
eq("https://balanceplatform-api-test.adyen.com/bcl/v2/mandates"),
116+
eq(null),
117+
eq(client.getConfig()),
118+
eq(false),
119+
eq(null),
120+
eq(ApiConstants.HttpMethod.GET),
121+
queryParamsCaptor.capture());
122+
123+
assertEquals("nextCursor", queryParamsCaptor.getValue().get("cursor"));
124+
}
125+
126+
@Test
127+
public void cancelMandateTest() throws Exception {
128+
Client client = createMockClientFromResponse("");
129+
DirectDebitMandatesApi service = new DirectDebitMandatesApi(client);
130+
131+
service.cancelMandate("MNDT000000000000000000000001");
132+
133+
verify(client.getHttpClient())
134+
.request(
135+
"https://balanceplatform-api-test.adyen.com/bcl/v2/mandates/MNDT000000000000000000000001/cancel",
136+
null,
137+
client.getConfig(),
138+
false,
139+
null,
140+
ApiConstants.HttpMethod.POST,
141+
null);
142+
}
143+
144+
@Test
145+
public void updateMandateTest() throws Exception {
146+
Client client = createMockClientFromResponse("");
147+
DirectDebitMandatesApi service = new DirectDebitMandatesApi(client);
148+
149+
MandateUpdate request = new MandateUpdate().paymentInstrumentId("PI000000000000000000000002");
150+
service.updateMandate("MNDT000000000000000000000001", request);
151+
152+
ArgumentCaptor<String> requestBodyCaptor = ArgumentCaptor.forClass(String.class);
153+
verify(client.getHttpClient())
154+
.request(
155+
eq(
156+
"https://balanceplatform-api-test.adyen.com/bcl/v2/mandates/MNDT000000000000000000000001"),
157+
requestBodyCaptor.capture(),
158+
eq(client.getConfig()),
159+
eq(false),
160+
eq(null),
161+
eq(ApiConstants.HttpMethod.PATCH),
162+
eq(null));
163+
164+
assertEquals(request.toJson(), requestBodyCaptor.getValue());
165+
}
166+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"link": {
3+
"next": {
4+
"href": "https://balanceplatform-api-test.adyen.com/bcl/v2/mandates?cursor=nextCursor"
5+
}
6+
},
7+
"mandates": [
8+
{
9+
"balanceAccountId": "BA000000000000000000000001",
10+
"counterparty": {
11+
"accountHolder": {
12+
"fullName": "Albert Klassens"
13+
},
14+
"accountIdentification": {
15+
"accountNumber": "10809699",
16+
"sortCode": "405081",
17+
"type": "ukLocal"
18+
}
19+
},
20+
"createdAt": "2025-09-04T13:40:41.581Z",
21+
"id": "MNDT000000000000000000000001",
22+
"paymentInstrumentId": "PI000000000000000000000001",
23+
"status": "approved",
24+
"type": "bacs",
25+
"updatedAt": "2025-09-04T13:40:41.581Z"
26+
}
27+
]
28+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"balanceAccountId": "BA000000000000000000000001",
3+
"counterparty": {
4+
"accountHolder": {
5+
"fullName": "Albert Klassens"
6+
},
7+
"accountIdentification": {
8+
"accountNumber": "10809699",
9+
"sortCode": "405081",
10+
"type": "ukLocal"
11+
}
12+
},
13+
"createdAt": "2025-09-04T13:40:41.581Z",
14+
"id": "MNDT000000000000000000000001",
15+
"paymentInstrumentId": "PI000000000000000000000001",
16+
"status": "approved",
17+
"type": "bacs",
18+
"updatedAt": "2025-09-04T13:40:41.581Z"
19+
}

0 commit comments

Comments
 (0)