@@ -141,6 +141,12 @@ public class JdbcResultSetTest {
141141 private static final BigDecimal NUMERIC_VALUE = new BigDecimal ("3.14" );
142142 private static final int NUMERIC_COLINDEX_NULL = 25 ;
143143 private static final int NUMERIC_COLINDEX_NOTNULL = 26 ;
144+ private static final String PG_NUMERIC_COL_NULL = "PG_NUMERIC_COL_NULL" ;
145+ private static final String PG_NUMERIC_COL_NOT_NULL = "PG_NUMERIC_COL_NOT_NULL" ;
146+ private static final String PG_NUMERIC_COL_NAN = "PG_NUMERIC_COL_NAN" ;
147+ private static final int PG_NUMERIC_COLINDEX_NULL = 44 ;
148+ private static final int PG_NUMERIC_COLINDEX_NOTNULL = 45 ;
149+ private static final int PG_NUMERIC_COLINDEX_NAN = 46 ;
144150 private static final String JSON_COL_NULL = "JSON_COL_NULL" ;
145151 private static final String JSON_COL_NOT_NULL = "JSON_COL_NOT_NULL" ;
146152 private static final int JSON_COLINDEX_NULL = 27 ;
@@ -237,7 +243,10 @@ static ResultSet getMockResultSet() {
237243 Type .array (Type .proto (SingerInfo .getDescriptor ().getFullName ()))),
238244 StructField .of (
239245 PROTO_ENUM_ARRAY_COL ,
240- Type .array (Type .protoEnum (Genre .getDescriptor ().getFullName ())))),
246+ Type .array (Type .protoEnum (Genre .getDescriptor ().getFullName ()))),
247+ StructField .of (PG_NUMERIC_COL_NULL , Type .pgNumeric ()),
248+ StructField .of (PG_NUMERIC_COL_NOT_NULL , Type .pgNumeric ()),
249+ StructField .of (PG_NUMERIC_COL_NAN , Type .pgNumeric ())),
241250 Collections .singletonList (
242251 Struct .newBuilder ()
243252 .set (STRING_COL_NULL )
@@ -327,6 +336,12 @@ static ResultSet getMockResultSet() {
327336 PROTO_MSG_ARRAY_VALUE , SingerInfo .getDescriptor ().getFullName ())
328337 .set (PROTO_ENUM_ARRAY_COL )
329338 .toProtoEnumArray (PROTO_ENUM_ARRAY_VALUE , Genre .getDescriptor ().getFullName ())
339+ .set (PG_NUMERIC_COL_NULL )
340+ .to (Value .pgNumeric ((String ) null ))
341+ .set (PG_NUMERIC_COL_NOT_NULL )
342+ .to (Value .pgNumeric ("3.14" ))
343+ .set (PG_NUMERIC_COL_NAN )
344+ .to (Value .pgNumeric ("NaN" ))
330345 .build ()));
331346 }
332347
@@ -594,14 +609,106 @@ public void testGetLongIndexForFloat64() throws SQLException {
594609 assertTrue (subject .wasNull ());
595610 }
596611
612+ @ Test
613+ public void testGetIntegerTypesOnNumeric () throws SQLException {
614+ assertEquals ((byte ) 0 , subject .getByte (NUMERIC_COLINDEX_NULL ));
615+ assertTrue (subject .wasNull ());
616+ assertEquals ((byte ) 3 , subject .getByte (NUMERIC_COLINDEX_NOTNULL ));
617+ assertFalse (subject .wasNull ());
618+
619+ assertEquals ((short ) 0 , subject .getShort (NUMERIC_COLINDEX_NULL ));
620+ assertTrue (subject .wasNull ());
621+ assertEquals ((short ) 3 , subject .getShort (NUMERIC_COLINDEX_NOTNULL ));
622+ assertFalse (subject .wasNull ());
623+
624+ assertEquals (0 , subject .getInt (NUMERIC_COLINDEX_NULL ));
625+ assertTrue (subject .wasNull ());
626+ assertEquals (3 , subject .getInt (NUMERIC_COLINDEX_NOTNULL ));
627+ assertFalse (subject .wasNull ());
628+
629+ assertEquals (0L , subject .getLong (NUMERIC_COLINDEX_NULL ));
630+ assertTrue (subject .wasNull ());
631+ assertEquals (3L , subject .getLong (NUMERIC_COLINDEX_NOTNULL ));
632+ assertFalse (subject .wasNull ());
633+ }
634+
635+ @ Test
636+ public void testGetIntegerTypesOnPgNumeric () throws SQLException {
637+ assertEquals ((byte ) 0 , subject .getByte (PG_NUMERIC_COLINDEX_NULL ));
638+ assertTrue (subject .wasNull ());
639+ assertEquals ((byte ) 3 , subject .getByte (PG_NUMERIC_COLINDEX_NOTNULL ));
640+ assertFalse (subject .wasNull ());
641+
642+ assertEquals ((short ) 0 , subject .getShort (PG_NUMERIC_COLINDEX_NULL ));
643+ assertTrue (subject .wasNull ());
644+ assertEquals ((short ) 3 , subject .getShort (PG_NUMERIC_COLINDEX_NOTNULL ));
645+ assertFalse (subject .wasNull ());
646+
647+ assertEquals (0 , subject .getInt (PG_NUMERIC_COLINDEX_NULL ));
648+ assertTrue (subject .wasNull ());
649+ assertEquals (3 , subject .getInt (PG_NUMERIC_COLINDEX_NOTNULL ));
650+ assertFalse (subject .wasNull ());
651+
652+ assertEquals (0L , subject .getLong (PG_NUMERIC_COLINDEX_NULL ));
653+ assertTrue (subject .wasNull ());
654+ assertEquals (3L , subject .getLong (PG_NUMERIC_COLINDEX_NOTNULL ));
655+ assertFalse (subject .wasNull ());
656+ }
657+
658+ @ Test
659+ public void testGetIntegerTypesOnPgNumericNaN () throws SQLException {
660+ assertTrue (Double .isNaN (subject .getDouble (PG_NUMERIC_COLINDEX_NAN )));
661+ assertTrue (Float .isNaN (subject .getFloat (PG_NUMERIC_COLINDEX_NAN )));
662+ assertEquals ("NaN" , subject .getString (PG_NUMERIC_COLINDEX_NAN ));
663+ try {
664+ subject .getByte (PG_NUMERIC_COLINDEX_NAN );
665+ fail ("missing expected SQLException" );
666+ } catch (SQLException e ) {
667+ assertTrue (e instanceof JdbcSqlException );
668+ assertEquals (Code .INVALID_ARGUMENT , ((JdbcSqlException ) e ).getCode ());
669+ }
670+
671+ try {
672+ subject .getShort (PG_NUMERIC_COLINDEX_NAN );
673+ fail ("missing expected SQLException" );
674+ } catch (SQLException e ) {
675+ assertTrue (e instanceof JdbcSqlException );
676+ assertEquals (Code .INVALID_ARGUMENT , ((JdbcSqlException ) e ).getCode ());
677+ }
678+
679+ try {
680+ subject .getInt (PG_NUMERIC_COLINDEX_NAN );
681+ fail ("missing expected SQLException" );
682+ } catch (SQLException e ) {
683+ assertTrue (e instanceof JdbcSqlException );
684+ assertEquals (Code .INVALID_ARGUMENT , ((JdbcSqlException ) e ).getCode ());
685+ }
686+
687+ try {
688+ subject .getLong (PG_NUMERIC_COLINDEX_NAN );
689+ fail ("missing expected SQLException" );
690+ } catch (SQLException e ) {
691+ assertTrue (e instanceof JdbcSqlException );
692+ assertEquals (Code .INVALID_ARGUMENT , ((JdbcSqlException ) e ).getCode ());
693+ }
694+
695+ try {
696+ subject .getBigDecimal (PG_NUMERIC_COLINDEX_NAN );
697+ fail ("missing expected SQLException" );
698+ } catch (SQLException e ) {
699+ assertTrue (e instanceof JdbcSqlException );
700+ assertEquals (Code .INVALID_ARGUMENT , ((JdbcSqlException ) e ).getCode ());
701+ }
702+ }
703+
597704 @ Test
598705 public void testGetLongIndexForString () {
599706 try {
600707 subject .getLong (STRING_COLINDEX_NOTNULL );
601708 fail ("missing expected SQLException" );
602709 } catch (SQLException e ) {
603710 assertTrue (e instanceof JdbcSqlException );
604- assertEquals (((JdbcSqlException ) e ).getCode (), Code . INVALID_ARGUMENT );
711+ assertEquals (Code . INVALID_ARGUMENT , ((JdbcSqlException ) e ).getCode ());
605712 }
606713 }
607714
@@ -625,7 +732,7 @@ public void testGetLongIndexForTimestamp() {
625732 fail ("missing expected SQLException" );
626733 } catch (SQLException e ) {
627734 assertTrue (e instanceof JdbcSqlException );
628- assertEquals (((JdbcSqlException ) e ).getCode (), Code . INVALID_ARGUMENT );
735+ assertEquals (Code . INVALID_ARGUMENT , ((JdbcSqlException ) e ).getCode ());
629736 }
630737 }
631738
@@ -669,7 +776,7 @@ public void testGetDoubleIndexFromTimestamp() {
669776 fail ("missing expected SQLException" );
670777 } catch (SQLException e ) {
671778 assertTrue (e instanceof JdbcSqlException );
672- assertEquals (((JdbcSqlException ) e ).getCode (), Code . INVALID_ARGUMENT );
779+ assertEquals (Code . INVALID_ARGUMENT , ((JdbcSqlException ) e ).getCode ());
673780 }
674781 }
675782
@@ -1392,7 +1499,7 @@ public void testGetFloatIndexFromTimestamp() {
13921499 fail ("missing expected SQLException" );
13931500 } catch (SQLException e ) {
13941501 assertTrue (e instanceof JdbcSqlException );
1395- assertEquals (((JdbcSqlException ) e ).getCode (), Code . INVALID_ARGUMENT );
1502+ assertEquals (Code . INVALID_ARGUMENT , ((JdbcSqlException ) e ).getCode ());
13961503 }
13971504 }
13981505
0 commit comments