diff --git a/src/test/java/it/gov/pagopa/gpd/payments/pull/resources/PaymentNoticesTest.java b/src/test/java/it/gov/pagopa/gpd/payments/pull/resources/PaymentNoticesTest.java index 4a31ae8..c04ad50 100644 --- a/src/test/java/it/gov/pagopa/gpd/payments/pull/resources/PaymentNoticesTest.java +++ b/src/test/java/it/gov/pagopa/gpd/payments/pull/resources/PaymentNoticesTest.java @@ -4,7 +4,6 @@ import com.fasterxml.jackson.databind.ObjectMapper; import io.quarkus.test.InjectMock; import io.quarkus.test.junit.QuarkusTest; -import io.smallrye.mutiny.Uni; import it.gov.pagopa.gpd.payments.pull.models.ErrorResponse; import it.gov.pagopa.gpd.payments.pull.models.PaymentNotice; import it.gov.pagopa.gpd.payments.pull.models.enums.AppErrorCodeEnum; @@ -21,8 +20,8 @@ import static jakarta.ws.rs.core.Response.Status.INTERNAL_SERVER_ERROR; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; @QuarkusTest class PaymentNoticesTest { @@ -35,8 +34,8 @@ class PaymentNoticesTest { @Test void getPaymentNoticesOnValidTaxCodeShouldReturnData() throws JsonProcessingException { - doReturn(Uni.createFrom().item(Collections.singletonList(PaymentNotice.builder().build()))) - .when(paymentNoticesService).getPaymentNotices(FISCAL_CODE, null, 50, 0); + when(paymentNoticesService.getPaymentNotices(FISCAL_CODE, null, 50, 0)) + .thenReturn(Collections.singletonList(PaymentNotice.builder().build())); String responseString = given() .header("x-tax-code", FISCAL_CODE) @@ -58,8 +57,8 @@ void getPaymentNoticesOnValidTaxCodeShouldReturnData() throws JsonProcessingExce @Test void getPaymentNoticesOnValidTaxCodeAndDateShouldReturnData() throws JsonProcessingException { - doReturn(Uni.createFrom().item(Collections.singletonList(PaymentNotice.builder().build()))) - .when(paymentNoticesService).getPaymentNotices(FISCAL_CODE, DUE_DATE, 50, 0); + when(paymentNoticesService.getPaymentNotices(FISCAL_CODE, DUE_DATE, 50, 0)) + .thenReturn(Collections.singletonList(PaymentNotice.builder().build())); String responseString = given() .header("x-tax-code", FISCAL_CODE) @@ -104,9 +103,8 @@ void getPaymentNoticesOnValidTaxCodeAndDateShouldReturnData() throws JsonProcess @Test void getPaymentNoticesOnServiceErrorShouldReturnIntServerError() throws JsonProcessingException { - doReturn(Uni.createFrom().item(() -> { - throw new RuntimeException(); - })).when(paymentNoticesService).getPaymentNotices(FISCAL_CODE, DUE_DATE, 50, 0); + when(paymentNoticesService.getPaymentNotices(FISCAL_CODE, DUE_DATE, 50, 0)) + .thenThrow(RuntimeException.class); String responseString = given() .header("x-tax-code", FISCAL_CODE) @@ -150,7 +148,6 @@ void getPaymentNoticesOnMissingTaxCodeShouldReturnBadRequest() throws JsonProces assertNotNull(response.getTitle()); } - @Test void getPaymentNoticesOnValidTaxCodeAndInvalidDateShouldBadRequest() throws JsonProcessingException { String responseString = @@ -174,5 +171,4 @@ void getPaymentNoticesOnValidTaxCodeAndInvalidDateShouldBadRequest() throws Json assertNotNull(response.getDetail()); assertNotNull(response.getTitle()); } - } diff --git a/src/test/java/it/gov/pagopa/gpd/payments/pull/service/impl/PaymentNoticesServiceImplTest.java b/src/test/java/it/gov/pagopa/gpd/payments/pull/service/impl/PaymentNoticesServiceImplTest.java index 46930bf..11a64a9 100644 --- a/src/test/java/it/gov/pagopa/gpd/payments/pull/service/impl/PaymentNoticesServiceImplTest.java +++ b/src/test/java/it/gov/pagopa/gpd/payments/pull/service/impl/PaymentNoticesServiceImplTest.java @@ -3,7 +3,6 @@ import io.quarkus.test.InjectMock; import io.quarkus.test.junit.QuarkusTest; import io.smallrye.mutiny.CompositeException; -import io.smallrye.mutiny.Uni; import it.gov.pagopa.gpd.payments.pull.entity.PaymentOption; import it.gov.pagopa.gpd.payments.pull.entity.PaymentPosition; import it.gov.pagopa.gpd.payments.pull.exception.PaymentNoticeException; @@ -27,8 +26,8 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; @QuarkusTest class PaymentNoticesServiceImplTest { @@ -41,13 +40,14 @@ class PaymentNoticesServiceImplTest { @Test void getPaymentNoticesShouldReturnOK() { - doReturn(Uni.createFrom().item(Arrays.asList(createPaymentPosition("", false), - createPaymentPosition("ACA_", false), - createPaymentPosition("PARTIAL_", true)))) - .when(paymentPositionRepository).findPaymentPositionsByTaxCodeAndDueDate - (FISCAL_CODE, DUE_DATE, 50, 0); + when(paymentPositionRepository.findPaymentPositionsByTaxCodeAndDueDate(FISCAL_CODE, DUE_DATE, 50, 0)) + .thenReturn(Arrays.asList(createPaymentPosition("", false), + createPaymentPosition("ACA_", false), + createPaymentPosition("PARTIAL_", true))); + List response = assertDoesNotThrow(() -> - paymentNoticesService.getPaymentNotices(FISCAL_CODE, DUE_DATE, 50, 0)); + paymentNoticesService.getPaymentNotices(FISCAL_CODE, DUE_DATE, 50, 0)); + assertNotNull(response); assertEquals(2, response.size()); assertEquals("iupd", response.get(0).getIupd()); @@ -60,44 +60,45 @@ void getPaymentNoticesShouldReturnOK() { @Test void getPaymentNoticesShouldReturnExceptionOnRepositoryError() { - doReturn(Uni.createFrom().item(() -> { - throw new RuntimeException(); - })).when(paymentPositionRepository).findPaymentPositionsByTaxCodeAndDueDate - (FISCAL_CODE, DUE_DATE, 50, 0); + when(paymentPositionRepository.findPaymentPositionsByTaxCodeAndDueDate(FISCAL_CODE, DUE_DATE, 50, 0)) + .thenThrow(RuntimeException.class); + CompositeException paymentNoticeException = assertThrows(CompositeException.class, () -> - paymentNoticesService.getPaymentNotices(FISCAL_CODE, DUE_DATE, 50, 0)); + paymentNoticesService.getPaymentNotices(FISCAL_CODE, DUE_DATE, 50, 0)); + List causes = paymentNoticeException.getCauses(); - assertEquals(AppErrorCodeEnum.PPL_800, ((PaymentNoticeException) causes.get(causes.size()-1)).getErrorCode()); + assertEquals(AppErrorCodeEnum.PPL_800, ((PaymentNoticeException) causes.get(causes.size() - 1)).getErrorCode()); } @Test void getPaymentNoticesShouldReturnExceptionOnMappingError() { PaymentPosition paymentPosition = createPaymentPosition("", true); paymentPosition.setPaymentOption(null); - doReturn(Uni.createFrom().item(Collections.singletonList(paymentPosition))) - .when(paymentPositionRepository).findPaymentPositionsByTaxCodeAndDueDate - (FISCAL_CODE, DUE_DATE, 50, 0); + when(paymentPositionRepository.findPaymentPositionsByTaxCodeAndDueDate(FISCAL_CODE, DUE_DATE, 50, 0)) + .thenReturn(Collections.singletonList(paymentPosition)); + CompositeException paymentNoticeException = assertThrows(CompositeException.class, () -> - paymentNoticesService.getPaymentNotices(FISCAL_CODE, DUE_DATE, 50, 0)); + paymentNoticesService.getPaymentNotices(FISCAL_CODE, DUE_DATE, 50, 0)); + List causes = paymentNoticeException.getCauses(); - assertEquals(AppErrorCodeEnum.PPL_800, ((PaymentNoticeException) causes.get(causes.size()-1)).getErrorCode()); + assertEquals(AppErrorCodeEnum.PPL_800, ((PaymentNoticeException) causes.get(causes.size() - 1)).getErrorCode()); } - PaymentPosition createPaymentPosition(String prefix, Boolean isPartialPayment) { + private PaymentPosition createPaymentPosition(String prefix, Boolean isPartialPayment) { PaymentPosition paymentPosition = PaymentPosition.builder() - .iupd(prefix+"iupd") + .iupd(prefix + "iupd") .status(DebtPositionStatus.VALID) .type(Type.F) .build(); List paymentOption = new ArrayList<>( List.of(new PaymentOption[]{PaymentOption.builder() - .amount(100) - .dueDate(LocalDateTime.now()) - .isPartialPayment(isPartialPayment) - .build()})); + .amount(100) + .dueDate(LocalDateTime.now()) + .isPartialPayment(isPartialPayment) + .build()})); if (isPartialPayment) { paymentOption.add(PaymentOption.builder() @@ -111,5 +112,4 @@ PaymentPosition createPaymentPosition(String prefix, Boolean isPartialPayment) { return paymentPosition; } - } \ No newline at end of file