Search in sources :

Example 26 with SonarComponents

use of org.sonar.java.SonarComponents in project sonar-java by SonarSource.

the class XmlAnalyzerTest method createSonarComponentsMock.

private static SonarComponents createSonarComponentsMock(DefaultFileSystem fs, JavaCheck... visitors) {
    SonarComponents sonarComponents = mock(SonarComponents.class);
    when(sonarComponents.checkClasses()).thenReturn(visitors);
    when(sonarComponents.getFileSystem()).thenReturn(fs);
    Checks<JavaCheck> checks = mock(Checks.class);
    when(checks.ruleKey(any(JavaCheck.class))).thenReturn(mock(RuleKey.class));
    when(sonarComponents.checks()).thenReturn(Lists.newArrayList(checks));
    return sonarComponents;
}
Also used : SonarComponents(org.sonar.java.SonarComponents) RuleKey(org.sonar.api.rule.RuleKey) JavaCheck(org.sonar.plugins.java.api.JavaCheck)

Example 27 with SonarComponents

use of org.sonar.java.SonarComponents in project sonar-java by SonarSource.

the class XmlAnalyzerTest method should_not_scan_file_with_parsing_issue.

@Test
public void should_not_scan_file_with_parsing_issue() {
    DefaultFileSystem fs = new DefaultFileSystem(new File(""));
    File xmlFile = new File(PARSE_ISSUE_POM);
    fs.add(new TestInputFileBuilder("", xmlFile.getAbsolutePath()).setLanguage("xml").build());
    SonarComponents sonarComponents = createSonarComponentsMock(fs, XML_CHECK, POM_CHECK);
    XmlAnalyzer analyzer = new XmlAnalyzer(sonarComponents, XML_CHECK, POM_CHECK);
    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));
}
Also used : TestInputFileBuilder(org.sonar.api.batch.fs.internal.TestInputFileBuilder) SonarComponents(org.sonar.java.SonarComponents) JavaCheck(org.sonar.plugins.java.api.JavaCheck) AnalyzerMessage(org.sonar.java.AnalyzerMessage) File(java.io.File) DefaultFileSystem(org.sonar.api.batch.fs.internal.DefaultFileSystem) Test(org.junit.Test)

Example 28 with SonarComponents

use of org.sonar.java.SonarComponents in project sonar-java by SonarSource.

the class XmlAnalyzerTest method should_not_scan_invalid_pom_file.

@Test
public void should_not_scan_invalid_pom_file() {
    DefaultFileSystem fs = new DefaultFileSystem(new File(""));
    File xmlFile = new File(INVALID_POM);
    fs.add(new TestInputFileBuilder("", xmlFile.getAbsolutePath()).setLanguage("xml").build());
    SonarComponents sonarComponents = createSonarComponentsMock(fs, POM_CHECK);
    XmlAnalyzer analyzer = new XmlAnalyzer(sonarComponents, POM_CHECK);
    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));
}
Also used : TestInputFileBuilder(org.sonar.api.batch.fs.internal.TestInputFileBuilder) SonarComponents(org.sonar.java.SonarComponents) JavaCheck(org.sonar.plugins.java.api.JavaCheck) AnalyzerMessage(org.sonar.java.AnalyzerMessage) File(java.io.File) DefaultFileSystem(org.sonar.api.batch.fs.internal.DefaultFileSystem) Test(org.junit.Test)

Example 29 with SonarComponents

use of org.sonar.java.SonarComponents in project sonar-java by SonarSource.

the class XmlAnalyzerTest method should_not_scan_when_no_xml_check_provided.

@Test
public void should_not_scan_when_no_xml_check_provided() {
    DefaultFileSystem fs = new DefaultFileSystem(new File(""));
    File pomFile = new File(VALID_POM);
    fs.add(new TestInputFileBuilder("", pomFile.getAbsolutePath()).setLanguage("xml").build());
    SonarComponents sonarComponents = createSonarComponentsMock(fs, JAVA_CHECK);
    XmlAnalyzer analyzer = new XmlAnalyzer(sonarComponents, JAVA_CHECK);
    analyzer.scan(Lists.newArrayList(pomFile));
    verify(sonarComponents, never()).addIssue(any(File.class), any(JavaCheck.class), any(Integer.class), anyString(), isNull());
    verify(sonarComponents, never()).reportIssue(any(AnalyzerMessage.class));
}
Also used : TestInputFileBuilder(org.sonar.api.batch.fs.internal.TestInputFileBuilder) SonarComponents(org.sonar.java.SonarComponents) JavaCheck(org.sonar.plugins.java.api.JavaCheck) AnalyzerMessage(org.sonar.java.AnalyzerMessage) File(java.io.File) DefaultFileSystem(org.sonar.api.batch.fs.internal.DefaultFileSystem) Test(org.junit.Test)

Example 30 with SonarComponents

use of org.sonar.java.SonarComponents in project sonar-java by SonarSource.

the class XmlAnalyzerTest method should_scan_xml_file_provided.

@Test
public void should_scan_xml_file_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, XML_CHECK, POM_CHECK);
    analyzer.scan(Lists.newArrayList(xmlFile));
    verify(sonarComponents, times(2)).addIssue(any(File.class), any(JavaCheck.class), any(Integer.class), anyString(), isNull());
    verify(sonarComponents, never()).reportIssue(any(AnalyzerMessage.class));
}
Also used : TestInputFileBuilder(org.sonar.api.batch.fs.internal.TestInputFileBuilder) SonarComponents(org.sonar.java.SonarComponents) JavaCheck(org.sonar.plugins.java.api.JavaCheck) AnalyzerMessage(org.sonar.java.AnalyzerMessage) File(java.io.File) DefaultFileSystem(org.sonar.api.batch.fs.internal.DefaultFileSystem) Test(org.junit.Test)

Aggregations

SonarComponents (org.sonar.java.SonarComponents)36 File (java.io.File)27 Test (org.junit.Test)21 DefaultFileSystem (org.sonar.api.batch.fs.internal.DefaultFileSystem)17 AnalyzerMessage (org.sonar.java.AnalyzerMessage)14 TestInputFileBuilder (org.sonar.api.batch.fs.internal.TestInputFileBuilder)13 JavaCheck (org.sonar.plugins.java.api.JavaCheck)11 DefaultInputFile (org.sonar.api.batch.fs.internal.DefaultInputFile)10 SensorContextTester (org.sonar.api.batch.sensor.internal.SensorContextTester)7 Before (org.junit.Before)6 Lists (com.google.common.collect.Lists)3 RecognitionException (com.sonar.sslr.api.RecognitionException)3 ArrayList (java.util.ArrayList)3 Nullable (javax.annotation.Nullable)3 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)3 MapSettings (org.sonar.api.config.internal.MapSettings)3 VisitorsBridge (org.sonar.java.model.VisitorsBridge)3 Files (com.google.common.io.Files)2 IOException (java.io.IOException)2 StandardCharsets (java.nio.charset.StandardCharsets)2