### Question:
GeneratedSourceMerger { public String merge (String newlyGenerated, String previouslyGenerated) throws Exception { Map<String, Section> sections = Maps.newLinkedHashMap(); Matcher m = _sectionDelimiter.matcher(newlyGenerated); while (m.find()) { Section section = extractGeneratedSection(m, newlyGenerated); Preconditions.checkArgument(!sections.containsKey(section.name), "Section '%s' used more than once", section.name); sections.put(section.name, section); } StringBuilder merged = new StringBuilder(); m = _sectionDelimiter.matcher(previouslyGenerated); int currentStart = 0; while (m.find()) { merged.append(previouslyGenerated.substring(currentStart, m.start())); Section existingSection = extractGeneratedSection(m, previouslyGenerated); Section newSection = sections.remove(existingSection.name); if (newSection == null) { System.err.println("Dropping previously generated section '" + m.group(1) + "' that's no longer generated by the template"); } else if (existingSection.disabled) { merged.append(existingSection.contents); } else { merged.append(newSection.contents); } currentStart = m.end(); } for (Section newSection : sections.values()) { System.err.println("Adding previously missing generated section '" + newSection.name + "' before the last non-generated text"); merged.append(newSection.contents); } merged.append(previouslyGenerated.substring(currentStart)); return merged.toString(); }  String merge(String newlyGenerated, String previouslyGenerated);  }### Answer:
@Test public void mergeNothing () throws Exception { new GeneratedSourceMerger().merge("", ""); }
@Test public void mergeUpdatedSection () throws Exception { String modified = before + " "var s :String = 'byte';\n" + " assertEquals(generated, new GeneratedSourceMerger().merge(generated, modified)); }
@Test public void mergeMissingSection () throws Exception { assertEquals(section + before, new GeneratedSourceMerger().merge(generated, before)); }
@Test public void ignoreDisabledSection () throws Exception { String disabled = " assertEquals(disabled, new GeneratedSourceMerger().merge(generated, disabled)); }
@Test public void dropOldSection () throws Exception { String previous = " "var noLongerNeeded :String = 'hi';\n" + " generated; assertEquals(generated, new GeneratedSourceMerger().merge(generated, previous)); }