From b3d086ad766ea7ff73aedde9c99058f3fac739a9 Mon Sep 17 00:00:00 2001 From: ReBy298 Date: Wed, 23 Oct 2024 18:30:39 -0600 Subject: [PATCH] feat: Create randomPast method (ref #37) --- src/test/java/dev/nmarulo/depensaapp/FakeTestUtil.java | 4 ++++ .../depensaapp/app/products/ProductServiceTestUtil.java | 4 ++-- .../app/shoppinglist/ShoppingListServiceTestUtil.java | 4 ++-- .../depensaapp/app/unitytypes/UnitTypeServiceTestUtil.java | 2 +- 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/test/java/dev/nmarulo/depensaapp/FakeTestUtil.java b/src/test/java/dev/nmarulo/depensaapp/FakeTestUtil.java index 52b2251..6b36ba9 100644 --- a/src/test/java/dev/nmarulo/depensaapp/FakeTestUtil.java +++ b/src/test/java/dev/nmarulo/depensaapp/FakeTestUtil.java @@ -58,4 +58,8 @@ public static LocalDateTime randomFuture() { .future(), ZoneId.systemDefault()); } + public static LocalDateTime randomPast() { + return LocalDateTime.ofInstant(faker.timeAndDate() + .past(), 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 57c0fb1..359f2e8 100644 --- a/src/test/java/dev/nmarulo/depensaapp/app/products/ProductServiceTestUtil.java +++ b/src/test/java/dev/nmarulo/depensaapp/app/products/ProductServiceTestUtil.java @@ -73,7 +73,7 @@ private static Product initProduct() { product.setImgUrl(FakeTestUtil.randomImage()); product.setCalories(BigDecimal.ZERO); product.setDescription(FakeTestUtil.randomSentence()); - product.setCreatedAt(LocalDateTime.now()); + product.setCreatedAt(FakeTestUtil.randomPast()); product.setUpdatedAt(FakeTestUtil.randomFuture()); product.setProductHasShoppingList(Collections.emptySet()); @@ -87,7 +87,7 @@ private User initUser() { user.setUsername(FakeTestUtil.randomUsername()); user.setPassword(FakeTestUtil.randomPassword()); user.setEmail(FakeTestUtil.randomEmail()); - user.setCreatedAt(LocalDateTime.now()); + user.setCreatedAt(FakeTestUtil.randomPast()); user.setUpdatedAt(FakeTestUtil.randomFuture()); user.setShoppingLists(Collections.emptySet()); 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 03da164..42fb2dd 100644 --- a/src/test/java/dev/nmarulo/depensaapp/app/shoppinglist/ShoppingListServiceTestUtil.java +++ b/src/test/java/dev/nmarulo/depensaapp/app/shoppinglist/ShoppingListServiceTestUtil.java @@ -35,7 +35,7 @@ private User initUser() { user.setUsername(FakeTestUtil.randomUsername()); user.setPassword(FakeTestUtil.randomPassword()); user.setEmail(FakeTestUtil.randomEmail()); - user.setCreatedAt(LocalDateTime.now()); + user.setCreatedAt(FakeTestUtil.randomPast()); user.setUpdatedAt(FakeTestUtil.randomFuture()); user.setShoppingLists(Collections.emptySet()); @@ -50,7 +50,7 @@ private ShoppingList initShoppingList(User user) { shoppingList.setTotalProducts(0); shoppingList.setTotalCalories(BigDecimal.ZERO); shoppingList.setTotalPrice(BigDecimal.ZERO); - shoppingList.setCreatedAt(LocalDateTime.now()); + shoppingList.setCreatedAt(FakeTestUtil.randomPast()); 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 4efc490..c0637a7 100644 --- a/src/test/java/dev/nmarulo/depensaapp/app/unitytypes/UnitTypeServiceTestUtil.java +++ b/src/test/java/dev/nmarulo/depensaapp/app/unitytypes/UnitTypeServiceTestUtil.java @@ -46,7 +46,7 @@ private UnitType initUnitType() { unitType.setId(FakeTestUtil.randomInteger()); unitType.setName(FakeTestUtil.randomWord()); - unitType.setCreatedAt(LocalDateTime.now()); + unitType.setCreatedAt(FakeTestUtil.randomPast()); unitType.setUpdatedAt(FakeTestUtil.randomFuture()); unitType.setProductHasShoppingList(Collections.emptySet());