@@ -229,6 +229,29 @@ public void should_create_list_codec_for_java_value() throws UnknownHostExceptio
229229 inOrder .verify (onCacheLookup ).accept (null , GenericType .listOf (GenericType .INTEGER ));
230230 }
231231
232+ @ Test
233+ public void should_create_list_codec_for_java_value_when_first_element_is_a_subtype ()
234+ throws UnknownHostException {
235+ ListType cqlType = DataTypes .listOf (DataTypes .INET );
236+ GenericType <List <InetAddress >> javaType = new GenericType <List <InetAddress >>() {};
237+ InetAddress address = InetAddress .getByAddress (new byte [] {127 , 0 , 0 , 1 });
238+ // Because the actual implementation is a subclass, there is no exact match with the codec's
239+ // declared type
240+ assertThat (address ).isInstanceOf (Inet4Address .class );
241+ List <InetAddress > value = ImmutableList .of (address );
242+
243+ TestCachingCodecRegistry registry = new TestCachingCodecRegistry (onCacheLookup );
244+ InOrder inOrder = Mockito .inOrder (onCacheLookup );
245+
246+ TypeCodec <List <InetAddress >> codec = registry .codecFor (value );
247+ assertThat (codec ).isNotNull ();
248+ assertThat (codec .canDecode (cqlType )).isTrue ();
249+ assertThat (codec .canEncode (javaType )).isTrue ();
250+ assertThat (codec .canEncode (value )).isTrue ();
251+
252+ inOrder .verify (onCacheLookup ).accept (null , GenericType .listOf (Inet4Address .class ));
253+ }
254+
232255 @ Test
233256 public void should_create_set_codec_for_cql_and_java_types () {
234257 SetType cqlType = DataTypes .setOf (DataTypes .setOf (DataTypes .INT ));
@@ -286,6 +309,29 @@ public void should_create_set_codec_for_java_value() {
286309 inOrder .verify (onCacheLookup ).accept (null , GenericType .setOf (GenericType .INTEGER ));
287310 }
288311
312+ @ Test
313+ public void should_create_set_codec_for_java_value_when_first_element_is_a_subtype ()
314+ throws UnknownHostException {
315+ SetType cqlType = DataTypes .setOf (DataTypes .INET );
316+ GenericType <Set <InetAddress >> javaType = new GenericType <Set <InetAddress >>() {};
317+ InetAddress address = InetAddress .getByAddress (new byte [] {127 , 0 , 0 , 1 });
318+ // Because the actual implementation is a subclass, there is no exact match with the codec's
319+ // declared type
320+ assertThat (address ).isInstanceOf (Inet4Address .class );
321+ Set <InetAddress > value = ImmutableSet .of (address );
322+
323+ TestCachingCodecRegistry registry = new TestCachingCodecRegistry (onCacheLookup );
324+ InOrder inOrder = Mockito .inOrder (onCacheLookup );
325+
326+ TypeCodec <Set <InetAddress >> codec = registry .codecFor (value );
327+ assertThat (codec ).isNotNull ();
328+ assertThat (codec .canDecode (cqlType )).isTrue ();
329+ assertThat (codec .canEncode (javaType )).isTrue ();
330+ assertThat (codec .canEncode (value )).isTrue ();
331+
332+ inOrder .verify (onCacheLookup ).accept (null , GenericType .setOf (Inet4Address .class ));
333+ }
334+
289335 @ Test
290336 public void should_create_map_codec_for_cql_and_java_types () {
291337 MapType cqlType = DataTypes .mapOf (DataTypes .INT , DataTypes .mapOf (DataTypes .INT , DataTypes .INT ));
@@ -350,6 +396,32 @@ public void should_create_map_codec_for_java_value() {
350396 .accept (null , GenericType .mapOf (GenericType .INTEGER , GenericType .INTEGER ));
351397 }
352398
399+ @ Test
400+ public void should_create_map_codec_for_java_value_when_first_element_is_a_subtype ()
401+ throws UnknownHostException {
402+ MapType cqlType = DataTypes .mapOf (DataTypes .INET , DataTypes .INET );
403+ GenericType <Map <InetAddress , InetAddress >> javaType =
404+ new GenericType <Map <InetAddress , InetAddress >>() {};
405+ InetAddress address = InetAddress .getByAddress (new byte [] {127 , 0 , 0 , 1 });
406+ // Because the actual implementation is a subclass, there is no exact match with the codec's
407+ // declared type
408+ assertThat (address ).isInstanceOf (Inet4Address .class );
409+ Map <InetAddress , InetAddress > value = ImmutableMap .of (address , address );
410+
411+ TestCachingCodecRegistry registry = new TestCachingCodecRegistry (onCacheLookup );
412+ InOrder inOrder = Mockito .inOrder (onCacheLookup );
413+
414+ TypeCodec <Map <InetAddress , InetAddress >> codec = registry .codecFor (value );
415+ assertThat (codec ).isNotNull ();
416+ assertThat (codec .canDecode (cqlType )).isTrue ();
417+ assertThat (codec .canEncode (javaType )).isTrue ();
418+ assertThat (codec .canEncode (value )).isTrue ();
419+
420+ inOrder
421+ .verify (onCacheLookup )
422+ .accept (null , GenericType .mapOf (Inet4Address .class , Inet4Address .class ));
423+ }
424+
353425 @ Test
354426 public void should_create_tuple_codec_for_cql_and_java_types () {
355427 TupleType cqlType = DataTypes .tupleOf (DataTypes .INT , DataTypes .listOf (DataTypes .TEXT ));
0 commit comments