@Test
public void testGetHighlightedTextNestedEntity() throws Exception {
String text = "This is a test sentence";
List<OffsetItem> offsetItems = new ArrayList<OffsetItem>();
OffsetItem mockEntity1 = mock(VertexOffsetItem.class);
when(mockEntity1.getStart()).thenReturn(0l);
when(mockEntity1.getEnd()).thenReturn(4l);
when(mockEntity1.getResolvedToVertexId()).thenReturn("0");
when(mockEntity1.getCssClasses()).thenReturn(asList(new String[]{"first"}));
when(mockEntity1.shouldHighlight()).thenReturn(true);
when(mockEntity1.getInfoJson()).thenReturn(new JSONObject("{\"data\":\"attribute\"}"));
offsetItems.add(mockEntity1);
OffsetItem mockEntity2 = mock(VertexOffsetItem.class);
when(mockEntity2.getStart()).thenReturn(0l);
when(mockEntity2.getEnd()).thenReturn(4l);
when(mockEntity2.getResolvedToVertexId()).thenReturn("1");
when(mockEntity2.getCssClasses()).thenReturn(asList(new String[]{"second"}));
when(mockEntity2.shouldHighlight()).thenReturn(true);
when(mockEntity2.getInfoJson()).thenReturn(new JSONObject("{\"data\":\"attribute\"}"));
offsetItems.add(mockEntity2);
OffsetItem mockEntity3 = mock(VertexOffsetItem.class);
when(mockEntity3.getStart()).thenReturn(0l);
when(mockEntity3.getEnd()).thenReturn(7l);
when(mockEntity3.getCssClasses()).thenReturn(asList(new String[]{"third"}));
when(mockEntity3.shouldHighlight()).thenReturn(true);
when(mockEntity3.getInfoJson()).thenReturn(new JSONObject("{\"data\":\"attribute\"}"));
offsetItems.add(mockEntity3);
OffsetItem mockEntity4 = mock(VertexOffsetItem.class);
when(mockEntity4.getStart()).thenReturn(5l);
when(mockEntity4.getEnd()).thenReturn(9l);
when(mockEntity4.getCssClasses()).thenReturn(asList(new String[]{"fourth"}));
when(mockEntity4.shouldHighlight()).thenReturn(true);
when(mockEntity4.getInfoJson()).thenReturn(new JSONObject("{\"data\":\"attribute\"}"));
offsetItems.add(mockEntity4);
OffsetItem mockEntity5 = mock(VertexOffsetItem.class);
when(mockEntity5.getStart()).thenReturn(15l);
when(mockEntity5.getEnd()).thenReturn(23l);
when(mockEntity5.getCssClasses()).thenReturn(asList(new String[]{"fifth"}));
when(mockEntity5.shouldHighlight()).thenReturn(true);
when(mockEntity5.getInfoJson()).thenReturn(new JSONObject("{\"data\":\"attribute\"}"));
offsetItems.add(mockEntity5);
String highlightedText = EntityHighlighter.getHighlightedText(text, offsetItems);
assertEquals("<span class=\"first\" data-info=\"{"data":"attribute"}\">This</span> " +
"<span class=\"fourth\" data-info=\"{"data":"attribute"}\">is a</span> test <span " +