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 e600cdd87009354ee32f589cf070007cc58af0e5 Author: Gary Gregory <[email protected]> AuthorDate: Sat Jul 11 07:17:12 2026 -0400 Sort members --- .../routines/BigIntegerValidatorTest.java | 48 +++++++++++----------- .../validator/routines/ShortValidatorTest.java | 30 +++++++------- 2 files changed, 39 insertions(+), 39 deletions(-) diff --git a/src/test/java/org/apache/commons/validator/routines/BigIntegerValidatorTest.java b/src/test/java/org/apache/commons/validator/routines/BigIntegerValidatorTest.java index 4a7b9ea0..0c2b0aaf 100644 --- a/src/test/java/org/apache/commons/validator/routines/BigIntegerValidatorTest.java +++ b/src/test/java/org/apache/commons/validator/routines/BigIntegerValidatorTest.java @@ -122,30 +122,6 @@ class BigIntegerValidatorTest extends AbstractNumberValidatorTest { assertEquals(BigDecimalValidator.getInstance().validate(exactStr, "#").toBigInteger(), instance.validate(exactStr, "#")); } - /** - * A fractional value written with a negative exponent and no decimal point (for example "15E-1" for 1.5) is consumed in full because parseIntegerOnly only - * stops at the decimal separator, so it arrives as a fractional BigDecimal and was floored by toBigInteger. It must be rejected instead, matching - * ByteValidator, IntegerValidator and LongValidator, which return null for the same input. - */ - @Test - void testRejectFractionalExponent() { - final BigIntegerValidator instance = BigIntegerValidator.getInstance(); - assertNull(instance.validate("15E-1")); // 1.5, was floored to 1 - assertNull(instance.validate("5E-1")); // 0.5, was floored to 0 - assertNull(instance.validate("5E-100")); - // the primitive integer validators already reject these - assertNull(IntegerValidator.getInstance().validate("15E-1")); - assertNull(LongValidator.getInstance().validate("15E-1")); - assertNull(ShortValidator.getInstance().validate("15E-1")); - assertNull(ByteValidator.getInstance().validate("15E-1")); - // a whole number written with an exponent stays valid - assertEquals(new BigInteger("100"), instance.validate("1E2")); - // the lenient (non-strict) validator still truncates trailing fraction digits - final BigIntegerValidator lenient = new BigIntegerValidator(false, 0); - assertEquals(new BigInteger("1234"), lenient.validate("1,234.5")); - assertNull(lenient.validate("15E-1")); - } - /** * Test BigInteger Range/Min/Max */ @@ -302,4 +278,28 @@ class BigIntegerValidatorTest extends AbstractNumberValidatorTest { assertEquals(50L, wrapsIntoRange.longValue()); assertFalse(instance.isInRange(wrapsIntoRange, min, max)); } + + /** + * A fractional value written with a negative exponent and no decimal point (for example "15E-1" for 1.5) is consumed in full because parseIntegerOnly only + * stops at the decimal separator, so it arrives as a fractional BigDecimal and was floored by toBigInteger. It must be rejected instead, matching + * ByteValidator, IntegerValidator and LongValidator, which return null for the same input. + */ + @Test + void testRejectFractionalExponent() { + final BigIntegerValidator instance = BigIntegerValidator.getInstance(); + assertNull(instance.validate("15E-1")); // 1.5, was floored to 1 + assertNull(instance.validate("5E-1")); // 0.5, was floored to 0 + assertNull(instance.validate("5E-100")); + // the primitive integer validators already reject these + assertNull(IntegerValidator.getInstance().validate("15E-1")); + assertNull(LongValidator.getInstance().validate("15E-1")); + assertNull(ShortValidator.getInstance().validate("15E-1")); + assertNull(ByteValidator.getInstance().validate("15E-1")); + // a whole number written with an exponent stays valid + assertEquals(new BigInteger("100"), instance.validate("1E2")); + // the lenient (non-strict) validator still truncates trailing fraction digits + final BigIntegerValidator lenient = new BigIntegerValidator(false, 0); + assertEquals(new BigInteger("1234"), lenient.validate("1,234.5")); + assertNull(lenient.validate("15E-1")); + } } 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 c73ba7b8..e785cdbc 100644 --- a/src/test/java/org/apache/commons/validator/routines/ShortValidatorTest.java +++ b/src/test/java/org/apache/commons/validator/routines/ShortValidatorTest.java @@ -71,21 +71,6 @@ 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"))); - } - /** * A value whose fractional part is expressed through a negative exponent rather than a decimal point (for example * {@code "15E-1"} for 1.5) is parsed to a fractional {@code Double}, not a {@code Long}, because {@code parseIntegerOnly} @@ -102,6 +87,21 @@ class ShortValidatorTest extends AbstractNumberValidatorTest { assertNull(validator.validate("1E-100", Locale.US), "validate(1E-100)"); } + /** + * 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 */
