@Test
public void should_highlight_only_partially_if_file_can_not_be_lexed() throws Exception {

  File file = TestUtils.getResource("/org/sonar/plugins/groovy/foundation/Error.groovy");
  SensorContextTester context = SensorContextTester.create(file.getParentFile());
  DefaultInputFile inputFile = new DefaultInputFile("", "Error.groovy")
    .setLanguage(Groovy.KEY)
    .setType(Type.MAIN)
    .initMetadata(new String(Files.readAllBytes(file.toPath()), "UTF-8"));
  context.fileSystem().add(inputFile);
  GroovyHighlighterAndTokenizer highlighter = new GroovyHighlighterAndTokenizer(inputFile);
  context = Mockito.spy(context);
  highlighter.processFile(context);
  assertThat(context.highlightingTypeAt(":Error.groovy", 1, 0)).containsOnly(TypeOfText.KEYWORD);
  assertThat(context.highlightingTypeAt(":Error.groovy", 2, 2)).containsOnly(TypeOfText.KEYWORD);
  assertThat(context.highlightingTypeAt(":Error.groovy", 3, 2)).isEmpty();
  Mockito.verify(context, Mockito.times(1)).newHighlighting();
}