XmlFileSensor implements Sensor { private void scanFile(SensorContext context, InputFile inputFile) { XmlFile xmlFile; try { xmlFile = XmlFile.create(inputFile); } catch (ParseException | IOException e) { LOG.debug("Skipped '{}' due to parsing error", inputFile); return; } catch (Exception e) { LOG.warn(String.format("Unable to analyse file '%s'.", inputFile), e); return; } checks.all().forEach(check -> { RuleKey ruleKey = checks.ruleKey(check); scanFile(context, xmlFile, check, ruleKey); }); } XmlFileSensor(CheckFactory checkFactory); @Override void describe(SensorDescriptor descriptor); @Override void execute(SensorContext context);  }
@Test void testCheckFailure() throws Exception { XmlFileSensor sensor = new XmlFileSensor(new CheckFactory(new ActiveRulesBuilder().build())); InputFile inputFile = addFileWithIssue("xml"); XmlFile xmlFile = XmlFile.create(inputFile); sensor.scanFile(context, xmlFile, new TestCheck(), XML_RULE_KEY); assertThat(logTester.logs(LoggerLevel.ERROR)).hasSize(1); assertThat(logTester.logs(LoggerLevel.ERROR).get(0)).isEqualTo("Failed to analyze 'test.xml' with rule java:S3281"); }