Search in sources :

Example 1 with DefaultJavaResourceLocator

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

the class JavaSquidSensorTest method testIssueCreation.

private void testIssueCreation(InputFile.Type onType, int expectedIssues) throws IOException {
    MapSettings settings = new MapSettings();
    NoSonarFilter noSonarFilter = mock(NoSonarFilter.class);
    SensorContextTester context = createContext(onType).setRuntime(SonarRuntimeImpl.forSonarLint(Version.create(6, 7)));
    DefaultFileSystem fs = context.fileSystem();
    SonarComponents sonarComponents = createSonarComponentsMock(context);
    DefaultJavaResourceLocator javaResourceLocator = new DefaultJavaResourceLocator(fs, new JavaClasspath(settings.asConfig(), fs));
    PostAnalysisIssueFilter postAnalysisIssueFilter = new PostAnalysisIssueFilter(fs);
    JavaSquidSensor jss = new JavaSquidSensor(sonarComponents, fs, javaResourceLocator, settings.asConfig(), noSonarFilter, postAnalysisIssueFilter);
    jss.execute(context);
    verify(noSonarFilter, times(1)).noSonarInFile(fs.inputFiles().iterator().next(), Sets.newHashSet(96));
    verify(sonarComponents, times(expectedIssues)).reportIssue(any(AnalyzerMessage.class));
    settings.setProperty(Java.SOURCE_VERSION, "wrongFormat");
    jss.execute(context);
    settings.setProperty(Java.SOURCE_VERSION, "1.7");
    jss.execute(context);
}
Also used : SonarComponents(org.sonar.java.SonarComponents) JavaClasspath(org.sonar.java.JavaClasspath) MapSettings(org.sonar.api.config.internal.MapSettings) NoSonarFilter(org.sonar.api.issue.NoSonarFilter) SensorContextTester(org.sonar.api.batch.sensor.internal.SensorContextTester) PostAnalysisIssueFilter(org.sonar.java.filters.PostAnalysisIssueFilter) DefaultJavaResourceLocator(org.sonar.java.DefaultJavaResourceLocator) AnalyzerMessage(org.sonar.java.AnalyzerMessage) DefaultFileSystem(org.sonar.api.batch.fs.internal.DefaultFileSystem)

Example 2 with DefaultJavaResourceLocator

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

the class JavaSquidSensorTest method executeJavaSquidSensor.

private void executeJavaSquidSensor(SensorContextTester context) {
    context.setRuntime(SonarRuntimeImpl.forSonarQube(Version.create(6, 7), SonarQubeSide.SCANNER));
    // Mock visitor for metrics.
    FileLinesContext fileLinesContext = mock(FileLinesContext.class);
    FileLinesContextFactory fileLinesContextFactory = mock(FileLinesContextFactory.class);
    when(fileLinesContextFactory.createFor(any(InputFile.class))).thenReturn(fileLinesContext);
    DefaultFileSystem fs = context.fileSystem().setWorkDir(tmp.getRoot().toPath());
    JavaClasspath javaClasspath = mock(JavaClasspath.class);
    JavaTestClasspath javaTestClasspath = mock(JavaTestClasspath.class);
    SonarComponents sonarComponents = new SonarComponents(fileLinesContextFactory, fs, javaClasspath, javaTestClasspath, checkFactory);
    DefaultJavaResourceLocator javaResourceLocator = mock(DefaultJavaResourceLocator.class);
    NoSonarFilter noSonarFilter = mock(NoSonarFilter.class);
    PostAnalysisIssueFilter postAnalysisIssueFilter = new PostAnalysisIssueFilter(fs);
    JavaSquidSensor jss = new JavaSquidSensor(sonarComponents, fs, javaResourceLocator, new MapSettings().asConfig(), noSonarFilter, postAnalysisIssueFilter);
    jss.execute(context);
}
Also used : SonarComponents(org.sonar.java.SonarComponents) JavaClasspath(org.sonar.java.JavaClasspath) NoSonarFilter(org.sonar.api.issue.NoSonarFilter) MapSettings(org.sonar.api.config.internal.MapSettings) FileLinesContextFactory(org.sonar.api.measures.FileLinesContextFactory) PostAnalysisIssueFilter(org.sonar.java.filters.PostAnalysisIssueFilter) JavaTestClasspath(org.sonar.java.JavaTestClasspath) DefaultJavaResourceLocator(org.sonar.java.DefaultJavaResourceLocator) DefaultFileSystem(org.sonar.api.batch.fs.internal.DefaultFileSystem) FileLinesContext(org.sonar.api.measures.FileLinesContext) InputFile(org.sonar.api.batch.fs.InputFile) DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile)

Aggregations

DefaultFileSystem (org.sonar.api.batch.fs.internal.DefaultFileSystem)2 MapSettings (org.sonar.api.config.internal.MapSettings)2 NoSonarFilter (org.sonar.api.issue.NoSonarFilter)2 DefaultJavaResourceLocator (org.sonar.java.DefaultJavaResourceLocator)2 JavaClasspath (org.sonar.java.JavaClasspath)2 SonarComponents (org.sonar.java.SonarComponents)2 PostAnalysisIssueFilter (org.sonar.java.filters.PostAnalysisIssueFilter)2 InputFile (org.sonar.api.batch.fs.InputFile)1 DefaultInputFile (org.sonar.api.batch.fs.internal.DefaultInputFile)1 SensorContextTester (org.sonar.api.batch.sensor.internal.SensorContextTester)1 FileLinesContext (org.sonar.api.measures.FileLinesContext)1 FileLinesContextFactory (org.sonar.api.measures.FileLinesContextFactory)1 AnalyzerMessage (org.sonar.java.AnalyzerMessage)1 JavaTestClasspath (org.sonar.java.JavaTestClasspath)1