### Question:
MessageComparator { private static ComparisonResult compareMessages(String name, Object actual, Object expected, boolean unchecked, boolean keyFieldsOnly, IFieldStructure structure, List<MetaContainer> metaContainers, ComparatorSettings settings) { ComparisonResult result = initialComparison(name, actual, expected, unchecked, structure, metaContainers, settings); if(result.getStatus() != null) { return result; } IMessage actualMessage = (IMessage)actual; IMessage expectedMessage = (IMessage)expected; Collection<String> fieldNames = null; Map<String, Boolean> keyFields = keyFieldsOnly ? metaContainers.get(0).getKeyFields() : Collections.emptyMap(); if (keyFieldsOnly) { fieldNames = keyFields.keySet(); } else if (structure != null) { fieldNames = structure.getFields().keySet(); } else { fieldNames = new LinkedHashSet<>(); fieldNames.addAll(actualMessage.getFieldNames()); fieldNames.addAll(expectedMessage.getFieldNames()); } for(String fieldName : fieldNames) { Object actualValue = actualMessage.getField(fieldName); Object expectedValue = expectedMessage.getField(fieldName); if(actualValue == null && expectedValue == null) { continue; } boolean uncheckedField = unchecked || settings.getUncheckedFields().contains(fieldName); boolean checkKeyFieldsOnly = keyFieldsOnly && keyFields.get(fieldName); IFieldStructure fieldStructure = structure != null ? structure.getFields().get(fieldName) : null; List<MetaContainer> subMetaContainers = getMetaContainers(metaContainers, fieldName, checkKeyFieldsOnly); result.addResult(compareValues(fieldName, actualValue, expectedValue, uncheckedField, checkKeyFieldsOnly, fieldStructure, subMetaContainers, settings)); } return result; }  static ComparisonResult compare(IMessage actual, IMessage expected, ComparatorSettings settings); @SuppressWarnings("deprecation") static ComparisonResult compare(IMessage actual, IMessage expected, ComparatorSettings settings, boolean checkNames); static double COMPARISON_PRECISION; }### Answer:
@Test public void compareMessages() throws IOException, ProtocolCodecException { IMessage msg1 = new MapMessage("MarketDataSnapshotFullRefresh", "namespace"); IMessage msg2 = new MapMessage("MarketDataSnapshotFullRefresh", "namespace"); List<IMessage> list = new ArrayList<>(); IMessage group = new MapMessage("MDEntries", "namespace"); group.addField("269", '1'); group.addField("270", 20.01D); group.addField("271", 40.01D); list.add(group); group = new MapMessage("MDEntries", "namespace"); group.addField("269", '2'); group.addField("270", 20.01D); group.addField("271", 40.01D); list.add(group); msg1.addField("MDEntries", list); list = new ArrayList<>(); list.add(group); msg2.addField("MDEntries", list); ComparatorSettings compSettings = new ComparatorSettings(); long startTime = System.currentTimeMillis(); ComparisonResult comparisonResult = MessageComparator.compare(msg1, msg2, compSettings); System.out.printf("diff %d\n", System.currentTimeMillis() - startTime); System.out.println(comparisonResult); Assert.assertEquals(0, ComparisonUtil.getResultCount(comparisonResult, StatusType.FAILED)); }