Search in sources :

Example 1 with MetricFinder

use of org.sonar.api.batch.measure.MetricFinder in project sonarqube by SonarSource.

the class DefaultSensorContextTest method prepare.

@Before
public void prepare() throws Exception {
    activeRules = new ActiveRulesBuilder().build();
    fs = new DefaultFileSystem(temp.newFolder().toPath());
    MetricFinder metricFinder = mock(MetricFinder.class);
    when(metricFinder.<Integer>findByKey(CoreMetrics.NCLOC_KEY)).thenReturn(CoreMetrics.NCLOC);
    when(metricFinder.<String>findByKey(CoreMetrics.FUNCTION_COMPLEXITY_DISTRIBUTION_KEY)).thenReturn(CoreMetrics.FUNCTION_COMPLEXITY_DISTRIBUTION);
    settings = new MapSettings();
    sensorStorage = mock(SensorStorage.class);
    analysisMode = mock(AnalysisMode.class);
    runtime = SonarRuntimeImpl.forSonarQube(Version.parse("5.5"), SonarQubeSide.SCANNER);
    adaptor = new DefaultSensorContext(mock(InputModule.class), settings, fs, activeRules, analysisMode, sensorStorage, runtime);
}
Also used : ActiveRulesBuilder(org.sonar.api.batch.rule.internal.ActiveRulesBuilder) MapSettings(org.sonar.api.config.MapSettings) MetricFinder(org.sonar.api.batch.measure.MetricFinder) AnalysisMode(org.sonar.api.batch.AnalysisMode) DefaultFileSystem(org.sonar.api.batch.fs.internal.DefaultFileSystem) SensorStorage(org.sonar.api.batch.sensor.internal.SensorStorage) Before(org.junit.Before)

Example 2 with MetricFinder

use of org.sonar.api.batch.measure.MetricFinder in project sonarqube by SonarSource.

the class DefaultSensorStorageTest method prepare.

@Before
public void prepare() throws Exception {
    MetricFinder metricFinder = mock(MetricFinder.class);
    when(metricFinder.<Integer>findByKey(CoreMetrics.NCLOC_KEY)).thenReturn(CoreMetrics.NCLOC);
    when(metricFinder.<String>findByKey(CoreMetrics.FUNCTION_COMPLEXITY_DISTRIBUTION_KEY)).thenReturn(CoreMetrics.FUNCTION_COMPLEXITY_DISTRIBUTION);
    when(metricFinder.<Integer>findByKey(CoreMetrics.LINES_TO_COVER_KEY)).thenReturn(CoreMetrics.LINES_TO_COVER);
    settings = new MapSettings();
    moduleIssues = mock(IssuePublisher.class);
    reportPublisher = mock(ReportPublisher.class);
    final File reportDir = temp.newFolder();
    reportWriter = new ScannerReportWriter(reportDir);
    reportReader = new ScannerReportReader(reportDir);
    when(reportPublisher.getWriter()).thenReturn(reportWriter);
    when(reportPublisher.getReader()).thenReturn(reportReader);
    branchConfiguration = mock(BranchConfiguration.class);
    underTest = new DefaultSensorStorage(metricFinder, moduleIssues, settings.asConfig(), reportPublisher, mock(SonarCpdBlockIndex.class), contextPropertiesCache, new ScannerMetrics(), branchConfiguration);
    project = new DefaultInputProject(ProjectDefinition.create().setKey("foo").setBaseDir(temp.newFolder()).setWorkDir(temp.newFolder()));
}
Also used : BranchConfiguration(org.sonar.scanner.scan.branch.BranchConfiguration) MetricFinder(org.sonar.api.batch.measure.MetricFinder) ScannerMetrics(org.sonar.core.metric.ScannerMetrics) ScannerReportWriter(org.sonar.scanner.protocol.output.ScannerReportWriter) ReportPublisher(org.sonar.scanner.report.ReportPublisher) ScannerReportReader(org.sonar.scanner.protocol.output.ScannerReportReader) DefaultInputProject(org.sonar.api.batch.fs.internal.DefaultInputProject) MapSettings(org.sonar.api.config.internal.MapSettings) IssuePublisher(org.sonar.scanner.issue.IssuePublisher) InputFile(org.sonar.api.batch.fs.InputFile) DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile) File(java.io.File) Before(org.junit.Before)

Example 3 with MetricFinder

use of org.sonar.api.batch.measure.MetricFinder in project sonarqube by SonarSource.

the class ModuleSensorContextTest method prepare.

