Skip to content

Commit

Permalink
[SELC-5887] added tests in UserUtilsTest
Browse files Browse the repository at this point in the history
  • Loading branch information
flaminiaScarciofolo committed Oct 30, 2024
1 parent f1ca3b0 commit b02715a
Showing 1 changed file with 79 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@
import java.time.LocalTime;
import java.time.OffsetDateTime;
import java.time.ZoneOffset;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.*;

import static org.junit.jupiter.api.Assertions.*;

Expand Down Expand Up @@ -124,4 +121,82 @@ void getHMAC256_withValidInputs_shouldReturnValidHash() {

assertNotNull(hash);
}

@Test
void retrieveFdProductIfItChanged_withValidProducts_shouldReturnMostRecentlyUpdatedProduct() {
List<OnboardedProduct> products = new ArrayList<>();
OnboardedProduct product1 = new OnboardedProduct();
product1.setProductId("1");
product1.setUpdatedAt(OffsetDateTime.now().minusDays(1));
product1.setCreatedAt(OffsetDateTime.now().minusDays(2));
products.add(product1);

OnboardedProduct product2 = new OnboardedProduct();
product2.setProductId("2");
product2.setUpdatedAt(OffsetDateTime.now());
product2.setCreatedAt(OffsetDateTime.now().minusDays(1));
products.add(product2);

List<String> productIdToCheck = List.of("1", "2");

OnboardedProduct result = UserUtils.retrieveFdProductIfItChanged(products, productIdToCheck);

assertNotNull(result);
assertEquals("2", result.getProductId());
}

@Test
void retrieveFdProductIfItChanged_withEmptyProductList() {
List<OnboardedProduct> products = Collections.emptyList();
List<String> productIdToCheck = List.of("1", "2");

OnboardedProduct result = UserUtils.retrieveFdProductIfItChanged(products, productIdToCheck);

assertNull(result);
}

@Test
void retrieveFdProductIfItChanged_withNoFdProductIds() {
List<OnboardedProduct> products = new ArrayList<>();
OnboardedProduct product1 = new OnboardedProduct();
product1.setProductId("1");
product1.setUpdatedAt(OffsetDateTime.now().minusDays(1));
product1.setCreatedAt(OffsetDateTime.now().minusDays(2));
products.add(product1);

OnboardedProduct product2 = new OnboardedProduct();
product2.setProductId("2");
product2.setUpdatedAt(OffsetDateTime.now());
product2.setCreatedAt(OffsetDateTime.now().minusDays(1));
products.add(product2);

List<String> productIdToCheck = List.of("3", "4");

OnboardedProduct result = UserUtils.retrieveFdProductIfItChanged(products, productIdToCheck);

assertNull(result);
}

@Test
void retrieveFdProductIfItChanged_withProductsWithSameUpdatedAt() {
List<OnboardedProduct> products = new ArrayList<>();
OnboardedProduct product1 = new OnboardedProduct();
product1.setProductId("1");
product1.setUpdatedAt(OffsetDateTime.now());
product1.setCreatedAt(OffsetDateTime.now().minusDays(2));
products.add(product1);

OnboardedProduct product2 = new OnboardedProduct();
product2.setProductId("2");
product2.setUpdatedAt(OffsetDateTime.now());
product2.setCreatedAt(OffsetDateTime.now().minusDays(1));
products.add(product2);

List<String> productIdToCheck = List.of("1", "2");

OnboardedProduct result = UserUtils.retrieveFdProductIfItChanged(products, productIdToCheck);

assertNotNull(result);
assertEquals("2", result.getProductId());
}
}

0 comments on commit b02715a

Please sign in to comment.