Skip to content

Commit

Permalink
Merge pull request #41 from KaroK365/master
Browse files Browse the repository at this point in the history
Implemented randomBigDecimal method
  • Loading branch information
nmarulo authored Oct 26, 2024
2 parents 76b7372 + 795148c commit d44ca98
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
6 changes: 6 additions & 0 deletions src/test/java/dev/nmarulo/depensaapp/FakeTestUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import net.datafaker.Faker;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.time.ZoneId;

Expand All @@ -12,6 +13,11 @@ public final class FakeTestUtil {
static {
faker = new Faker();
}

public static BigDecimal randomBigDecimal(){
double randomValue = faker.number().randomDouble(2, 1, 1000);
return BigDecimal.valueOf(randomValue);
}

public static Integer randomInteger() {
return faker.random()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.Collections;

@Getter
Expand Down Expand Up @@ -69,9 +66,9 @@ private static Product initProduct() {

product.setId(FakeTestUtil.randomLong());
product.setName(FakeTestUtil.randomWord());
product.setPrice(BigDecimal.ZERO);
product.setPrice(FakeTestUtil.randomBigDecimal());
product.setImgUrl(FakeTestUtil.randomImage());
product.setCalories(BigDecimal.ZERO);
product.setCalories(FakeTestUtil.randomBigDecimal());
product.setDescription(FakeTestUtil.randomSentence());
product.setCreatedAt(FakeTestUtil.randomPast());
product.setUpdatedAt(FakeTestUtil.randomFuture());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.Collections;

@Getter
Expand Down Expand Up @@ -48,8 +46,8 @@ private ShoppingList initShoppingList(User user) {
shoppingList.setId(FakeTestUtil.randomInteger());
shoppingList.setName(FakeTestUtil.randomSentence());
shoppingList.setTotalProducts(0);
shoppingList.setTotalCalories(BigDecimal.ZERO);
shoppingList.setTotalPrice(BigDecimal.ZERO);
shoppingList.setTotalCalories(FakeTestUtil.randomBigDecimal());
shoppingList.setTotalPrice(FakeTestUtil.randomBigDecimal());
shoppingList.setCreatedAt(FakeTestUtil.randomPast());
shoppingList.setUpdatedAt(FakeTestUtil.randomFuture());
shoppingList.setProductHasShoppingList(Collections.emptySet());
Expand Down

0 comments on commit d44ca98

Please sign in to comment.