From d17e8d5deab2b11131dc4b9bf42731d8c7c79009 Mon Sep 17 00:00:00 2001 From: Jeanderson Barros Candido <2225536+jeandersonbc@users.noreply.github.com> Date: Fri, 15 May 2026 10:38:55 +0200 Subject: [PATCH] chore: test coverage for mandates api --- .../com/adyen/DirectDebitMandatesTest.java | 179 ++++++++++++++++++ .../balancePlatform/ListMandatesResponse.json | 28 +++ .../mocks/balancePlatform/Mandate.json | 19 ++ 3 files changed, 226 insertions(+) create mode 100644 src/test/java/com/adyen/DirectDebitMandatesTest.java create mode 100644 src/test/resources/mocks/balancePlatform/ListMandatesResponse.json create mode 100644 src/test/resources/mocks/balancePlatform/Mandate.json diff --git a/src/test/java/com/adyen/DirectDebitMandatesTest.java b/src/test/java/com/adyen/DirectDebitMandatesTest.java new file mode 100644 index 000000000..eb52da335 --- /dev/null +++ b/src/test/java/com/adyen/DirectDebitMandatesTest.java @@ -0,0 +1,179 @@ +package com.adyen; + +import static org.junit.jupiter.api.Assertions.*; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.verify; + +import com.adyen.constants.ApiConstants; +import com.adyen.model.balanceplatform.*; +import com.adyen.service.balanceplatform.DirectDebitMandatesApi; +import java.util.HashMap; +import java.util.Map; +import org.junit.jupiter.api.Test; +import org.mockito.ArgumentCaptor; + +public class DirectDebitMandatesTest extends BaseTest { + + @Test + public void getMandateByIdTest() throws Exception { + Client client = createMockClientFromFile("mocks/balancePlatform/Mandate.json"); + DirectDebitMandatesApi service = new DirectDebitMandatesApi(client); + + Mandate response = service.getMandateById("MNDT000000000000000000000001"); + + assertNotNull(response); + assertEquals("MNDT000000000000000000000001", response.getId()); + assertEquals("BA000000000000000000000001", response.getBalanceAccountId()); + assertEquals("PI000000000000000000000001", response.getPaymentInstrumentId()); + assertEquals(MandateStatus.APPROVED, response.getStatus()); + assertEquals(MandateType.BACS, response.getType()); + verify(client.getHttpClient()) + .request( + "https://balanceplatform-api-test.adyen.com/bcl/v2/mandates/MNDT000000000000000000000001", + null, + client.getConfig(), + false, + null, + ApiConstants.HttpMethod.GET, + null); + } + + @Test + public void getMandateCounterpartyTest() throws Exception { + Client client = createMockClientFromFile("mocks/balancePlatform/Mandate.json"); + DirectDebitMandatesApi service = new DirectDebitMandatesApi(client); + + Mandate response = service.getMandateById("MNDT000000000000000000000001"); + + assertNotNull(response.getCounterparty()); + assertNotNull(response.getCounterparty().getAccountHolder()); + assertEquals("Albert Klassens", response.getCounterparty().getAccountHolder().getFullName()); + + MandateAccountIdentification accountIdentification = + response.getCounterparty().getAccountIdentification(); + assertNotNull(accountIdentification); + assertInstanceOf(UKLocalMandateAccountIdentification.class, accountIdentification); + + UKLocalMandateAccountIdentification ukIdentification = + (UKLocalMandateAccountIdentification) accountIdentification; + assertEquals("ukLocal", ukIdentification.getType()); + assertEquals("10809699", ukIdentification.getAccountNumber()); + assertEquals("405081", ukIdentification.getSortCode()); + } + + @Test + public void getListOfMandatesTest() throws Exception { + Client client = createMockClientFromFile("mocks/balancePlatform/ListMandatesResponse.json"); + DirectDebitMandatesApi service = new DirectDebitMandatesApi(client); + + ListMandatesResponse response = service.getListOfMandates(); + + assertNotNull(response); + assertNotNull(response.getMandates()); + assertEquals(1, response.getMandates().size()); + assertEquals("MNDT000000000000000000000001", response.getMandates().get(0).getId()); + assertNotNull(response.getLink()); + verify(client.getHttpClient()) + .request( + "https://balanceplatform-api-test.adyen.com/bcl/v2/mandates", + null, + client.getConfig(), + false, + null, + ApiConstants.HttpMethod.GET, + new HashMap<>()); + } + + @Test + public void getListOfMandatesWithQueryParamsTest() throws Exception { + Client client = createMockClientFromFile("mocks/balancePlatform/ListMandatesResponse.json"); + DirectDebitMandatesApi service = new DirectDebitMandatesApi(client); + + ListMandatesResponse response = + service.getListOfMandates( + "BA000000000000000000000001", "PI000000000000000000000001", null, null); + + assertNotNull(response); + assertEquals(1, response.getMandates().size()); + + ArgumentCaptor> queryParamsCaptor = ArgumentCaptor.captor(); + verify(client.getHttpClient()) + .request( + eq("https://balanceplatform-api-test.adyen.com/bcl/v2/mandates"), + eq(null), + eq(client.getConfig()), + eq(false), + eq(null), + eq(ApiConstants.HttpMethod.GET), + queryParamsCaptor.capture()); + + Map queryParams = queryParamsCaptor.getValue(); + assertEquals(2, queryParams.size()); + assertEquals("BA000000000000000000000001", queryParams.get("balanceAccountId")); + assertEquals("PI000000000000000000000001", queryParams.get("paymentInstrumentId")); + } + + @Test + public void getListOfMandatesWithCursorTest() throws Exception { + Client client = createMockClientFromFile("mocks/balancePlatform/ListMandatesResponse.json"); + DirectDebitMandatesApi service = new DirectDebitMandatesApi(client); + + service.getListOfMandates(null, null, "nextCursor", null); + + ArgumentCaptor> queryParamsCaptor = ArgumentCaptor.captor(); + verify(client.getHttpClient()) + .request( + eq("https://balanceplatform-api-test.adyen.com/bcl/v2/mandates"), + eq(null), + eq(client.getConfig()), + eq(false), + eq(null), + eq(ApiConstants.HttpMethod.GET), + queryParamsCaptor.capture()); + + Map queryParams = queryParamsCaptor.getValue(); + assertEquals(1, queryParams.size()); + assertEquals("nextCursor", queryParamsCaptor.getValue().get("cursor")); + } + + @Test + public void cancelMandateTest() throws Exception { + Client client = createMockClientFromResponse(""); + DirectDebitMandatesApi service = new DirectDebitMandatesApi(client); + + service.cancelMandate("MNDT000000000000000000000001"); + + verify(client.getHttpClient()) + .request( + "https://balanceplatform-api-test.adyen.com/bcl/v2/mandates/MNDT000000000000000000000001/cancel", + null, + client.getConfig(), + false, + null, + ApiConstants.HttpMethod.POST, + null); + } + + @Test + public void updateMandateTest() throws Exception { + Client client = createMockClientFromResponse(""); + DirectDebitMandatesApi service = new DirectDebitMandatesApi(client); + + MandateUpdate request = new MandateUpdate().paymentInstrumentId("PI000000000000000000000002"); + service.updateMandate("MNDT000000000000000000000001", request); + + ArgumentCaptor requestBodyCaptor = ArgumentCaptor.forClass(String.class); + verify(client.getHttpClient()) + .request( + eq( + "https://balanceplatform-api-test.adyen.com/bcl/v2/mandates/MNDT000000000000000000000001"), + requestBodyCaptor.capture(), + eq(client.getConfig()), + eq(false), + eq(null), + eq(ApiConstants.HttpMethod.PATCH), + eq(null)); + + assertEquals(request.toJson(), requestBodyCaptor.getValue()); + } +} diff --git a/src/test/resources/mocks/balancePlatform/ListMandatesResponse.json b/src/test/resources/mocks/balancePlatform/ListMandatesResponse.json new file mode 100644 index 000000000..479ee8a47 --- /dev/null +++ b/src/test/resources/mocks/balancePlatform/ListMandatesResponse.json @@ -0,0 +1,28 @@ +{ + "link": { + "next": { + "href": "https://balanceplatform-api-test.adyen.com/bcl/v2/mandates?cursor=nextCursor" + } + }, + "mandates": [ + { + "balanceAccountId": "BA000000000000000000000001", + "counterparty": { + "accountHolder": { + "fullName": "Albert Klassens" + }, + "accountIdentification": { + "accountNumber": "10809699", + "sortCode": "405081", + "type": "ukLocal" + } + }, + "createdAt": "2025-09-04T13:40:41.581Z", + "id": "MNDT000000000000000000000001", + "paymentInstrumentId": "PI000000000000000000000001", + "status": "approved", + "type": "bacs", + "updatedAt": "2025-09-04T13:40:41.581Z" + } + ] +} diff --git a/src/test/resources/mocks/balancePlatform/Mandate.json b/src/test/resources/mocks/balancePlatform/Mandate.json new file mode 100644 index 000000000..b1784453e --- /dev/null +++ b/src/test/resources/mocks/balancePlatform/Mandate.json @@ -0,0 +1,19 @@ +{ + "balanceAccountId": "BA000000000000000000000001", + "counterparty": { + "accountHolder": { + "fullName": "Albert Klassens" + }, + "accountIdentification": { + "accountNumber": "10809699", + "sortCode": "405081", + "type": "ukLocal" + } + }, + "createdAt": "2025-09-04T13:40:41.581Z", + "id": "MNDT000000000000000000000001", + "paymentInstrumentId": "PI000000000000000000000001", + "status": "approved", + "type": "bacs", + "updatedAt": "2025-09-04T13:40:41.581Z" +}