19
19
20
20
import java .time .LocalDate ;
21
21
import java .time .LocalTime ;
22
+ import java .util .function .BiFunction ;
23
+ import java .util .function .Function ;
24
+ import java .util .function .Supplier ;
22
25
23
26
public abstract class BinaryDataTypeEncodeTestBase extends DataTypeTestBase {
24
27
protected abstract String statement (String ... parts );
25
28
26
29
@ Test
27
30
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 );
29
32
}
30
33
31
34
@ Test
32
35
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 );
34
37
}
35
38
36
39
@ Test
37
40
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 );
39
42
}
40
43
41
44
@ Test
42
45
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 );
44
47
}
45
48
46
49
@ Test
47
50
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 );
49
52
}
50
53
51
54
@ Test
52
55
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" ));
54
57
}
55
58
56
59
@ Test
57
60
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" ));
59
62
}
60
63
61
64
@ Test
62
65
public void testChar (TestContext ctx ) {
63
- testEncodeGeneric (ctx , "test_char" , String .class , "newchar0" );
66
+ testEncodeGeneric (ctx , "test_char" , String .class , Row :: getString , "newchar0" );
64
67
}
65
68
66
69
@ Test
67
70
public void testVarchar (TestContext ctx ) {
68
- testEncodeGeneric (ctx , "test_varchar" , String .class , "newvarchar" );
71
+ testEncodeGeneric (ctx , "test_varchar" , String .class , Row :: getString , "newvarchar" );
69
72
}
70
73
71
74
@ Test
72
75
public void testBoolean (TestContext ctx ) {
73
- testEncodeGeneric (ctx , "test_boolean" , Boolean .class , false );
76
+ testEncodeGeneric (ctx , "test_boolean" , Boolean .class , Row :: getBoolean , false );
74
77
}
75
78
76
79
@ Test
77
80
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" ));
79
82
}
80
83
81
84
@ Test
82
85
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 ));
84
87
}
85
88
86
89
@ Test
@@ -134,6 +137,7 @@ public void testNullValues(TestContext ctx) {
134
137
protected <T > void testEncodeGeneric (TestContext ctx ,
135
138
String columnName ,
136
139
Class <T > clazz ,
140
+ BiFunction <Row ,String ,T > getter ,
137
141
T expected ) {
138
142
connector .connect (ctx .asyncAssertSuccess (conn -> {
139
143
conn
@@ -147,6 +151,9 @@ protected <T> void testEncodeGeneric(TestContext ctx,
147
151
ctx .assertEquals (1 , row .size ());
148
152
ctx .assertEquals (expected , row .getValue (0 ));
149
153
ctx .assertEquals (expected , row .getValue (columnName ));
154
+ if (getter != null ) {
155
+ ctx .assertEquals (expected , getter .apply (row , columnName ));
156
+ }
150
157
// ctx.assertEquals(expected, row.get(clazz, 0));
151
158
// ColumnChecker.checkColumn(0, columnName)
152
159
// .returns(Tuple::getValue, Row::getValue, expected)
0 commit comments