Search in sources :

Example 16 with DefaultFileSystem

use of org.sonar.api.batch.fs.internal.DefaultFileSystem 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));
}
Also used : 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)

Example 17 with DefaultFileSystem

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

use of org.sonar.api.batch.fs.internal.DefaultFileSystem 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));
}
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 19 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__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));
}
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 20 with DefaultFileSystem

use of org.sonar.api.batch.fs.internal.DefaultFileSystem 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));
}
Also used : 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)113 File (java.io.File)70 InputFile (org.sonar.api.batch.fs.InputFile)58 Test (org.junit.Test)46 TestInputFileBuilder (org.sonar.api.batch.fs.internal.TestInputFileBuilder)46 DefaultInputFile (org.sonar.api.batch.fs.internal.DefaultInputFile)38 SensorContextTester (org.sonar.api.batch.sensor.internal.SensorContextTester)37 Test (org.junit.jupiter.api.Test)26 SonarComponents (org.sonar.java.SonarComponents)24 Before (org.junit.Before)22 MapSettings (org.sonar.api.config.internal.MapSettings)21 PathResolver (org.sonar.api.scan.filesystem.PathResolver)20 JavaCheck (org.sonar.plugins.java.api.JavaCheck)14 AnalyzerMessage (org.sonar.java.AnalyzerMessage)11 ClasspathForTest (org.sonar.java.classpath.ClasspathForTest)10 NoSonarFilter (org.sonar.api.issue.NoSonarFilter)8 Path (java.nio.file.Path)7 ClasspathForMain (org.sonar.java.classpath.ClasspathForMain)7 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)6 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)6