@Test
public void should_parse_report() {

  FilePredicates fp = mock(FilePredicates.class);
  class CustomFilePredicate implements FilePredicate {
    final String fileName;
    CustomFilePredicate(String fileName) {
      this.fileName = fileName;
    }
    @Override
    public boolean apply(InputFile inputFile) {
      return true;
    }
  }
  when(fp.hasAbsolutePath(ArgumentMatchers.anyString())).thenAnswer(new Answer<FilePredicate>() {
    @Override
    public FilePredicate answer(InvocationOnMock invocation) throws Throwable {
      return new CustomFilePredicate(invocation.<String>getArgument(0));
    }
  });
  FileSystem mockfileSystem = mock(FileSystem.class);
  when(mockfileSystem.predicates()).thenReturn(fp);
  when(mockfileSystem.hasFiles(ArgumentMatchers.nullable(FilePredicate.class))).thenReturn(true);
  Map<String, DefaultInputFile> groovyFilesByName = new HashMap<>();
  when(mockfileSystem.inputFile(any(FilePredicate.class))).thenAnswer(new Answer<InputFile>() {
    boolean firstCall = true;
    @Override
    public InputFile answer(InvocationOnMock invocation) throws Throwable {
      if (firstCall) {
        // The first class in the test coverage.xml is a java class and the rest are groovy
        firstCall = false;
        return new DefaultInputFile("", "fake.java").setLanguage("java");
      }
      String fileName = invocation.<CustomFilePredicate>getArgument(0).fileName;
      DefaultInputFile groovyFile;
      if (!groovyFilesByName.containsKey(fileName)) {
        // store groovy file as default input files
        groovyFile = new DefaultInputFile("", fileName).setLanguage(Groovy.KEY).setType(Type.MAIN).setLines(Integer.MAX_VALUE);
        groovyFilesByName.put(fileName, groovyFile);
      }
      return groovyFilesByName.get(fileName);
    }
  });
  sensor = new CoberturaSensor(settings, mockfileSystem);
  SensorContextTester context = SensorContextTester.create(new File(""));
  sensor.execute(context);
  // random pick groovy file
  String filekey = ":/Users/cpicat/myproject/grails-app/domain/AboveEighteenFilters.groovy";
  int[] lineHits = {2, 6, 7};
  int[] lineNoHits = {9, 10, 11};
  for (int line : lineHits) {
    assertThat(context.lineHits(filekey, CoverageType.UNIT, line)).isEqualTo(1);
  }
  for (int line : lineNoHits) {
    assertThat(context.lineHits(filekey, CoverageType.UNIT, line)).isEqualTo(0);
  }
  // No value for java file
  assertThat(context.lineHits(":/Users/cpicat/myproject/grails-app/domain/com/test/web/EmptyResultException.java", CoverageType.UNIT, 16)).isNull();
}