### Question:
ChunkConverter { public List<ContentChunk> convert(List<ContentChunk> chunkList, long totalLength) { if (chunkList.isEmpty() || isChunksUnderLimit(chunkList)) { return chunkList; } ArrayList<ContentChunk> convertedChunks = new ArrayList<>(); long pendingBytes = totalLength; long offset = 0; ContentReader contentReader = new ContentReader(chunkList); while (pendingBytes > 0) { long newBufferLength = Math.min(pendingBytes, maxChunkSizeLimit); ContentChunk newChunk = new ContentChunk(offset, contentReader.getNextBytes((int) newBufferLength)); convertedChunks.add(newChunk); pendingBytes = pendingBytes - newBufferLength; offset = offset + newBufferLength; } return convertedChunks; } ChunkConverter(int maxChunkSizeLimit); List<ContentChunk> convert(List<ContentChunk> chunkList, long totalLength);  }### Answer:
@Test public void testConvertLarge() { ChunkConverter converter = new ChunkConverter(10); int chunkLength = 12; String stringData = RandomStringGenerator.randomString(chunkLength); List<ContentChunk> beforeList = createContentChunks(stringData, 1); List<ContentChunk> afterList = converter.convert(beforeList, chunkLength); Assert.assertEquals(afterList.size(), 2, "After converting there should be only two chunks"); String convertedDataString = getString(afterList, chunkLength); Assert.assertEquals(convertedDataString, stringData, "Content should be equal after conversion"); }
@Test public void testConvertLargeMultiple() { ChunkConverter converter = new ChunkConverter(10); int chunkLength = 30; String stringData = RandomStringGenerator.randomString(chunkLength); List<ContentChunk> beforeList = createContentChunks(stringData, 2); List<ContentChunk> afterList = converter.convert(beforeList, chunkLength); Assert.assertEquals(afterList.size(), 3, "After converting there should be only three chunks"); String convertedDataString = getString(afterList, chunkLength); Assert.assertEquals(convertedDataString, stringData, "Content should be equal after conversion"); }
@Test public void testConvertSmall() { ChunkConverter converter = new ChunkConverter(10); int chunkLength = 8; List<ContentChunk> beforeList = createContentChunk(chunkLength); List<ContentChunk> afterList = converter.convert(beforeList, chunkLength); Assert.assertEquals(afterList, beforeList, "Smaller chunks should not be converted"); }
@Test public void testConvertEmpty() { ChunkConverter converter = new ChunkConverter(10); int chunkLength = 8; List<ContentChunk> beforeList = new ArrayList<>(); List<ContentChunk> afterList = converter.convert(beforeList, chunkLength); Assert.assertEquals(afterList, beforeList, "Empty chunk list should not be converted"); }