use of org.sonar.java.SonarComponents in project sonar-java by SonarSource.
the class XmlAnalyzerTest method should_scan_xml_file__when_no_check_provided.
@Test
public void should_scan_xml_file__when_no_check_provided() {
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, POM_CHECK);
XmlAnalyzer analyzer = new XmlAnalyzer(sonarComponents);
analyzer.scan(Lists.newArrayList(xmlFile));
verify(sonarComponents, never()).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_not_run_xml_check_when_no_check_provided.
@Test
public void should_not_run_xml_check_when_no_check_provided() {
DefaultFileSystem fs = new DefaultFileSystem(new File(""));
SonarComponents sonarComponents = createSonarComponentsMock(fs, JAVA_CHECK);
XmlAnalyzer analyzer = new XmlAnalyzer(sonarComponents);
analyzer.scan(Lists.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 PomCheckContextImplTest method setup.
@Before
public void setup() {
reportedMessage = null;
SonarComponents sonarComponents = createSonarComponentsMock();
XPath xPath = XPathFactory.newInstance().newXPath();
context = new PomCheckContextImpl(mock(MavenProject.class), mock(Document.class), mock(File.class), xPath, sonarComponents);
}
use of org.sonar.java.SonarComponents in project sonar-java by SonarSource.
the class ParsingErrorCheckTest method test.
@Test
public void test() {
SonarComponents sonarComponents = mock(SonarComponents.class);
when(sonarComponents.fileContent(any())).thenCallRealMethod();
when(sonarComponents.fileLength(any())).thenCallRealMethod();
VisitorsBridgeForTests visitorsBridge = new VisitorsBridgeForTests(new ParsingErrorCheck(), sonarComponents);
JavaAstScanner.scanSingleFileForTests(new File("src/test/files/checks/ParsingError.java"), visitorsBridge);
Set<AnalyzerMessage> issues = visitorsBridge.lastCreatedTestContext().getIssues();
assertThat(issues).hasSize(1);
AnalyzerMessage issue = issues.iterator().next();
assertThat(issue.getLine()).isEqualTo(1);
assertThat(issue.getMessage()).isEqualTo("Parse error");
}
use of org.sonar.java.SonarComponents in project sonar-java by SonarSource.
the class DefaultJavaFileScannerContextTest method createSonarComponentsMock.
private static SonarComponents createSonarComponentsMock() {
SonarComponents sonarComponents = mock(SonarComponents.class);
doAnswer(invocation -> {
reportedMessage = (AnalyzerMessage) invocation.getArguments()[0];
return null;
}).when(sonarComponents).reportIssue(any(AnalyzerMessage.class));
return sonarComponents;
}
Aggregations