Skip to content

Commit

Permalink
Made error messages clearer.
Browse files Browse the repository at this point in the history
  • Loading branch information
jdereg committed Feb 4, 2024
1 parent 2369c2b commit bfcd8c3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand All @@ -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();
}
Expand All @@ -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();
}
Expand All @@ -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;
}
Expand All @@ -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");
}
}

Expand All @@ -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");
}
}

Expand Down Expand Up @@ -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.");
}
}

Expand All @@ -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.");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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[][] {
Expand All @@ -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
Expand Down

0 comments on commit bfcd8c3

Please sign in to comment.