### Question:
EntityProcessorImpl implements EntityProcessor { protected final String insertSpans(List<EntityAnnotation> annotationList, String content, EntityFormatConfiguration config) throws IOException { StringBuilder buffer = new StringBuilder(content); Set<String> terms = newHashSet(); Set<String> attrs = newHashSet(); Set<String> cssClasses = newHashSet(); for (EntityAnnotationGroup group : getAnnotationGroups(annotationList, config.isLongestOnly())) { cssClasses.clear(); attrs.clear(); terms.clear(); for (Entity entity : group.getAnnotations()) { String serialized = entity.serialize(); if (!isNullOrEmpty(serialized)) { terms.add(serialized); } cssClasses.add(recognizer.getCssClass()); } if (!terms.isEmpty()) { attrs.add(format("%s=\"%s\"", config.getDataAttrName(), on("|").join(terms))); } buffer.insert(group.getEnd(), "</span>"); buffer.insert(group.getStart(), format("<span class=\"%s\" %s>", on(" ").join(cssClasses), on(" ").join(attrs))); } return buffer.toString(); } @Inject protected  EntityProcessorImpl(EntityRecognizer recognizer); @Override List<EntityAnnotation> annotateEntities(EntityFormatConfiguration config);  }### Answer:
@Test public void testInsertAllSpans() throws Exception { String java7Expected = "Sentence about <span class=\"mock\" data-entity=\"SMA,1,|muscular atrophy,1,\">Spinal muscular atrophy</span>" + " <span class=\"mock\" data-entity=\"SMA,1,\">(SMA).</span>"; String java8Expected = "Sentence about <span class=\"mock\" data-entity=\"muscular atrophy,1,|SMA,1,\">Spinal muscular atrophy</span>" + " <span class=\"mock\" data-entity=\"SMA,1,\">(SMA).</span>"; assertThat(processor.insertSpans(expectedAnnotations, text, config), isOneOf(java7Expected, java8Expected)); }
@Test public void testInsertLongestOnlySpans() throws Exception { when(config.isLongestOnly()).thenReturn(true); String expected = "Sentence about <span class=\"mock\" data-entity=\"SMA,1,\">Spinal muscular atrophy</span>" + " <span class=\"mock\" data-entity=\"SMA,1,\">(SMA).</span>"; assertThat(processor.insertSpans(expectedAnnotations, text, config), is(expected)); }