Search in sources :

Example 86 with DefaultFileSystem

use of org.sonar.api.batch.fs.internal.DefaultFileSystem 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 87 with DefaultFileSystem

use of org.sonar.api.batch.fs.internal.DefaultFileSystem 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 88 with DefaultFileSystem

use of org.sonar.api.batch.fs.internal.DefaultFileSystem 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 89 with DefaultFileSystem

use of org.sonar.api.batch.fs.internal.DefaultFileSystem 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)

Example 90 with DefaultFileSystem

use of org.sonar.api.batch.fs.internal.DefaultFileSystem in project sonar-java by SonarSource.

the class XmlAnalyzerTest method should_not_run_pom_check_when_no_pom_file_provided.

@Test
public void should_not_run_pom_check_when_no_pom_file_provided() {
    DefaultFileSystem fs = new DefaultFileSystem(new File(""));
    File xmlFile = new File("src/test/files/xml/parsing.xml");
    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), eq(POM_CHECK), any(Integer.class), anyString(), isNull());
    verify(sonarComponents, times(1)).addIssue(any(File.class), eq(XML_CHECK), 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) AnalyzerMessage(org.sonar.java.AnalyzerMessage) File(java.io.File) DefaultFileSystem(org.sonar.api.batch.fs.internal.DefaultFileSystem) Test(org.junit.Test)

Aggregations

DefaultFileSystem (org.sonar.api.batch.fs.internal.DefaultFileSystem)126 File (java.io.File)79 InputFile (org.sonar.api.batch.fs.InputFile)70 TestInputFileBuilder (org.sonar.api.batch.fs.internal.TestInputFileBuilder)55 Test (org.junit.Test)54 DefaultInputFile (org.sonar.api.batch.fs.internal.DefaultInputFile)52 SensorContextTester (org.sonar.api.batch.sensor.internal.SensorContextTester)39 Test (org.junit.jupiter.api.Test)27 SonarComponents (org.sonar.java.SonarComponents)25 Before (org.junit.Before)23 MapSettings (org.sonar.api.config.internal.MapSettings)22 PathResolver (org.sonar.api.scan.filesystem.PathResolver)20 JavaCheck (org.sonar.plugins.java.api.JavaCheck)14 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)13 AnalyzerMessage (org.sonar.java.AnalyzerMessage)11 Path (java.nio.file.Path)10 ClasspathForTest (org.sonar.java.classpath.ClasspathForTest)10 ActiveRulesBuilder (org.sonar.api.batch.rule.internal.ActiveRulesBuilder)8 NoSonarFilter (org.sonar.api.issue.NoSonarFilter)8 FileLinesContext (org.sonar.api.measures.FileLinesContext)7