@@ -567,6 +567,61 @@ public TestModelSubdivision(
567567 }
568568 }
569569
570+ @ Test
571+ public void testDecodeWrongTypeWithConstructorException () throws IOException {
572+ this .testReader = new Reader (getFile ("GeoIP2-City-Test.mmdb" ));
573+ DeserializationException ex = assertThrows (DeserializationException .class ,
574+ () -> this .testReader .get ( InetAddress .getByName ("2.125.160.216" ),
575+ TestModelSubdivisionsWithUnknownException .class ));
576+
577+ assertThat (ex .getMessage (), containsString ("Error getting record for IP /2.125.160.216 - Error creating object" ));
578+ }
579+
580+ static class TestModelSubdivisionsWithUnknownException {
581+ List <TestModelSubdivision > subdivisions ;
582+
583+ @ MaxMindDbConstructor
584+ public TestModelSubdivisionsWithUnknownException (
585+ @ MaxMindDbParameter (name ="subdivisions" )
586+ List <TestModelSubdivision > subdivisions
587+ ) throws Exception {
588+ throw new Exception ();
589+ }
590+ }
591+
592+ @ Test
593+ public void testDecodeWrongTypeWithWrongArguments () throws IOException {
594+ this .testReader = new Reader (getFile ("GeoIP2-City-Test.mmdb" ));
595+ DeserializationException ex = assertThrows (DeserializationException .class ,
596+ () -> this .testReader .get ( InetAddress .getByName ("2.125.160.216" ),
597+ TestWrongModelSubdivisions .class ));
598+ assertThat (ex .getMessage (), containsString ("Error getting record for IP" ));
599+ }
600+
601+ static class TestWrongModelSubdivisions {
602+ List <TestWrongModelSubdivision > subdivisions ;
603+
604+ @ MaxMindDbConstructor
605+ public TestWrongModelSubdivisions (
606+ @ MaxMindDbParameter (name ="subdivisions" )
607+ List <TestWrongModelSubdivision > subdivisions
608+ ) {
609+ this .subdivisions = subdivisions ;
610+ }
611+ }
612+
613+ static class TestWrongModelSubdivision {
614+ Integer uint16Field ;
615+ @ MaxMindDbConstructor
616+ public TestWrongModelSubdivision (
617+ @ MaxMindDbParameter (name ="iso_code" )
618+ Integer uint16Field
619+ ) {
620+ this .uint16Field = uint16Field ;
621+ ;
622+ }
623+ }
624+
570625 @ Test
571626 public void testDecodeConcurrentHashMap () throws IOException {
572627 this .testReader = new Reader (getFile ("GeoIP2-City-Test.mmdb" ));
@@ -775,7 +830,7 @@ public void voidTestMapKeyIsString() throws IOException {
775830 TestModelInvalidMap .class
776831 )
777832 );
778- assertEquals ("Map keys must be strings." , ex .getMessage ());
833+ assertEquals ("Error getting record for IP /2.125.160.216 - Map keys must be strings." , ex .getMessage ());
779834 }
780835
781836 static class TestModelInvalidMap {
0 commit comments