Skip to content

Commit

Permalink
Fix constructor parameters in BigDecimalRangeRandomizer
Browse files Browse the repository at this point in the history
  • Loading branch information
lexakimov authored and fmbenhassine committed Jul 15, 2023
1 parent 8743c55 commit 5124167
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ public BigDecimalRangeRandomizer(final Double min, final Double max, final Integ
* @param roundingMode of the {@code BigDecimal} value to be returned.
*/
public BigDecimalRangeRandomizer(final Double min, final Double max, final Integer scale, final RoundingMode roundingMode) {
delegate = new DoubleRangeRandomizer(min, max, scale);
delegate = new DoubleRangeRandomizer(min, max);
this.scale = scale;
this.roundingMode = roundingMode;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import java.math.BigDecimal;
import java.math.RoundingMode;

import nonapi.io.github.classgraph.utils.ReflectionUtils;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

Expand Down Expand Up @@ -92,6 +93,22 @@ void generatedValueShouldHaveProvidedPositiveScale() {
then(bigDecimal.scale()).isEqualTo(scale);
}

@Test
void generatedValueShouldHaveProvidedPositiveScaleAndRoundingMode() {
// given
Integer scale = 2;
RoundingMode roundingMode = RoundingMode.DOWN;
BigDecimalRangeRandomizer bigDecimalRangeRandomizer = new BigDecimalRangeRandomizer(min, max, scale, roundingMode);

// when
BigDecimal bigDecimal = bigDecimalRangeRandomizer.getRandomValue();

then(bigDecimal.scale()).isEqualTo(scale);

var actualRoundingMode = ReflectionUtils.getFieldVal(bigDecimalRangeRandomizer, "roundingMode", false);
then(actualRoundingMode).isEqualTo(RoundingMode.DOWN);
}

@Test
void generatedValueShouldHaveProvidedNegativeScale() {
// given
Expand Down

0 comments on commit 5124167

Please sign in to comment.