@Test public void test_calculateChecksum_orderIndependent() throws Exception{ Component component2 = Component.Builder.create("a", "b", "name2").build(); Component component3 = Component.Builder.create("b", "a", "name3").build(); Component component4 = Component.Builder.create("c", "c", "name4").build(); List<Component> components1 = new ArrayList<Component>(); components1.add(component); components1.add(component2); components1.add(component3); components1.add(component4); String checksum1 = componentService.calculateChecksum(components1); assert checksum1 != null; List<Component> components2 = new ArrayList<Component>(); components2.add(component3); components2.add(component2); components2.add(component); components2.add(component4); String checksum2 = componentService.calculateChecksum(components2); assert checksum2 != null; assertTrue("Checksums match",StringUtils.equals(checksum1,checksum2)); }
protected String calculateChecksum(List<Component> components) { Collections.sort(components, new Comparator<Component>() { @Override public int compare(Component component1, Component component2) { return CompareToBuilder.reflectionCompare(component1, component2); } }); return ChecksumUtils.calculateChecksum(components); }
ComponentServiceImpl implements ComponentService { protected String calculateChecksum(List<Component> components) { Collections.sort(components, new Comparator<Component>() { @Override public int compare(Component component1, Component component2) { return CompareToBuilder.reflectionCompare(component1, component2); } }); return ChecksumUtils.calculateChecksum(components); } }
ComponentServiceImpl implements ComponentService { protected String calculateChecksum(List<Component> components) { Collections.sort(components, new Comparator<Component>() { @Override public int compare(Component component1, Component component2) { return CompareToBuilder.reflectionCompare(component1, component2); } }); return ChecksumUtils.calculateChecksum(components); }  }
ComponentServiceImpl implements ComponentService { protected String calculateChecksum(List<Component> components) { Collections.sort(components, new Comparator<Component>() { @Override public int compare(Component component1, Component component2) { return CompareToBuilder.reflectionCompare(component1, component2); } }); return ChecksumUtils.calculateChecksum(components); }  @Override Component getComponentByCode(String namespaceCode, String componentCode); @Override List<Component> getAllComponentsByNamespaceCode(String namespaceCode); @Override List<Component> getActiveComponentsByNamespaceCode(String namespaceCode); @Override List<Component> getDerivedComponentSet(String componentSetId); @Override @Transactional void publishDerivedComponents(String componentSetId, List<Component> components); ComponentSetDao getComponentSetDao(); void setComponentSetDao(ComponentSetDao componentSetDao); DataObjectService getDataObjectService(); @Required void setDataObjectService(DataObjectService dataObjectService); }
ComponentServiceImpl implements ComponentService { protected String calculateChecksum(List<Component> components) { Collections.sort(components, new Comparator<Component>() { @Override public int compare(Component component1, Component component2) { return CompareToBuilder.reflectionCompare(component1, component2); } }); return ChecksumUtils.calculateChecksum(components); }  @Override Component getComponentByCode(String namespaceCode, String componentCode); @Override List<Component> getAllComponentsByNamespaceCode(String namespaceCode); @Override List<Component> getActiveComponentsByNamespaceCode(String namespaceCode); @Override List<Component> getDerivedComponentSet(String componentSetId); @Override @Transactional void publishDerivedComponents(String componentSetId, List<Component> components); ComponentSetDao getComponentSetDao(); void setComponentSetDao(ComponentSetDao componentSetDao); DataObjectService getDataObjectService(); @Required void setDataObjectService(DataObjectService dataObjectService);  }