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-lang.git
commit 294aac0f00c54792654124b44fa145c677368176 Author: Gary Gregory <[email protected]> AuthorDate: Sat Jun 13 11:59:58 2026 +0000 Refactor NumberUtilsTest.testCreateBigDecimalFailure() test using @ParameterizedTest --- .../apache/commons/lang3/math/NumberUtilsTest.java | 36 +++++++++++++--------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/src/test/java/org/apache/commons/lang3/math/NumberUtilsTest.java b/src/test/java/org/apache/commons/lang3/math/NumberUtilsTest.java index a3d987de8..c587dd32b 100644 --- a/src/test/java/org/apache/commons/lang3/math/NumberUtilsTest.java +++ b/src/test/java/org/apache/commons/lang3/math/NumberUtilsTest.java @@ -436,25 +436,31 @@ void testCreateBigDecimal() { final String string2 = "0.100000001490116121"; assertEquals(new BigDecimal(string2), NumberUtils.createBigDecimal(string2)); assertNull(NumberUtils.createBigDecimal(null), "createBigDecimal(null) failed"); - testCreateBigDecimalFailure(""); - testCreateBigDecimalFailure(" "); - testCreateBigDecimalFailure("\b\t\n\f\r"); - // Funky whitespaces - testCreateBigDecimalFailure("\u00A0\uFEFF\u000B\u000C\u001C\u001D\u001E\u001F"); - // sign alone not valid - testCreateBigDecimalFailure("-"); - // comment in NumberUtils suggests some implementations may incorrectly allow this - testCreateBigDecimalFailure("--"); - testCreateBigDecimalFailure("--0"); - // sign alone not valid - testCreateBigDecimalFailure("+"); - // in case this was also allowed by some JVMs - testCreateBigDecimalFailure("++"); - testCreateBigDecimalFailure("++0"); } + @ParameterizedTest + @ValueSource(strings = { + // @formatter:off + "", + " ", + "\b\t\n\f\r", + // Funky whitespaces + "\u00A0\uFEFF\u000B\u000C\u001C\u001D\u001E\u001F", + // sign alone not valid + "-", + // comment in NumberUtils suggests some implementations may incorrectly allow this + "--", + "--0", + // sign alone not valid + "+", + // in case this was also allowed by some JVMs + "++", + "++0" }) + // @formatter:on protected void testCreateBigDecimalFailure(final String str) { assertThrows(NumberFormatException.class, () -> NumberUtils.createBigDecimal(str), "createBigDecimal(\"" + str + "\") should have failed."); + // Should match java.math.BigInteger.BigInteger(String) + assertThrows(NumberFormatException.class, () -> new BigDecimal(str)); } @Test
