From bfcd8c360cebca89b03f63b7447f480623f4e7ba Mon Sep 17 00:00:00 2001 From: John DeRegnaucourt Date: Sun, 4 Feb 2024 00:43:50 -0500 Subject: [PATCH] Made error messages clearer. --- .../util/convert/StringConversions.java | 16 +++++++------- .../util/convert/ConverterEverythingTest.java | 22 +++++++++---------- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/main/java/com/cedarsoftware/util/convert/StringConversions.java b/src/main/java/com/cedarsoftware/util/convert/StringConversions.java index c940a7ce..25daef47 100644 --- a/src/main/java/com/cedarsoftware/util/convert/StringConversions.java +++ b/src/main/java/com/cedarsoftware/util/convert/StringConversions.java @@ -84,7 +84,7 @@ private static Byte toByte(String s) { } catch (NumberFormatException e) { Long value = toLong(s, bigDecimalMinByte, bigDecimalMaxByte); if (value == null) { - throw new IllegalArgumentException("Value: " + s + " not parseable as a byte value or outside " + Byte.MIN_VALUE + " to " + Byte.MAX_VALUE); + throw new IllegalArgumentException("Value '" + s + "' not parseable as a byte value or outside " + Byte.MIN_VALUE + " to " + Byte.MAX_VALUE); } return value.byteValue(); } @@ -104,7 +104,7 @@ private static Short toShort(Object o) { } catch (NumberFormatException e) { Long value = toLong(str, bigDecimalMinShort, bigDecimalMaxShort); if (value == null) { - throw new IllegalArgumentException("Value: " + o + " not parseable as a short value or outside " + Short.MIN_VALUE + " to " + Short.MAX_VALUE); + throw new IllegalArgumentException("Value '" + o + "' not parseable as a short value or outside " + Short.MIN_VALUE + " to " + Short.MAX_VALUE); } return value.shortValue(); } @@ -124,7 +124,7 @@ private static Integer toInt(Object from) { } catch (NumberFormatException e) { Long value = toLong(str, bigDecimalMinInteger, bigDecimalMaxInteger); if (value == null) { - throw new IllegalArgumentException("Value: " + from + " not parseable as an int value or outside " + Integer.MIN_VALUE + " to " + Integer.MAX_VALUE); + throw new IllegalArgumentException("Value '" + from + "' not parseable as an int value or outside " + Integer.MIN_VALUE + " to " + Integer.MAX_VALUE); } return value.intValue(); } @@ -145,7 +145,7 @@ private static Long toLong(Object from) { } catch (NumberFormatException e) { Long value = toLong(str, bigDecimalMinLong, bigDecimalMaxLong); if (value == null) { - throw new IllegalArgumentException("Value: " + from + " not parseable as a long value or outside " + Long.MIN_VALUE + " to " + Long.MAX_VALUE); + throw new IllegalArgumentException("Value '" + from + "' not parseable as a long value or outside " + Long.MIN_VALUE + " to " + Long.MAX_VALUE); } return value; } @@ -172,7 +172,7 @@ static Float toFloat(Object from, Converter converter, ConverterOptions options) try { return Float.valueOf(str); } catch (NumberFormatException e) { - throw new IllegalArgumentException("Value: " + from + " not parseable as a float value"); + throw new IllegalArgumentException("Value '" + from + "' not parseable as a float value"); } } @@ -184,7 +184,7 @@ static Double toDouble(Object from, Converter converter, ConverterOptions option try { return Double.valueOf(str); } catch (NumberFormatException e) { - throw new IllegalArgumentException("Value: " + from + " not parseable as a double value"); + throw new IllegalArgumentException("Value '" + from + "' not parseable as a double value"); } } @@ -239,7 +239,7 @@ static BigInteger toBigInteger(Object from, Converter converter, ConverterOption BigDecimal bigDec = new BigDecimal(str); return bigDec.toBigInteger(); } catch (NumberFormatException e) { - throw new IllegalArgumentException("Value: " + from + " not parseable as a BigInteger value."); + throw new IllegalArgumentException("Value '" + from + "' not parseable as a BigInteger value."); } } @@ -251,7 +251,7 @@ static BigDecimal toBigDecimal(Object from, Converter converter, ConverterOption try { return new BigDecimal(str); } catch (NumberFormatException e) { - throw new IllegalArgumentException("Value: " + from + " not parseable as a BigDecimal value."); + throw new IllegalArgumentException("Value '" + from + "' not parseable as a BigDecimal value."); } } diff --git a/src/test/java/com/cedarsoftware/util/convert/ConverterEverythingTest.java b/src/test/java/com/cedarsoftware/util/convert/ConverterEverythingTest.java index f78bcaf2..d22d7997 100644 --- a/src/test/java/com/cedarsoftware/util/convert/ConverterEverythingTest.java +++ b/src/test/java/com/cedarsoftware/util/convert/ConverterEverythingTest.java @@ -195,14 +195,14 @@ class ConverterEverythingTest { mapOf("value", "127"), Byte.MAX_VALUE }, { mapOf("value", 127L), Byte.MAX_VALUE }, - { mapOf("_v", "-129"), new IllegalArgumentException("-129 not parseable as a byte value or outside -128 to 127") }, + { mapOf("_v", "-129"), new IllegalArgumentException("'-129' not parseable as a byte value or outside -128 to 127") }, { mapOf("_v", -129), (byte)127 }, - { mapOf("value", "-129"), new IllegalArgumentException("-129 not parseable as a byte value or outside -128 to 127") }, + { mapOf("value", "-129"), new IllegalArgumentException("'-129' not parseable as a byte value or outside -128 to 127") }, { mapOf("value", -129L), (byte) 127 }, - { mapOf("_v", "128"), new IllegalArgumentException("128 not parseable as a byte value or outside -128 to 127") }, + { mapOf("_v", "128"), new IllegalArgumentException("'128' not parseable as a byte value or outside -128 to 127") }, { mapOf("_v", 128), (byte) -128 }, - { mapOf("value", "128"), new IllegalArgumentException("128 not parseable as a byte value or outside -128 to 127") }, + { mapOf("value", "128"), new IllegalArgumentException("'128' not parseable as a byte value or outside -128 to 127") }, { mapOf("value", 128L), (byte) -128 }, }); TEST_FACTORY.put(pair(String.class, Byte.class), new Object[][] { @@ -216,13 +216,13 @@ class ConverterEverythingTest { "-128", (byte)-128 }, { "127", (byte)127 }, { "", (byte)0 }, - { "crapola", new IllegalArgumentException("Value: crapola not parseable as a byte value or outside -128 to 127")}, - { "54 crapola", new IllegalArgumentException("Value: 54 crapola not parseable as a byte value or outside -128 to 127")}, - { "54crapola", new IllegalArgumentException("Value: 54crapola not parseable as a byte value or outside -128 to 127")}, - { "crapola 54", new IllegalArgumentException("Value: crapola 54 not parseable as a byte value or outside -128 to 127")}, - { "crapola54", new IllegalArgumentException("Value: crapola54 not parseable as a byte value or outside -128 to 127")}, - { "-129", new IllegalArgumentException("-129 not parseable as a byte value or outside -128 to 127") }, - { "128", new IllegalArgumentException("128 not parseable as a byte value or outside -128 to 127") }, + { "crapola", new IllegalArgumentException("Value 'crapola' not parseable as a byte value or outside -128 to 127")}, + { "54 crapola", new IllegalArgumentException("Value '54 crapola' not parseable as a byte value or outside -128 to 127")}, + { "54crapola", new IllegalArgumentException("Value '54crapola' not parseable as a byte value or outside -128 to 127")}, + { "crapola 54", new IllegalArgumentException("Value 'crapola 54' not parseable as a byte value or outside -128 to 127")}, + { "crapola54", new IllegalArgumentException("Value 'crapola54' not parseable as a byte value or outside -128 to 127")}, + { "-129", new IllegalArgumentException("'-129' not parseable as a byte value or outside -128 to 127") }, + { "128", new IllegalArgumentException("'128' not parseable as a byte value or outside -128 to 127") }, }); } @BeforeEach