From 46b22e87d9b66e0075fc5b78e31378d447aed0c5 Mon Sep 17 00:00:00 2001 From: empassaro Date: Mon, 29 Jan 2024 14:39:33 +0100 Subject: [PATCH] test: added unit tests for coverage --- .../selfcare/user/util/UserUtilTest.java | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/apps/user-ms/src/test/java/it/pagopa/selfcare/user/util/UserUtilTest.java b/apps/user-ms/src/test/java/it/pagopa/selfcare/user/util/UserUtilTest.java index b216ebde..70788c9c 100644 --- a/apps/user-ms/src/test/java/it/pagopa/selfcare/user/util/UserUtilTest.java +++ b/apps/user-ms/src/test/java/it/pagopa/selfcare/user/util/UserUtilTest.java @@ -7,11 +7,15 @@ import it.pagopa.selfcare.product.entity.ProductRole; import it.pagopa.selfcare.product.entity.ProductRoleInfo; import it.pagopa.selfcare.product.service.ProductService; +import it.pagopa.selfcare.user.constant.OnboardedProductState; +import it.pagopa.selfcare.user.entity.OnboardedProduct; +import it.pagopa.selfcare.user.entity.UserInstitution; import it.pagopa.selfcare.user.exception.InvalidRequestException; import jakarta.inject.Inject; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; +import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -81,4 +85,25 @@ private Product getProductResource() { return productResource; } + @Test + void testFilterProductWorks() { + OnboardedProduct onboardedProduct1 = new OnboardedProduct(); + onboardedProduct1.setProductId("test-id"); + onboardedProduct1.setStatus(OnboardedProductState.ACTIVE); + OnboardedProduct onboardedProduct2 = new OnboardedProduct(); + onboardedProduct2.setProductId("test-id"); + onboardedProduct2.setStatus(OnboardedProductState.DELETED); + + List onboardedProducts = new ArrayList<>(); + onboardedProducts.add(onboardedProduct1); + onboardedProducts.add(onboardedProduct2); + + UserInstitution userInstitution = new UserInstitution(); + userInstitution.setProducts(onboardedProducts); + + String[] states = {"ACTIVE"}; + UserInstitution filteredUserInstitution = userUtils.filterProduct(userInstitution, states); + Assertions.assertEquals(1, filteredUserInstitution.getProducts().size()); + } + }