@@ -70,6 +70,50 @@ protected void setUp() {
7070
7171 }
7272
73+ /**
74+ * Test a value larger than {@link Long#MAX_VALUE} keeps its magnitude instead of being clamped to {@link Long#MAX_VALUE}.
75+ */
76+ @ Test
77+ void testBigIntegerAboveLongMaxValue () {
78+ // One past Long.MAX_VALUE, so NumberFormat parses it as a Double rather than a Long.
79+ final BigInteger aboveLong = BigInteger .valueOf (Long .MAX_VALUE ).add (BigInteger .ONE );
80+ final String aboveLongStr = aboveLong .toString ();
81+ final BigIntegerValidator instance = BigIntegerValidator .getInstance ();
82+ final BigInteger resultAboveLong = instance .validate (aboveLongStr , "#" );
83+ assertTrue (resultAboveLong .compareTo (BigInteger .valueOf (Long .MIN_VALUE )) > 0 );
84+ assertTrue (resultAboveLong .compareTo (BigInteger .ZERO ) > 0 );
85+ assertTrue (resultAboveLong .compareTo (BigInteger .valueOf (Long .MAX_VALUE )) > 0 );
86+ assertTrue (instance .minValue (resultAboveLong , Long .MIN_VALUE ));
87+ assertFalse (instance .minValue (resultAboveLong , Long .MAX_VALUE ));
88+ assertFalse (instance .maxValue (resultAboveLong , Long .MIN_VALUE ));
89+ assertFalse (instance .maxValue (resultAboveLong , Long .MAX_VALUE ));
90+ assertFalse (instance .isInRange (resultAboveLong , Long .MIN_VALUE , Long .MAX_VALUE ));
91+ // BigDecimalValidator already preserves the magnitude, so the two must agree
92+ assertEquals (BigDecimalValidator .getInstance ().validate (aboveLongStr , "#" ).toBigInteger (), resultAboveLong );
93+ }
94+
95+ /**
96+ * Test a value larger than {@link Long#MAX_VALUE} keeps its magnitude instead of being clamped to {@link Long#MAX_VALUE}.
97+ */
98+ @ Test
99+ void testBigIntegerBelowLongMinValue () {
100+ // One past Long.MAX_VALUE, so NumberFormat parses it as a Double rather than a Long.
101+ final BigInteger belowLong = BigInteger .valueOf (Long .MIN_VALUE ).subtract (BigInteger .ONE );
102+ final String belowLongStr = belowLong .toString ();
103+ final BigIntegerValidator instance = BigIntegerValidator .getInstance ();
104+ final BigInteger resultBelowLong = instance .validate (belowLongStr , "#" );
105+ assertTrue (resultBelowLong .compareTo (BigInteger .valueOf (Long .MIN_VALUE )) < 0 );
106+ assertTrue (resultBelowLong .compareTo (BigInteger .ZERO ) < 0 );
107+ assertTrue (resultBelowLong .compareTo (BigInteger .valueOf (Long .MAX_VALUE )) < 0 );
108+ assertTrue (instance .minValue (resultBelowLong , Long .MIN_VALUE ));
109+ assertFalse (instance .minValue (resultBelowLong , Long .MAX_VALUE ));
110+ assertTrue (instance .maxValue (resultBelowLong , Long .MIN_VALUE ));
111+ assertTrue (instance .maxValue (resultBelowLong , Long .MAX_VALUE ));
112+ assertFalse (instance .isInRange (resultBelowLong , Long .MIN_VALUE , Long .MAX_VALUE ));
113+ // BigDecimalValidator already preserves the magnitude, so the two must agree
114+ assertEquals (BigDecimalValidator .getInstance ().validate (belowLongStr , "#" ).toBigInteger (), resultBelowLong );
115+ }
116+
73117 /**
74118 * Test BigInteger Range/Min/Max
75119 */
0 commit comments