use of org.sonar.java.SonarComponents in project sonar-java by SonarSource.
the class VisitorsBridgeTest method rethrow_exception_when_hidden_property_set_to_true.
@Test
public void rethrow_exception_when_hidden_property_set_to_true() {
NullPointerException npe = new NullPointerException("BimBadaboum");
JavaFileScanner visitor = c -> {
throw npe;
};
File currentFile = new File("");
SensorContextTester sensorContextTester = SensorContextTester.create(currentFile);
SonarComponents sonarComponents = new SonarComponents(null, null, null, null, null, null);
sonarComponents.setSensorContext(sensorContextTester);
VisitorsBridge visitorsBridge = new VisitorsBridge(Collections.singleton(visitor), new ArrayList<>(), sonarComponents);
visitorsBridge.setCurrentFile(currentFile);
try {
visitorsBridge.visitFile(null);
assertThat(sonarComponents.analysisErrors).hasSize(1);
} catch (Exception e) {
e.printStackTrace();
Fail.fail("Exception should be swallowed when property is not set");
}
sensorContextTester.settings().appendProperty(SonarComponents.FAIL_ON_EXCEPTION_KEY, "true");
try {
visitorsBridge.visitFile(null);
Fail.fail("scanning of file should have raise an exception");
} catch (Exception e) {
assertThat(e).isSameAs(npe);
}
}
use of org.sonar.java.SonarComponents in project sonar-java by SonarSource.
the class XmlAnalyzerTest method should_interrupt_analysis_when_InterruptedException_is_thrown.
@Test
public void should_interrupt_analysis_when_InterruptedException_is_thrown() {
DefaultFileSystem fs = new DefaultFileSystem(new File(""));
File pomFile = new File(VALID_POM);
fs.add(new TestInputFileBuilder("", pomFile.getAbsolutePath()).build());
XmlCheckThrowingException check = new XmlCheckThrowingException(new RuntimeException("Analysis cancelled"));
SonarComponents sonarComponents = createSonarComponentsMock(fs, check);
thrown.expectMessage("Analysis cancelled");
thrown.expect(RuntimeException.class);
XmlAnalyzer analyzer = new XmlAnalyzer(sonarComponents, check);
analyzer.scan(Lists.newArrayList(pomFile));
}
use of org.sonar.java.SonarComponents in project sonar-java by SonarSource.
the class XmlAnalyzerTest method should_not_run_xml_check_when_no_xml_file_provided.
@Test
public void should_not_run_xml_check_when_no_xml_file_provided() {
DefaultFileSystem fs = new DefaultFileSystem(new File(""));
SonarComponents sonarComponents = createSonarComponentsMock(fs, XML_CHECK, POM_CHECK);
XmlAnalyzer analyzer = new XmlAnalyzer(sonarComponents, XML_CHECK, POM_CHECK);
analyzer.scan(Lists.<File>newArrayList());
verify(sonarComponents, never()).addIssue(any(File.class), eq(POM_CHECK), any(Integer.class), anyString(), isNull());
verify(sonarComponents, never()).addIssue(any(File.class), eq(XML_CHECK), any(Integer.class), anyString(), isNull());
verify(sonarComponents, never()).reportIssue(any(AnalyzerMessage.class));
}
use of org.sonar.java.SonarComponents in project sonar-java by SonarSource.
the class XmlAnalyzerTest method should_scan_pom_file_with_xml_check.
@Test
public void should_scan_pom_file_with_xml_check() {
DefaultFileSystem fs = new DefaultFileSystem(new File(""));
File xmlFile = new File(VALID_POM);
fs.add(new TestInputFileBuilder("", xmlFile.getAbsolutePath()).build());
SonarComponents sonarComponents = createSonarComponentsMock(fs, XML_CHECK);
XmlAnalyzer analyzer = new XmlAnalyzer(sonarComponents, XML_CHECK);
analyzer.scan(Lists.newArrayList(xmlFile));
verify(sonarComponents, times(1)).addIssue(any(File.class), any(JavaCheck.class), any(Integer.class), anyString(), isNull());
verify(sonarComponents, never()).reportIssue(any(AnalyzerMessage.class));
}
use of org.sonar.java.SonarComponents in project sonar-java by SonarSource.
the class XmlAnalyzerTest method should_scan_pom_file_with_pom_check.
@Test
public void should_scan_pom_file_with_pom_check() {
DefaultFileSystem fs = new DefaultFileSystem(new File(""));
File xmlFile = new File(VALID_POM);
fs.add(new TestInputFileBuilder("", xmlFile.getAbsolutePath()).build());
SonarComponents sonarComponents = createSonarComponentsMock(fs, POM_CHECK);
XmlAnalyzer analyzer = new XmlAnalyzer(sonarComponents, POM_CHECK);
analyzer.scan(Lists.newArrayList(xmlFile));
verify(sonarComponents, times(1)).addIssue(any(File.class), any(JavaCheck.class), any(Integer.class), anyString(), isNull());
verify(sonarComponents, never()).reportIssue(any(AnalyzerMessage.class));
}
Aggregations