### Question:
OnHCSMessageCallback implements HCSCallBackFromMirror { static Optional<ApplicationMessage> pushUntilCompleteMessage(ApplicationMessageChunk messageChunk, SxcPersistence persistence) throws InvalidProtocolBufferException { ApplicationMessageID applicationMessageId = messageChunk.getApplicationMessageId(); List<ApplicationMessageChunk> chunkList = persistence.getParts(applicationMessageId); if (chunkList==null){ chunkList = new ArrayList<ApplicationMessageChunk>(); chunkList.add(messageChunk); } else { chunkList.add(messageChunk); } persistence.putParts(applicationMessageId, chunkList); if (messageChunk.getChunksCount() == 1){ ApplicationMessage applicationMessage = ApplicationMessage.parseFrom(messageChunk.getMessageChunk()); return Optional.of( applicationMessage); } else if (chunkList.size() == messageChunk.getChunksCount()) { chunkList.sort(Comparator.comparingInt(ApplicationMessageChunk::getChunkIndex)); ByteString merged = chunkList.stream() .map(ApplicationMessageChunk::getMessageChunk) .reduce(ByteUtil::merge).get(); ApplicationMessage messageEnvelope = ApplicationMessage.parseFrom(merged); return Optional.of(messageEnvelope); } else { return Optional.empty(); } } OnHCSMessageCallback(HCSCore hcsCore); @Override void addObserver(HCSCallBackToAppInterface listener); @Override void notifyObservers(SxcConsensusMessage sxcConsensusMessage, byte[] message, ApplicationMessageID applicationMessageId); @Override void storeMirrorResponse(SxcConsensusMessage consensusMessage); @Override void partialMessage(ApplicationMessageChunk messagePart, SxcConsensusMessage sxcConsensusMesssage);  }### Answer:
@Test public void testSingleChunking() throws IOException { byte[] message = "Single Chunk Message".getBytes(); ApplicationMessage userMessageToApplicationMessage = OutboundHCSMessage.userMessageToApplicationMessage(new TransactionId(new AccountId(1234L)), message, null, null); List<ApplicationMessageChunk> chunks = OutboundHCSMessage.chunk(userMessageToApplicationMessage); assertTrue(chunks.size() == 1); SxcPersistence persistence = new Persist(); Optional<ApplicationMessage> messageOptional = OnHCSMessageCallback.pushUntilCompleteMessage(chunks.get(0), persistence); assertTrue(messageOptional.isPresent()); ApplicationMessage applicationMessage = messageOptional.get(); assertArrayEquals(message,applicationMessage.getBusinessProcessMessage().toByteArray()); }
@Test public void testMultiChunking() throws IOException { byte[] longString = RandomStringUtils.random(5000, true, true).getBytes(); ApplicationMessage userMessageToApplicationMessage = OutboundHCSMessage.userMessageToApplicationMessage(new TransactionId(new AccountId(1234L)), longString, null, null); List<ApplicationMessageChunk> chunks = OutboundHCSMessage.chunk(userMessageToApplicationMessage); assertTrue(chunks.size() == 2); Optional<ApplicationMessage> messageOptional = null; SxcPersistence persistence = new Persist(); for (ApplicationMessageChunk messagePart : chunks){ messageOptional = OnHCSMessageCallback.pushUntilCompleteMessage(messagePart, persistence); } assertTrue(messageOptional.isPresent()); ApplicationMessage applicationMessage = messageOptional.get(); assertArrayEquals(longString,applicationMessage.getBusinessProcessMessage().toByteArray()); }