@@ -1148,10 +1148,95 @@ public TestModelVector(
11481148 @ MaxMindDbParameter (name = "array" )
11491149 Vector <Long > arrayField
11501150 ) {
1151- this .arrayField = arrayField ;
1151+ this .arrayField = arrayField ;
1152+ }
1153+ }
1154+
1155+ // Positive tests for primitive constructor parameters
1156+ static class TestModelPrimitivesBasic {
1157+ boolean booleanField ;
1158+ double doubleField ;
1159+ float floatField ;
1160+ int int32Field ;
1161+ long uint32Field ;
1162+
1163+ @ MaxMindDbConstructor
1164+ public TestModelPrimitivesBasic (
1165+ @ MaxMindDbParameter (name = "boolean" ) boolean booleanField ,
1166+ @ MaxMindDbParameter (name = "double" ) double doubleField ,
1167+ @ MaxMindDbParameter (name = "float" ) float floatField ,
1168+ @ MaxMindDbParameter (name = "int32" ) int int32Field ,
1169+ @ MaxMindDbParameter (name = "uint32" ) long uint32Field
1170+ ) {
1171+ this .booleanField = booleanField ;
1172+ this .doubleField = doubleField ;
1173+ this .floatField = floatField ;
1174+ this .int32Field = int32Field ;
1175+ this .uint32Field = uint32Field ;
1176+ }
1177+ }
1178+
1179+ @ ParameterizedTest
1180+ @ MethodSource ("chunkSizes" )
1181+ public void testPrimitiveConstructorParamsBasicWorks (int chunkSize ) throws IOException {
1182+ this .testReader = new Reader (getFile ("MaxMind-DB-test-decoder.mmdb" ), chunkSize );
1183+
1184+ var model = this .testReader .get (
1185+ InetAddress .getByName ("::1.1.1.0" ),
1186+ TestModelPrimitivesBasic .class
1187+ );
1188+
1189+ assertTrue (model .booleanField );
1190+ assertEquals (42.123456 , model .doubleField , 0.000000001 );
1191+ assertEquals (1.1 , model .floatField , 0.000001 );
1192+ assertEquals (-268435456 , model .int32Field );
1193+ assertEquals (268435456L , model .uint32Field );
1194+ }
1195+
1196+ static class TestModelShortPrimitive {
1197+ short uint16Field ;
1198+
1199+ @ MaxMindDbConstructor
1200+ public TestModelShortPrimitive (
1201+ @ MaxMindDbParameter (name = "uint16" ) short uint16Field
1202+ ) {
1203+ this .uint16Field = uint16Field ;
1204+ }
1205+ }
1206+
1207+ @ ParameterizedTest
1208+ @ MethodSource ("chunkSizes" )
1209+ public void testPrimitiveConstructorParamShortWorks (int chunkSize ) throws IOException {
1210+ this .testReader = new Reader (getFile ("MaxMind-DB-test-decoder.mmdb" ), chunkSize );
1211+ var model = this .testReader .get (
1212+ InetAddress .getByName ("::1.1.1.0" ),
1213+ TestModelShortPrimitive .class
1214+ );
1215+ assertEquals ((short ) 100 , model .uint16Field );
1216+ }
1217+
1218+ static class TestModelBytePrimitive {
1219+ byte uint16Field ;
1220+
1221+ @ MaxMindDbConstructor
1222+ public TestModelBytePrimitive (
1223+ @ MaxMindDbParameter (name = "uint16" ) byte uint16Field
1224+ ) {
1225+ this .uint16Field = uint16Field ;
11521226 }
11531227 }
11541228
1229+ @ ParameterizedTest
1230+ @ MethodSource ("chunkSizes" )
1231+ public void testPrimitiveConstructorParamByteWorks (int chunkSize ) throws IOException {
1232+ this .testReader = new Reader (getFile ("MaxMind-DB-test-decoder.mmdb" ), chunkSize );
1233+ var model = this .testReader .get (
1234+ InetAddress .getByName ("::1.1.1.0" ),
1235+ TestModelBytePrimitive .class
1236+ );
1237+ assertEquals ((byte ) 100 , model .uint16Field );
1238+ }
1239+
11551240 // Test that we cache differently depending on more than the offset.
11561241 @ ParameterizedTest
11571242 @ MethodSource ("chunkSizes" )
0 commit comments