From 2dc6e10b2e2f21ce3c9a91ccc70de0d859d0ed55 Mon Sep 17 00:00:00 2001 From: ArturWood Date: Tue, 22 Oct 2024 22:39:41 -0300 Subject: [PATCH] Created the randomFuture method in the FakeTestUtil class --- src/test/java/dev/nmarulo/depensaapp/FakeTestUtil.java | 10 +++++++++- .../app/products/ProductServiceTestUtil.java | 4 ++-- .../app/shoppinglist/ShoppingListServiceTestUtil.java | 4 ++-- .../app/unitytypes/UnitTypeServiceTestUtil.java | 2 +- 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/test/java/dev/nmarulo/depensaapp/FakeTestUtil.java b/src/test/java/dev/nmarulo/depensaapp/FakeTestUtil.java index a888536..52b2251 100644 --- a/src/test/java/dev/nmarulo/depensaapp/FakeTestUtil.java +++ b/src/test/java/dev/nmarulo/depensaapp/FakeTestUtil.java @@ -2,6 +2,9 @@ import net.datafaker.Faker; +import java.time.LocalDateTime; +import java.time.ZoneId; + public final class FakeTestUtil { public static final Faker faker; @@ -44,10 +47,15 @@ public static String randomUsername() { return faker.internet() .username(); } - + public static String randomImage() { return faker.internet() .image(); } + public static LocalDateTime randomFuture() { + return LocalDateTime.ofInstant(faker.timeAndDate() + .future(), ZoneId.systemDefault()); + } + } diff --git a/src/test/java/dev/nmarulo/depensaapp/app/products/ProductServiceTestUtil.java b/src/test/java/dev/nmarulo/depensaapp/app/products/ProductServiceTestUtil.java index f54fc67..57c0fb1 100644 --- a/src/test/java/dev/nmarulo/depensaapp/app/products/ProductServiceTestUtil.java +++ b/src/test/java/dev/nmarulo/depensaapp/app/products/ProductServiceTestUtil.java @@ -74,7 +74,7 @@ private static Product initProduct() { product.setCalories(BigDecimal.ZERO); product.setDescription(FakeTestUtil.randomSentence()); product.setCreatedAt(LocalDateTime.now()); - product.setUpdatedAt(LocalDateTime.now()); + product.setUpdatedAt(FakeTestUtil.randomFuture()); product.setProductHasShoppingList(Collections.emptySet()); return product; @@ -88,7 +88,7 @@ private User initUser() { user.setPassword(FakeTestUtil.randomPassword()); user.setEmail(FakeTestUtil.randomEmail()); user.setCreatedAt(LocalDateTime.now()); - user.setUpdatedAt(LocalDateTime.now()); + user.setUpdatedAt(FakeTestUtil.randomFuture()); user.setShoppingLists(Collections.emptySet()); return user; diff --git a/src/test/java/dev/nmarulo/depensaapp/app/shoppinglist/ShoppingListServiceTestUtil.java b/src/test/java/dev/nmarulo/depensaapp/app/shoppinglist/ShoppingListServiceTestUtil.java index a5a817d..03da164 100644 --- a/src/test/java/dev/nmarulo/depensaapp/app/shoppinglist/ShoppingListServiceTestUtil.java +++ b/src/test/java/dev/nmarulo/depensaapp/app/shoppinglist/ShoppingListServiceTestUtil.java @@ -36,7 +36,7 @@ private User initUser() { user.setPassword(FakeTestUtil.randomPassword()); user.setEmail(FakeTestUtil.randomEmail()); user.setCreatedAt(LocalDateTime.now()); - user.setUpdatedAt(LocalDateTime.now()); + user.setUpdatedAt(FakeTestUtil.randomFuture()); user.setShoppingLists(Collections.emptySet()); return user; @@ -51,7 +51,7 @@ private ShoppingList initShoppingList(User user) { shoppingList.setTotalCalories(BigDecimal.ZERO); shoppingList.setTotalPrice(BigDecimal.ZERO); shoppingList.setCreatedAt(LocalDateTime.now()); - shoppingList.setUpdatedAt(LocalDateTime.now()); + shoppingList.setUpdatedAt(FakeTestUtil.randomFuture()); shoppingList.setProductHasShoppingList(Collections.emptySet()); shoppingList.setUser(user); diff --git a/src/test/java/dev/nmarulo/depensaapp/app/unitytypes/UnitTypeServiceTestUtil.java b/src/test/java/dev/nmarulo/depensaapp/app/unitytypes/UnitTypeServiceTestUtil.java index 523911d..4efc490 100644 --- a/src/test/java/dev/nmarulo/depensaapp/app/unitytypes/UnitTypeServiceTestUtil.java +++ b/src/test/java/dev/nmarulo/depensaapp/app/unitytypes/UnitTypeServiceTestUtil.java @@ -47,7 +47,7 @@ private UnitType initUnitType() { unitType.setId(FakeTestUtil.randomInteger()); unitType.setName(FakeTestUtil.randomWord()); unitType.setCreatedAt(LocalDateTime.now()); - unitType.setUpdatedAt(LocalDateTime.now()); + unitType.setUpdatedAt(FakeTestUtil.randomFuture()); unitType.setProductHasShoppingList(Collections.emptySet()); return unitType;