Search in sources :

Example 1 with JavaTestClasspath

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

the class JavaSquidSensorTest method createSonarComponentsMock.

private static SonarComponents createSonarComponentsMock(SensorContextTester contextTester) {
    Configuration settings = new MapSettings().asConfig();
    DefaultFileSystem fs = contextTester.fileSystem();
    JavaTestClasspath javaTestClasspath = new JavaTestClasspath(settings, fs);
    JavaClasspath javaClasspath = new JavaClasspath(settings, fs);
    FileLinesContext fileLinesContext = mock(FileLinesContext.class);
    FileLinesContextFactory fileLinesContextFactory = mock(FileLinesContextFactory.class);
    when(fileLinesContextFactory.createFor(any(InputFile.class))).thenReturn(fileLinesContext);
    SonarComponents sonarComponents = spy(new SonarComponents(fileLinesContextFactory, fs, javaClasspath, javaTestClasspath, checkFactory));
    sonarComponents.setSensorContext(contextTester);
    BadMethodNameCheck check = new BadMethodNameCheck();
    when(sonarComponents.checkClasses()).thenReturn(new JavaCheck[] { check });
    return sonarComponents;
}
Also used : SonarComponents(org.sonar.java.SonarComponents) JavaClasspath(org.sonar.java.JavaClasspath) BadMethodNameCheck(org.sonar.java.checks.naming.BadMethodNameCheck) Configuration(org.sonar.api.config.Configuration) MapSettings(org.sonar.api.config.internal.MapSettings) FileLinesContextFactory(org.sonar.api.measures.FileLinesContextFactory) JavaTestClasspath(org.sonar.java.JavaTestClasspath) 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)

Example 2 with JavaTestClasspath

use of org.sonar.java.JavaTestClasspath 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

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