@Before
public void prepare() throws Exception {
    activeRules = new ActiveRulesBuilder().build();
    fs = new DefaultFileSystem(temp.newFolder().toPath());
    MetricFinder metricFinder = mock(MetricFinder.class);
    when(metricFinder.<Integer>findByKey(CoreMetrics.NCLOC_KEY)).thenReturn(CoreMetrics.NCLOC);
    when(metricFinder.<String>findByKey(CoreMetrics.FUNCTION_COMPLEXITY_DISTRIBUTION_KEY)).thenReturn(CoreMetrics.FUNCTION_COMPLEXITY_DISTRIBUTION);
    settings = new MapSettings();
    sensorStorage = mock(SensorStorage.class);
    branchConfiguration = mock(BranchConfiguration.class);
    runtime = SonarRuntimeImpl.forSonarQube(Version.parse("5.5"), SonarQubeSide.SCANNER, SonarEdition.COMMUNITY);
}
Also used : ActiveRulesBuilder(org.sonar.api.batch.rule.internal.ActiveRulesBuilder) BranchConfiguration(org.sonar.scanner.scan.branch.BranchConfiguration) MapSettings(org.sonar.api.config.internal.MapSettings) MetricFinder(org.sonar.api.batch.measure.MetricFinder) DefaultFileSystem(org.sonar.api.batch.fs.internal.DefaultFileSystem) SensorStorage(org.sonar.api.batch.sensor.internal.SensorStorage) Before(org.junit.Before)

Example 4 with MetricFinder

use of org.sonar.api.batch.measure.MetricFinder in project sonarqube by SonarSource.

the class DefaultFileLinesContextTest method setUp.

@Before
public void setUp() {
    MetricFinder metricFinder = mock(MetricFinder.class);
    org.sonar.api.batch.measure.Metric<String> hitsMetric = mock(org.sonar.api.batch.measure.Metric.class);
    when(hitsMetric.valueType()).thenReturn(String.class);
    when(hitsMetric.key()).thenReturn(HITS_METRIC_KEY);
    when(metricFinder.<String>findByKey(HITS_METRIC_KEY)).thenReturn(hitsMetric);
    org.sonar.api.batch.measure.Metric<String> authorMetric = mock(org.sonar.api.batch.measure.Metric.class);
    when(authorMetric.valueType()).thenReturn(String.class);
    when(authorMetric.key()).thenReturn(AUTHOR_METRIC_KEY);
    when(metricFinder.<String>findByKey(AUTHOR_METRIC_KEY)).thenReturn(authorMetric);
    org.sonar.api.batch.measure.Metric<String> branchesMetric = mock(org.sonar.api.batch.measure.Metric.class);
    when(branchesMetric.valueType()).thenReturn(String.class);
    when(branchesMetric.key()).thenReturn(BRANCHES_METRIC_KEY);
    when(metricFinder.<String>findByKey(BRANCHES_METRIC_KEY)).thenReturn(branchesMetric);
    when(metricFinder.<String>findByKey(CoreMetrics.NCLOC_DATA_KEY)).thenReturn(CoreMetrics.NCLOC_DATA);
    when(metricFinder.<String>findByKey(CoreMetrics.EXECUTABLE_LINES_DATA_KEY)).thenReturn(CoreMetrics.EXECUTABLE_LINES_DATA);
    sensorStorage = mock(SensorStorage.class);
    file = new TestInputFileBuilder("foo", "src/foo.php").initMetadata("Foo\nbar\nbiz").build();
    fileLineMeasures = new DefaultFileLinesContext(sensorStorage, file, metricFinder);
}
Also used : TestInputFileBuilder(org.sonar.api.batch.fs.internal.TestInputFileBuilder) MetricFinder(org.sonar.api.batch.measure.MetricFinder) SensorStorage(org.sonar.api.batch.sensor.internal.SensorStorage) Before(org.junit.Before)

Aggregations

Before (org.junit.Before)4 MetricFinder (org.sonar.api.batch.measure.MetricFinder)4 SensorStorage (org.sonar.api.batch.sensor.internal.SensorStorage)3 DefaultFileSystem (org.sonar.api.batch.fs.internal.DefaultFileSystem)2 ActiveRulesBuilder (org.sonar.api.batch.rule.internal.ActiveRulesBuilder)2 MapSettings (org.sonar.api.config.internal.MapSettings)2 BranchConfiguration (org.sonar.scanner.scan.branch.BranchConfiguration)2 File (java.io.File)1 AnalysisMode (org.sonar.api.batch.AnalysisMode)1 InputFile (org.sonar.api.batch.fs.InputFile)1 DefaultInputFile (org.sonar.api.batch.fs.internal.DefaultInputFile)1 DefaultInputProject (org.sonar.api.batch.fs.internal.DefaultInputProject)1 TestInputFileBuilder (org.sonar.api.batch.fs.internal.TestInputFileBuilder)1 MapSettings (org.sonar.api.config.MapSettings)1 ScannerMetrics (org.sonar.core.metric.ScannerMetrics)1 IssuePublisher (org.sonar.scanner.issue.IssuePublisher)1 ScannerReportReader (org.sonar.scanner.protocol.output.ScannerReportReader)1 ScannerReportWriter (org.sonar.scanner.protocol.output.ScannerReportWriter)1 ReportPublisher (org.sonar.scanner.report.ReportPublisher)1