11package com .maxmind .db ;
22
33import static org .hamcrest .CoreMatchers .containsString ;
4+ import static org .hamcrest .CoreMatchers .equalTo ;
45import static org .hamcrest .MatcherAssert .assertThat ;
56import static org .junit .Assert .assertArrayEquals ;
67import static org .junit .Assert .assertEquals ;
@@ -620,6 +621,17 @@ public void testDecodeWrongTypeWithWrongArguments() throws IOException {
620621 assertThat (ex .getMessage (), containsString ("Error getting record for IP" ));
621622 }
622623
624+ @ Test
625+ public void testDecodeWithDataTypeMismatchInModel () throws IOException {
626+ this .testReader = new Reader (getFile ("GeoIP2-City-Test.mmdb" ));
627+ DeserializationException ex = assertThrows (DeserializationException .class ,
628+ () -> this .testReader .get (InetAddress .getByName ("2.125.160.216" ),
629+ TestDataTypeMismatchInModel .class ));
630+ assertThat (ex .getMessage (), containsString ("Error getting record for IP" ));
631+ assertThat (ex .getMessage (), containsString ("Error creating map entry for" ));
632+ assertThat (ex .getCause ().getCause ().getClass (), equalTo (ClassCastException .class ));
633+ }
634+
623635 static class TestWrongModelSubdivisions {
624636 List <TestWrongModelSubdivision > subdivisions ;
625637
@@ -644,6 +656,18 @@ public TestWrongModelSubdivision(
644656 }
645657 }
646658
659+ static class TestDataTypeMismatchInModel {
660+ Map <String , Float > location ;
661+
662+ @ MaxMindDbConstructor
663+ public TestDataTypeMismatchInModel (
664+ @ MaxMindDbParameter (name = "location" )
665+ Map <String , Float > location
666+ ) {
667+ this .location = location ;
668+ }
669+ }
670+
647671 @ Test
648672 public void testDecodeConcurrentHashMap () throws IOException {
649673 this .testReader = new Reader (getFile ("GeoIP2-City-Test.mmdb" ));
0 commit comments