71
71
*/
72
72
@ RunWith (Parameterized .class )
73
73
public class AvaticaResultSetConversionsTest {
74
+
75
+ // UTC: 2016-10-10 20:18:38.123
76
+ // October 10 is considered DST in all time zones that observe DST (both hemispheres), so tests
77
+ // using this value will cover daylight time zone conversion when run in a location that observes
78
+ // DST. This is just a matter of coverage; all tests must succeed no matter where the host is.
79
+ private static final long DST_INSTANT = 1476130718123L ;
80
+ private static final String DST_DATE_STRING = "2016-10-10" ;
81
+ private static final String DST_TIME_STRING = "20:18:38" ;
82
+ private static final String DST_TIMESTAMP_STRING = "2016-10-10 20:18:38" ;
83
+
84
+ // UTC: 2016-11-14 11:32:03.242
85
+ // There is no date where all time zones (both hemispheres) are on standard time, but all northern
86
+ // time zones observe standard time by mid-November. Tests using this value may or may not
87
+ // exercise standard time zone conversion, but this is just a matter of coverage; all tests must
88
+ // succeed no matter where the host is.
89
+ private static final long STANDARD_INSTANT = 1479123123242L ;
90
+
91
+ // UTC: 00:24:36.123
92
+ private static final long VALID_TIME = 1476123L ;
93
+
94
+ // UTC: 41:05:12.242
95
+ private static final long OVERFLOW_TIME = 147912242L ;
96
+
74
97
/**
75
98
* A fake test driver for test.
76
99
*/
@@ -215,15 +238,15 @@ public TestMetaImpl(AvaticaConnection connection) {
215
238
List <Object > row = Collections .<Object >singletonList (
216
239
new Object [] {
217
240
true , (byte ) 1 , (short ) 2 , 3 , 4L , 5.0f , 6.0d , "testvalue" ,
218
- new Date (1476130718123L ), new Time (1476130718123L ),
219
- new Timestamp (1476130718123L ),
241
+ new Date (DST_INSTANT ), new Time (DST_INSTANT ),
242
+ new Timestamp (DST_INSTANT ),
220
243
Arrays .asList (1 , 2 , 3 ),
221
244
new StructImpl (Arrays .asList (42 , false )),
222
245
true ,
223
246
null ,
224
247
Arrays .asList (123 , 18234 ),
225
- Arrays .asList (1476130718123L , 1479123123242L ),
226
- Arrays .asList (1476123L , 147912242L ),
248
+ Arrays .asList (DST_INSTANT , STANDARD_INSTANT ),
249
+ Arrays .asList (VALID_TIME , OVERFLOW_TIME ),
227
250
Arrays .asList (1 , 1.1 )
228
251
});
229
252
@@ -653,7 +676,7 @@ private TimeArrayAccessorTestHelper(Getter g) {
653
676
ColumnMetaData .scalar (Types .TIME , "TIME" , ColumnMetaData .Rep .NUMBER );
654
677
Array expectedArray =
655
678
new ArrayFactoryImpl (TimeZone .getTimeZone ("UTC" )).createArray (
656
- intType , Arrays .asList (1476123L , 147912242L ));
679
+ intType , Arrays .asList (VALID_TIME , OVERFLOW_TIME ));
657
680
assertTrue (ArrayImpl .equalContents (expectedArray , g .getArray (resultSet )));
658
681
}
659
682
}
@@ -671,7 +694,7 @@ private TimestampArrayAccessorTestHelper(Getter g) {
671
694
ColumnMetaData .scalar (Types .TIMESTAMP , "TIMESTAMP" , ColumnMetaData .Rep .PRIMITIVE_LONG );
672
695
Array expectedArray =
673
696
new ArrayFactoryImpl (TimeZone .getTimeZone ("UTC" )).createArray (
674
- intType , Arrays .asList (1476130718123L , 1479123123242L ));
697
+ intType , Arrays .asList (DST_INSTANT , STANDARD_INSTANT ));
675
698
assertTrue (ArrayImpl .equalContents (expectedArray , g .getArray (resultSet )));
676
699
}
677
700
}
@@ -986,7 +1009,7 @@ private DateAccessorTestHelper(Getter g) {
986
1009
}
987
1010
988
1011
@ Override public void testGetString (ResultSet resultSet ) throws SQLException {
989
- assertEquals ("2016-10-10" , g .getString (resultSet ));
1012
+ assertEquals (DST_DATE_STRING , g .getString (resultSet ));
990
1013
}
991
1014
992
1015
@ Override public void testGetBoolean (ResultSet resultSet ) throws SQLException {
@@ -1010,7 +1033,7 @@ private DateAccessorTestHelper(Getter g) {
1010
1033
}
1011
1034
1012
1035
@ Override public void testGetDate (ResultSet resultSet , Calendar calendar ) throws SQLException {
1013
- assertEquals (new Date (1476130718123L ), g .getDate (resultSet , calendar ));
1036
+ assertEquals (new Date (DST_INSTANT ), g .getDate (resultSet , calendar ));
1014
1037
}
1015
1038
}
1016
1039
@@ -1023,31 +1046,31 @@ private TimeAccessorTestHelper(Getter g) {
1023
1046
}
1024
1047
1025
1048
@ Override public void testGetString (ResultSet resultSet ) throws SQLException {
1026
- assertEquals ("20:18:38" , g .getString (resultSet ));
1049
+ assertEquals (DST_TIME_STRING , g .getString (resultSet ));
1027
1050
}
1028
1051
1029
1052
@ Override public void testGetBoolean (ResultSet resultSet ) throws SQLException {
1030
1053
assertEquals (true , g .getBoolean (resultSet ));
1031
1054
}
1032
1055
1033
1056
@ Override public void testGetByte (ResultSet resultSet ) throws SQLException {
1034
- assertEquals ((byte ) - 85 , g .getByte (resultSet ));
1057
+ assertEquals ((byte ) DST_INSTANT , g .getByte (resultSet ));
1035
1058
}
1036
1059
1037
1060
@ Override public void testGetShort (ResultSet resultSet ) throws SQLException {
1038
- assertEquals ((short ) - 20053 , g .getShort (resultSet ));
1061
+ assertEquals ((short ) ( DST_INSTANT % DateTimeUtils . MILLIS_PER_DAY ) , g .getShort (resultSet ));
1039
1062
}
1040
1063
1041
1064
@ Override public void testGetInt (ResultSet resultSet ) throws SQLException {
1042
- assertEquals (73118123 , g .getInt (resultSet ));
1065
+ assertEquals (( int ) ( DST_INSTANT % DateTimeUtils . MILLIS_PER_DAY ) , g .getInt (resultSet ));
1043
1066
}
1044
1067
1045
1068
@ Override public void testGetLong (ResultSet resultSet ) throws SQLException {
1046
- assertEquals (73118123 , g .getLong (resultSet ));
1069
+ assertEquals (DST_INSTANT % DateTimeUtils . MILLIS_PER_DAY , g .getLong (resultSet ));
1047
1070
}
1048
1071
1049
1072
@ Override public void testGetTime (ResultSet resultSet , Calendar calendar ) throws SQLException {
1050
- assertEquals (new Time (1476130718123L ), g .getTime (resultSet , calendar ));
1073
+ assertEquals (new Time (DST_INSTANT ), g .getTime (resultSet , calendar ));
1051
1074
}
1052
1075
}
1053
1076
@@ -1060,40 +1083,40 @@ private TimestampAccessorTestHelper(Getter g) {
1060
1083
}
1061
1084
1062
1085
@ Override public void testGetString (ResultSet resultSet ) throws SQLException {
1063
- assertEquals ("2016-10-10 20:18:38" , g .getString (resultSet ));
1086
+ assertEquals (DST_TIMESTAMP_STRING , g .getString (resultSet ));
1064
1087
}
1065
1088
1066
1089
@ Override public void testGetBoolean (ResultSet resultSet ) throws SQLException {
1067
1090
assertEquals (true , g .getBoolean (resultSet ));
1068
1091
}
1069
1092
1070
1093
@ Override public void testGetByte (ResultSet resultSet ) throws SQLException {
1071
- assertEquals ((byte ) - 85 , g .getByte (resultSet ));
1094
+ assertEquals ((byte ) DST_INSTANT , g .getByte (resultSet ));
1072
1095
}
1073
1096
1074
1097
@ Override public void testGetShort (ResultSet resultSet ) throws SQLException {
1075
- assertEquals ((short ) 16811 , g .getShort (resultSet ));
1098
+ assertEquals ((short ) DST_INSTANT , g .getShort (resultSet ));
1076
1099
}
1077
1100
1078
1101
@ Override public void testGetInt (ResultSet resultSet ) throws SQLException {
1079
- assertEquals (- 1338031701 , g .getInt (resultSet ));
1102
+ assertEquals (( int ) DST_INSTANT , g .getInt (resultSet ));
1080
1103
}
1081
1104
1082
1105
@ Override public void testGetLong (ResultSet resultSet ) throws SQLException {
1083
- assertEquals (1476130718123L , g .getLong (resultSet ));
1106
+ assertEquals (DST_INSTANT , g .getLong (resultSet ));
1084
1107
}
1085
1108
1086
1109
@ Override public void testGetDate (ResultSet resultSet , Calendar calendar ) throws SQLException {
1087
- assertEquals (new Date (1476130718123L ), g .getDate (resultSet , calendar ));
1110
+ assertEquals (new Date (DST_INSTANT ), g .getDate (resultSet , calendar ));
1088
1111
}
1089
1112
1090
1113
@ Override public void testGetTime (ResultSet resultSet , Calendar calendar ) throws SQLException {
1091
- assertEquals (new Time (1476130718123L ), g .getTime (resultSet , calendar ));
1114
+ assertEquals (new Time (DST_INSTANT ), g .getTime (resultSet , calendar ));
1092
1115
}
1093
1116
1094
1117
@ Override public void testGetTimestamp (ResultSet resultSet , Calendar calendar )
1095
1118
throws SQLException {
1096
- assertEquals (new Timestamp (1476130718123L ), g .getTimestamp (resultSet , calendar ));
1119
+ assertEquals (new Timestamp (DST_INSTANT ), g .getTimestamp (resultSet , calendar ));
1097
1120
}
1098
1121
}
1099
1122
@@ -1110,7 +1133,7 @@ private StringAccessorTestHelper(Getter g) {
1110
1133
}
1111
1134
}
1112
1135
1113
- private static final Calendar DEFAULT_CALENDAR = DateTimeUtils .calendar ();
1136
+ private static final Calendar UTC_CALENDAR = DateTimeUtils .calendar ();
1114
1137
1115
1138
private static Connection connection = null ;
1116
1139
private static ResultSet resultSet = null ;
@@ -1282,17 +1305,17 @@ public void testGetArray() throws SQLException {
1282
1305
1283
1306
@ Test
1284
1307
public void testGetDate () throws SQLException {
1285
- testHelper .testGetDate (resultSet , DEFAULT_CALENDAR );
1308
+ testHelper .testGetDate (resultSet , UTC_CALENDAR );
1286
1309
}
1287
1310
1288
1311
@ Test
1289
1312
public void testGetTime () throws SQLException {
1290
- testHelper .testGetTime (resultSet , DEFAULT_CALENDAR );
1313
+ testHelper .testGetTime (resultSet , UTC_CALENDAR );
1291
1314
}
1292
1315
1293
1316
@ Test
1294
1317
public void testGetTimestamp () throws SQLException {
1295
- testHelper .testGetTimestamp (resultSet , DEFAULT_CALENDAR );
1318
+ testHelper .testGetTimestamp (resultSet , UTC_CALENDAR );
1296
1319
}
1297
1320
1298
1321
@ Test
0 commit comments