This is an automated email from the ASF dual-hosted git repository. garydgregory pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-validator.git
commit 1d544ac65a1c617e9fc8382f0958b04d68ed48e7 Author: Gary Gregory <[email protected]> AuthorDate: Sat Jul 4 14:52:48 2026 -0400 Sort members --- .../validator/routines/ByteValidatorTest.java | 30 +++++++-------- .../validator/routines/CurrencyValidatorTest.java | 32 ++++++++-------- .../validator/routines/FloatValidatorTest.java | 32 ++++++++-------- .../validator/routines/LongValidatorTest.java | 44 +++++++++++----------- .../validator/routines/PercentValidatorTest.java | 32 ++++++++-------- .../validator/routines/ShortValidatorTest.java | 30 +++++++-------- 6 files changed, 100 insertions(+), 100 deletions(-) diff --git a/src/test/java/org/apache/commons/validator/routines/ByteValidatorTest.java b/src/test/java/org/apache/commons/validator/routines/ByteValidatorTest.java index b08b231c..179b3051 100644 --- a/src/test/java/org/apache/commons/validator/routines/ByteValidatorTest.java +++ b/src/test/java/org/apache/commons/validator/routines/ByteValidatorTest.java @@ -113,21 +113,6 @@ class ByteValidatorTest extends AbstractNumberValidatorTest { assertFalse(validator.maxValue(number21, max), "maxValue() > max"); } - /** - * The inherited {@link Number}-typed range overloads must compare the exact bound rather than one narrowed to a {@code long}. - */ - @Test - void testNumberRangeExactBound() { - final AbstractNumberValidator instance = ByteValidator.getInstance(); - final Number value = Byte.valueOf((byte) 100); - // A bound above the long range narrows to a negative long, wrongly reporting 100 as above the maximum. - final Number aboveLongMax = BigInteger.valueOf(Long.MAX_VALUE).add(BigInteger.ONE); - assertTrue(instance.maxValue(value, aboveLongMax)); - assertTrue(instance.isInRange(value, BigInteger.ZERO, aboveLongMax)); - // A fractional bound is not floored: 5 >= 5.5 is false. - assertFalse(instance.minValue(Byte.valueOf((byte) 5), new BigDecimal("5.5"))); - } - /** * Test ByteValidator validate Methods */ @@ -161,4 +146,19 @@ class ByteValidatorTest extends AbstractNumberValidatorTest { assertFalse(ByteValidator.getInstance().isValid(xxxx, pattern), "isValid(B) pattern"); assertFalse(ByteValidator.getInstance().isValid(patternVal, pattern, Locale.GERMAN), "isValid(B) both"); } + + /** + * The inherited {@link Number}-typed range overloads must compare the exact bound rather than one narrowed to a {@code long}. + */ + @Test + void testNumberRangeExactBound() { + final AbstractNumberValidator instance = ByteValidator.getInstance(); + final Number value = Byte.valueOf((byte) 100); + // A bound above the long range narrows to a negative long, wrongly reporting 100 as above the maximum. + final Number aboveLongMax = BigInteger.valueOf(Long.MAX_VALUE).add(BigInteger.ONE); + assertTrue(instance.maxValue(value, aboveLongMax)); + assertTrue(instance.isInRange(value, BigInteger.ZERO, aboveLongMax)); + // A fractional bound is not floored: 5 >= 5.5 is false. + assertFalse(instance.minValue(Byte.valueOf((byte) 5), new BigDecimal("5.5"))); + } } diff --git a/src/test/java/org/apache/commons/validator/routines/CurrencyValidatorTest.java b/src/test/java/org/apache/commons/validator/routines/CurrencyValidatorTest.java index 6191da6a..4f733b56 100644 --- a/src/test/java/org/apache/commons/validator/routines/CurrencyValidatorTest.java +++ b/src/test/java/org/apache/commons/validator/routines/CurrencyValidatorTest.java @@ -47,22 +47,6 @@ class CurrencyValidatorTest { ukPound = new DecimalFormatSymbols(Locale.UK).getCurrencySymbol(); } - /** - * The {@link Number}-typed range overloads inherited through {@link BigDecimalValidator} from {@link AbstractNumberValidator} must compare the exact bound, - * so a {@code BigInteger} or {@code BigDecimal} bound outside the long range or a fractional bound is not silently truncated. - */ - @Test - void testNumberRangeExactBound() { - final AbstractNumberValidator instance = CurrencyValidator.getInstance(); - final Number value = new BigDecimal("100"); - // A bound above the long range must not narrow to a negative long and wrongly report 100 as above the maximum. - final Number aboveLongMax = BigInteger.valueOf(Long.MAX_VALUE).add(BigInteger.ONE); - assertTrue(instance.maxValue(value, aboveLongMax)); - assertTrue(instance.isInRange(value, BigInteger.ZERO, aboveLongMax)); - // A fractional bound is not floored: 5 >= 5.5 is false. - assertFalse(instance.minValue(new BigDecimal("5"), new BigDecimal("5.5"))); - } - /** * Test Format Type */ @@ -147,6 +131,22 @@ class CurrencyValidatorTest { } } + /** + * The {@link Number}-typed range overloads inherited through {@link BigDecimalValidator} from {@link AbstractNumberValidator} must compare the exact bound, + * so a {@code BigInteger} or {@code BigDecimal} bound outside the long range or a fractional bound is not silently truncated. + */ + @Test + void testNumberRangeExactBound() { + final AbstractNumberValidator instance = CurrencyValidator.getInstance(); + final Number value = new BigDecimal("100"); + // A bound above the long range must not narrow to a negative long and wrongly report 100 as above the maximum. + final Number aboveLongMax = BigInteger.valueOf(Long.MAX_VALUE).add(BigInteger.ONE); + assertTrue(instance.maxValue(value, aboveLongMax)); + assertTrue(instance.isInRange(value, BigInteger.ZERO, aboveLongMax)); + // A fractional bound is not floored: 5 >= 5.5 is false. + assertFalse(instance.minValue(new BigDecimal("5"), new BigDecimal("5.5"))); + } + /** * Test currency values with a pattern */ diff --git a/src/test/java/org/apache/commons/validator/routines/FloatValidatorTest.java b/src/test/java/org/apache/commons/validator/routines/FloatValidatorTest.java index f87f17fd..21c059c3 100644 --- a/src/test/java/org/apache/commons/validator/routines/FloatValidatorTest.java +++ b/src/test/java/org/apache/commons/validator/routines/FloatValidatorTest.java @@ -138,22 +138,6 @@ class FloatValidatorTest extends AbstractNumberValidatorTest { assertFalse(validator.maxValue(Float.NaN, 20), "maxValue() NaN"); } - /** - * The {@link Number}-typed range overloads inherited from {@link AbstractNumberValidator} must compare the exact bound, so a {@code BigInteger} or - * {@code BigDecimal} bound outside the long range or a fractional bound is not silently truncated. - */ - @Test - void testNumberRangeExactBound() { - final AbstractNumberValidator instance = FloatValidator.getInstance(); - final Number value = Float.valueOf(100); - // A bound above the long range must not narrow to a negative long and wrongly report 100 as above the maximum. - final Number aboveLongMax = BigInteger.valueOf(Long.MAX_VALUE).add(BigInteger.ONE); - assertTrue(instance.maxValue(value, aboveLongMax)); - assertTrue(instance.isInRange(value, BigInteger.ZERO, aboveLongMax)); - // A fractional bound is not floored: 5 >= 5.5 is false. - assertFalse(instance.minValue(Float.valueOf(5), new BigDecimal("5.5"))); - } - /** * Test Float validation for values too small to handle. (slightly different from max/min which are the largest +ve/-ve */ @@ -211,6 +195,22 @@ class FloatValidatorTest extends AbstractNumberValidatorTest { assertFalse(validator.isValid(patternVal, pattern, Locale.GERMAN), "isValid(B) both"); } + /** + * The {@link Number}-typed range overloads inherited from {@link AbstractNumberValidator} must compare the exact bound, so a {@code BigInteger} or + * {@code BigDecimal} bound outside the long range or a fractional bound is not silently truncated. + */ + @Test + void testNumberRangeExactBound() { + final AbstractNumberValidator instance = FloatValidator.getInstance(); + final Number value = Float.valueOf(100); + // A bound above the long range must not narrow to a negative long and wrongly report 100 as above the maximum. + final Number aboveLongMax = BigInteger.valueOf(Long.MAX_VALUE).add(BigInteger.ONE); + assertTrue(instance.maxValue(value, aboveLongMax)); + assertTrue(instance.isInRange(value, BigInteger.ZERO, aboveLongMax)); + // A fractional bound is not floored: 5 >= 5.5 is false. + assertFalse(instance.minValue(Float.valueOf(5), new BigDecimal("5.5"))); + } + @Test void testSpecialSymbols() { final FloatValidator validator = FloatValidator.getInstance(); diff --git a/src/test/java/org/apache/commons/validator/routines/LongValidatorTest.java b/src/test/java/org/apache/commons/validator/routines/LongValidatorTest.java index 0c36da94..48ec91f3 100644 --- a/src/test/java/org/apache/commons/validator/routines/LongValidatorTest.java +++ b/src/test/java/org/apache/commons/validator/routines/LongValidatorTest.java @@ -113,28 +113,6 @@ class LongValidatorTest extends AbstractNumberValidatorTest { assertFalse(validator.maxValue(number21, 20), "maxValue() > max"); } - /** - * The {@link Number}-typed range overloads inherited from {@link AbstractNumberValidator} must compare the exact bound rather than one narrowed to a - * {@code long}, so a {@code BigInteger}/{@code BigDecimal} bound outside the long range or a fractional bound is not silently truncated. - */ - @Test - void testNumberRangeExactBound() { - final AbstractNumberValidator instance = LongValidator.getInstance(); - final Number value = Long.valueOf(Long.MAX_VALUE); - // One above Long.MAX_VALUE narrows to Long.MIN_VALUE, wrongly reporting Long.MAX_VALUE as above the maximum. - final Number aboveLongMax = BigInteger.valueOf(Long.MAX_VALUE).add(BigInteger.ONE); - assertTrue(instance.maxValue(value, aboveLongMax)); - assertTrue(instance.isInRange(value, BigInteger.ZERO, aboveLongMax)); - // A fractional bound is not floored: 5 >= 5.5 is false, 5 <= 5.5 is true. - assertFalse(instance.minValue(Long.valueOf(5), Double.valueOf(5.5))); - assertFalse(instance.minValue(Long.valueOf(5), new BigDecimal("5.5"))); - assertTrue(instance.maxValue(Long.valueOf(5), new BigDecimal("5.5"))); - // A non-finite bound falls back to the double comparison, matching the Big* validators. - assertFalse(instance.minValue(value, Double.NaN)); - assertTrue(instance.maxValue(value, Double.POSITIVE_INFINITY)); - assertTrue(instance.minValue(value, Double.NEGATIVE_INFINITY)); - } - /** * Test LongValidator validate Methods */ @@ -168,4 +146,26 @@ class LongValidatorTest extends AbstractNumberValidatorTest { assertFalse(LongValidator.getInstance().isValid(xxxx, pattern), "isValid(B) pattern"); assertFalse(LongValidator.getInstance().isValid(patternVal, pattern, Locale.GERMAN), "isValid(B) both"); } + + /** + * The {@link Number}-typed range overloads inherited from {@link AbstractNumberValidator} must compare the exact bound rather than one narrowed to a + * {@code long}, so a {@code BigInteger}/{@code BigDecimal} bound outside the long range or a fractional bound is not silently truncated. + */ + @Test + void testNumberRangeExactBound() { + final AbstractNumberValidator instance = LongValidator.getInstance(); + final Number value = Long.valueOf(Long.MAX_VALUE); + // One above Long.MAX_VALUE narrows to Long.MIN_VALUE, wrongly reporting Long.MAX_VALUE as above the maximum. + final Number aboveLongMax = BigInteger.valueOf(Long.MAX_VALUE).add(BigInteger.ONE); + assertTrue(instance.maxValue(value, aboveLongMax)); + assertTrue(instance.isInRange(value, BigInteger.ZERO, aboveLongMax)); + // A fractional bound is not floored: 5 >= 5.5 is false, 5 <= 5.5 is true. + assertFalse(instance.minValue(Long.valueOf(5), Double.valueOf(5.5))); + assertFalse(instance.minValue(Long.valueOf(5), new BigDecimal("5.5"))); + assertTrue(instance.maxValue(Long.valueOf(5), new BigDecimal("5.5"))); + // A non-finite bound falls back to the double comparison, matching the Big* validators. + assertFalse(instance.minValue(value, Double.NaN)); + assertTrue(instance.maxValue(value, Double.POSITIVE_INFINITY)); + assertTrue(instance.minValue(value, Double.NEGATIVE_INFINITY)); + } } diff --git a/src/test/java/org/apache/commons/validator/routines/PercentValidatorTest.java b/src/test/java/org/apache/commons/validator/routines/PercentValidatorTest.java index 9afe81b2..24f1fb99 100644 --- a/src/test/java/org/apache/commons/validator/routines/PercentValidatorTest.java +++ b/src/test/java/org/apache/commons/validator/routines/PercentValidatorTest.java @@ -53,22 +53,6 @@ class PercentValidatorTest { validator = null; } - /** - * The {@link Number}-typed range overloads inherited through {@link BigDecimalValidator} from {@link AbstractNumberValidator} must compare the exact bound, - * so a {@code BigInteger} or {@code BigDecimal} bound outside the long range or a fractional bound is not silently truncated. - */ - @Test - void testNumberRangeExactBound() { - final AbstractNumberValidator instance = PercentValidator.getInstance(); - final Number value = new BigDecimal("100"); - // A bound above the long range must not narrow to a negative long and wrongly report 100 as above the maximum. - final Number aboveLongMax = BigInteger.valueOf(Long.MAX_VALUE).add(BigInteger.ONE); - assertTrue(instance.maxValue(value, aboveLongMax)); - assertTrue(instance.isInRange(value, BigInteger.ZERO, aboveLongMax)); - // A fractional bound is not floored: 5 >= 5.5 is false. - assertFalse(instance.minValue(new BigDecimal("5"), new BigDecimal("5.5"))); - } - /** * Test Format Type */ @@ -100,6 +84,22 @@ class PercentValidatorTest { assertFalse(validator.isValid("(12%)", Locale.US), "US wrong negative"); } + /** + * The {@link Number}-typed range overloads inherited through {@link BigDecimalValidator} from {@link AbstractNumberValidator} must compare the exact bound, + * so a {@code BigInteger} or {@code BigDecimal} bound outside the long range or a fractional bound is not silently truncated. + */ + @Test + void testNumberRangeExactBound() { + final AbstractNumberValidator instance = PercentValidator.getInstance(); + final Number value = new BigDecimal("100"); + // A bound above the long range must not narrow to a negative long and wrongly report 100 as above the maximum. + final Number aboveLongMax = BigInteger.valueOf(Long.MAX_VALUE).add(BigInteger.ONE); + assertTrue(instance.maxValue(value, aboveLongMax)); + assertTrue(instance.isInRange(value, BigInteger.ZERO, aboveLongMax)); + // A fractional bound is not floored: 5 >= 5.5 is false. + assertFalse(instance.minValue(new BigDecimal("5"), new BigDecimal("5.5"))); + } + /** * Test Valid percentage values */ diff --git a/src/test/java/org/apache/commons/validator/routines/ShortValidatorTest.java b/src/test/java/org/apache/commons/validator/routines/ShortValidatorTest.java index 66a86383..f3ceb74b 100644 --- a/src/test/java/org/apache/commons/validator/routines/ShortValidatorTest.java +++ b/src/test/java/org/apache/commons/validator/routines/ShortValidatorTest.java @@ -71,6 +71,21 @@ class ShortValidatorTest extends AbstractNumberValidatorTest { } + /** + * The inherited {@link Number}-typed range overloads must compare the exact bound rather than one narrowed to a {@code long}. + */ + @Test + void testNumberRangeExactBound() { + final AbstractNumberValidator instance = ShortValidator.getInstance(); + final Number value = Short.valueOf((short) 100); + // A bound above the long range narrows to a negative long, wrongly reporting 100 as above the maximum. + final Number aboveLongMax = BigInteger.valueOf(Long.MAX_VALUE).add(BigInteger.ONE); + assertTrue(instance.maxValue(value, aboveLongMax)); + assertTrue(instance.isInRange(value, BigInteger.ZERO, aboveLongMax)); + // A fractional bound is not floored: 5 >= 5.5 is false. + assertFalse(instance.minValue(Short.valueOf((short) 5), new BigDecimal("5.5"))); + } + /** * Test Short Range/Min/Max */ @@ -104,21 +119,6 @@ class ShortValidatorTest extends AbstractNumberValidatorTest { assertFalse(validator.maxValue(number21, max), "maxValue() > max"); } - /** - * The inherited {@link Number}-typed range overloads must compare the exact bound rather than one narrowed to a {@code long}. - */ - @Test - void testNumberRangeExactBound() { - final AbstractNumberValidator instance = ShortValidator.getInstance(); - final Number value = Short.valueOf((short) 100); - // A bound above the long range narrows to a negative long, wrongly reporting 100 as above the maximum. - final Number aboveLongMax = BigInteger.valueOf(Long.MAX_VALUE).add(BigInteger.ONE); - assertTrue(instance.maxValue(value, aboveLongMax)); - assertTrue(instance.isInRange(value, BigInteger.ZERO, aboveLongMax)); - // A fractional bound is not floored: 5 >= 5.5 is false. - assertFalse(instance.minValue(Short.valueOf((short) 5), new BigDecimal("5.5"))); - } - /** * Test ShortValidator validate Methods */
