1919
2020import java .time .LocalDate ;
2121import java .time .LocalTime ;
22+ import java .util .function .BiFunction ;
23+ import java .util .function .Function ;
24+ import java .util .function .Supplier ;
2225
2326public abstract class BinaryDataTypeEncodeTestBase extends DataTypeTestBase {
2427 protected abstract String statement (String ... parts );
2528
2629 @ Test
2730 public void testSmallInt (TestContext ctx ) {
28- testEncodeGeneric (ctx , "test_int_2" , Short .class , (short ) Short .MIN_VALUE );
31+ testEncodeGeneric (ctx , "test_int_2" , Short .class , Row :: getShort , (short ) Short .MIN_VALUE );
2932 }
3033
3134 @ Test
3235 public void testInteger (TestContext ctx ) {
33- testEncodeGeneric (ctx , "test_int_4" , Integer .class , (int ) Integer .MIN_VALUE );
36+ testEncodeGeneric (ctx , "test_int_4" , Integer .class , Row :: getInteger , (int ) Integer .MIN_VALUE );
3437 }
3538
3639 @ Test
3740 public void testBigInt (TestContext ctx ) {
38- testEncodeGeneric (ctx , "test_int_8" , Long .class , (long ) Long .MIN_VALUE );
41+ testEncodeGeneric (ctx , "test_int_8" , Long .class , Row :: getLong , (long ) Long .MIN_VALUE );
3942 }
4043
4144 @ Test
4245 public void testFloat4 (TestContext ctx ) {
43- testEncodeGeneric (ctx , "test_float_4" , Float .class , (float ) -3.402823e38F );
46+ testEncodeGeneric (ctx , "test_float_4" , Float .class , Row :: getFloat , (float ) -3.402823e38F );
4447 }
4548
4649 @ Test
4750 public void testDouble (TestContext ctx ) {
48- testEncodeGeneric (ctx , "test_float_8" , Double .class , (double ) Double .MIN_VALUE );
51+ testEncodeGeneric (ctx , "test_float_8" , Double .class , Row :: getDouble , (double ) Double .MIN_VALUE );
4952 }
5053
5154 @ Test
5255 public void testNumeric (TestContext ctx ) {
53- testEncodeGeneric (ctx , "test_numeric" , Numeric .class , Numeric .parse ("-999.99" ));
56+ testEncodeGeneric (ctx , "test_numeric" , Numeric .class , null , Numeric .parse ("-999.99" ));
5457 }
5558
5659 @ Test
5760 public void testDecimal (TestContext ctx ) {
58- testEncodeGeneric (ctx , "test_decimal" , Numeric .class , Numeric .parse ("-12345" ));
61+ testEncodeGeneric (ctx , "test_decimal" , Numeric .class , null , Numeric .parse ("-12345" ));
5962 }
6063
6164 @ Test
6265 public void testChar (TestContext ctx ) {
63- testEncodeGeneric (ctx , "test_char" , String .class , "newchar0" );
66+ testEncodeGeneric (ctx , "test_char" , String .class , Row :: getString , "newchar0" );
6467 }
6568
6669 @ Test
6770 public void testVarchar (TestContext ctx ) {
68- testEncodeGeneric (ctx , "test_varchar" , String .class , "newvarchar" );
71+ testEncodeGeneric (ctx , "test_varchar" , String .class , Row :: getString , "newvarchar" );
6972 }
7073
7174 @ Test
7275 public void testBoolean (TestContext ctx ) {
73- testEncodeGeneric (ctx , "test_boolean" , Boolean .class , false );
76+ testEncodeGeneric (ctx , "test_boolean" , Boolean .class , Row :: getBoolean , false );
7477 }
7578
7679 @ Test
7780 public void testDate (TestContext ctx ) {
78- testEncodeGeneric (ctx , "test_date" , LocalDate .class , LocalDate .parse ("1999-12-31" ));
81+ testEncodeGeneric (ctx , "test_date" , LocalDate .class , Row :: getLocalDate , LocalDate .parse ("1999-12-31" ));
7982 }
8083
8184 @ Test
8285 public void testTime (TestContext ctx ) {
83- testEncodeGeneric (ctx , "test_time" , LocalTime .class , LocalTime .of (12 ,1 ,30 ));
86+ testEncodeGeneric (ctx , "test_time" , LocalTime .class , Row :: getLocalTime , LocalTime .of (12 ,1 ,30 ));
8487 }
8588
8689 @ Test
@@ -134,6 +137,7 @@ public void testNullValues(TestContext ctx) {
134137 protected <T > void testEncodeGeneric (TestContext ctx ,
135138 String columnName ,
136139 Class <T > clazz ,
140+ BiFunction <Row ,String ,T > getter ,
137141 T expected ) {
138142 connector .connect (ctx .asyncAssertSuccess (conn -> {
139143 conn
@@ -147,6 +151,9 @@ protected <T> void testEncodeGeneric(TestContext ctx,
147151 ctx .assertEquals (1 , row .size ());
148152 ctx .assertEquals (expected , row .getValue (0 ));
149153 ctx .assertEquals (expected , row .getValue (columnName ));
154+ if (getter != null ) {
155+ ctx .assertEquals (expected , getter .apply (row , columnName ));
156+ }
150157// ctx.assertEquals(expected, row.get(clazz, 0));
151158// ColumnChecker.checkColumn(0, columnName)
152159// .returns(Tuple::getValue, Row::getValue, expected)
0 commit comments