@Test
public void shouldHandleList() {

  Codec<List<String>> listStringCodec = mapper.codecFor(new RawList(primitive(VARCHAR)));
  Codec<List<String>> listStringCodec2 = mapper.codecFor(new RawList(primitive(VARCHAR)));
  // Repetitive calls should yield thes ame instance.
  assertThat(listStringCodec).isSameAs(listStringCodec2);
  List<String> l = new ArrayList<>();
  l.add("one");
  l.add("two");
  l.add("one");
  String listStr = "0x00000003000000036f6e650000000374776f000000036f6e65";
  encodeAndDecode(
      listStringCodec, Collections.singletonList("hello"), "0x000000010000000568656c6c6f");
  encodeAndDecode(listStringCodec, l, listStr);
  encodeAndDecode(listStringCodec, Collections.emptyList(), "0x00000000");
  encodeAndDecode(listStringCodec, null, null, Collections.emptyList());
  encodeObjectAndDecode(listStringCodec, l, listStr, l);
  encodeObjectAndDecode(listStringCodec, new LinkedBlockingQueue<>(l), listStr, l);
  encodeObjectAndDecode(listStringCodec, null, null, Collections.emptyList());
  encodeObjectAndDecode(listStringCodec, Optional.of(12), null, Collections.emptyList());
  // Null value in List
  try {
    encodeAndDecode(listStringCodec, Collections.singletonList(null), null);
    fail("Expected NPE");
  } catch (NullPointerException e) { // expected
  }
  // List not matching type for Codec
  try {
    List intList = new ArrayList<>();
    intList.add(1);
    encodeAndDecode(listStringCodec, intList, "");
    fail("Expected InvalidTypeException");
  } catch (InvalidTypeException e) {
    assertThat(e.getCause()).isInstanceOf(ClassCastException.class);
  }
  // Underflow while decoding
  try {
    ByteBuffer buf = listStringCodec.encode(l);
    // half limit so buffer is truncated.
    buf.limit(buf.limit() / 2);
    listStringCodec.decode(buf);
    fail("Expected InvalidTypeException");
  } catch (InvalidTypeException e) {
    assertThat(e.getCause()).isInstanceOf(BufferUnderflowException.class);
  }
  // Values of set should be mapped using encodeObject
  // In this case we have a codec that calls for list<ascii> but we give it a Set<Integer>.
  // The codec should properly convert to List<String> from List<Integer>.
  Set<Integer> intSet = new LinkedHashSet<>();
  intSet.add(1);
  intSet.add(2);
  intSet.add(-40);
  List<String> stringList = new ArrayList<>();
  stringList.add("1");
  stringList.add("2");
  stringList.add("-40");
  encodeObjectAndDecode(
      listStringCodec, intSet, "0x0000000300000001310000000132000000032d3430", stringList);
}