### Question:
MutateInUtil { static byte[] convertDocsToBytes(final List<?> docs, final JsonSerializer serializer) { if (docs.size() == 1) { return serializer.serialize(docs.get(0)); } else { final ByteBuf bytes = UnpooledByteBufAllocator.DEFAULT.heapBuffer(); try { final Iterator<?> it = docs.iterator(); while (it.hasNext()) { Object d = it.next(); bytes.writeBytes(serializer.serialize(d)); if (it.hasNext()) { bytes.writeByte(','); } } return ByteBufUtil.getBytes(bytes); } finally { bytes.release(); } } } private  MutateInUtil();   }### Answer:
@Test void convertsEmptyDocList() { byte[] result = MutateInUtil.convertDocsToBytes(Collections.emptyList(), JSON_SERIALIZER); assertEquals(0, result.length); }
@Test void convertsSingleDocList() { JsonObject input = JsonObject.create().put("hello", "world"); byte[] result = MutateInUtil.convertDocsToBytes(Collections.singletonList(input), JSON_SERIALIZER); assertArrayEquals("{\"hello\":\"world\"}".getBytes(StandardCharsets.UTF_8), result); }
@Test void convertsMultiDocList() { JsonObject i1 = JsonObject.create().put("hello", "world"); String i2 = "What?"; boolean i3 = false; byte[] result = MutateInUtil.convertDocsToBytes(Arrays.asList(i1, i2, i3), JSON_SERIALIZER); assertArrayEquals("{\"hello\":\"world\"},\"What?\",false".getBytes(StandardCharsets.UTF_8), result); }