### Question:
ChangeLogSet { public List<ChangeLog> diff(ChangeLogSet model) { for(ChangeLog changeLog : model.changeLogs) { ChangeLog myChangeLog = bySource.get(changeLog.getSource()); if(myChangeLog != null) { for(ChangeSet changeSet : changeLog.getChangeSets()) { if(!myChangeLog.removeChangeSet(changeSet.getIdentifier())) { myChangeLog.addChangeSet(changeSet); } } if(myChangeLog.getChangeSets().isEmpty()) { changeLogs.remove(myChangeLog); bySource.remove(myChangeLog.getSource()); } } else { changeLogs.add(changeLog); bySource.put(changeLog.getSource(), changeLog); } } return changeLogs; } ChangeLogSet(List<ChangeLog> changeLogs); static ChangeLogSet fromChangesets(List<ChangeSet> changeSets); List<ChangeLog> getChangeLogs(); List<ChangeLog> diff(ChangeLogSet model); List<ChangeLog> prune(Version version); void verify(ChangeLogSet model); void verify(ChangeLogSet model, boolean verifyChecksums);  }### Answer:
@Test public void testDifferenceWhenModelIsEmpty() { ChangeLogSet set1 = new ChangeLogSet(Arrays.asList(cl1, cl2)); ChangeLogSet set2 = new ChangeLogSet(Collections.<ChangeLog>emptyList()); List<ChangeLog> differences = set1.diff(set2); assertEquals(2, differences.size()); }
@Test public void testDifferenceWithNewChangeLog() { ChangeLogSet set1 = new ChangeLogSet(Arrays.asList(cl1)); ChangeLogSet set2 = new ChangeLogSet(Arrays.asList(copy(cl1), cl2)); List<ChangeLog> differences = set1.diff(set2); assertEquals(1, differences.size()); assertEquals(cl2.getSource(), differences.get(0).getSource()); }
@Test public void testDifferenceInChangeSets() throws Exception { ChangeLogSet set1 = new ChangeLogSet(Arrays.asList(cl1)); ChangeLog cl1Copy = new ChangeLog(); cl1Copy.setSource(cl1.getSource()); cl1Copy.setVersion(cl1.getVersion()); for(ChangeSet cs : cl1.getChangeSets()) { cl1Copy.addChangeSet(cs); } ChangeSet cs = new ChangeSet(); cs.setAuthor("rob"); cs.setIdentifier("changeset5"); cl1Copy.addChangeSet(cs); ChangeLogSet set2 = new ChangeLogSet(Arrays.asList(cl1Copy)); List<ChangeLog> differences = set1.diff(set2); assertEquals(1, differences.size()); assertEquals(1, differences.get(0).getChangeSets().size()); }
@Test public void testNoDifferences() throws Exception { ChangeLogSet set1 = new ChangeLogSet(Arrays.asList(cl1)); ChangeLogSet set2 = new ChangeLogSet(Arrays.asList(copy(cl1))); List<ChangeLog> differences = set1.diff(set2); assertEquals(0, differences.size()); }