Search in sources :

Example 11 with SensorStorage

use of org.sonar.api.batch.sensor.internal.SensorStorage in project sonarqube by SonarSource.

the class DefaultCpdTokensTest method basic_validation.

@Test
public void basic_validation() {
    SensorStorage sensorStorage = mock(SensorStorage.class);
    DefaultCpdTokens tokens = new DefaultCpdTokens(new MapSettings(), sensorStorage);
    try {
        tokens.save();
        fail("Expected exception");
    } catch (Exception e) {
        assertThat(e).hasMessage("Call onFile() first");
    }
    try {
        tokens.addToken(INPUT_FILE.newRange(1, 2, 1, 5), "foo");
        fail("Expected exception");
    } catch (Exception e) {
        assertThat(e).hasMessage("Call onFile() first");
    }
    try {
        tokens.addToken(null, "foo");
        fail("Expected exception");
    } catch (Exception e) {
        assertThat(e).hasMessage("Range should not be null");
    }
    try {
        tokens.addToken(INPUT_FILE.newRange(1, 2, 1, 5), null);
        fail("Expected exception");
    } catch (Exception e) {
        assertThat(e).hasMessage("Image should not be null");
    }
}
Also used : MapSettings(org.sonar.api.config.MapSettings) SensorStorage(org.sonar.api.batch.sensor.internal.SensorStorage) Test(org.junit.Test)

Example 12 with SensorStorage

use of org.sonar.api.batch.sensor.internal.SensorStorage in project sonarqube by SonarSource.

the class DefaultMeasureTest method build_file_measure.

@Test
public void build_file_measure() {
    SensorStorage storage = mock(SensorStorage.class);
    DefaultMeasure<Integer> newMeasure = new DefaultMeasure<Integer>(storage).forMetric(CoreMetrics.LINES).on(new TestInputFileBuilder("foo", "src/Foo.php").build()).withValue(3);
    assertThat(newMeasure.inputComponent()).isEqualTo(new TestInputFileBuilder("foo", "src/Foo.php").build());
    assertThat(newMeasure.metric()).isEqualTo(CoreMetrics.LINES);
    assertThat(newMeasure.value()).isEqualTo(3);
    newMeasure.save();
    verify(storage).store(newMeasure);
}
Also used : TestInputFileBuilder(org.sonar.api.batch.fs.internal.TestInputFileBuilder) SensorStorage(org.sonar.api.batch.sensor.internal.SensorStorage) Test(org.junit.Test)

Example 13 with SensorStorage

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

Aggregations

SensorStorage (org.sonar.api.batch.sensor.internal.SensorStorage)13 Test (org.junit.Test)12 MapSettings (org.sonar.api.config.MapSettings)7 AnalysisMode (org.sonar.api.batch.AnalysisMode)2 DefaultInputModule (org.sonar.api.batch.fs.internal.DefaultInputModule)2 TestInputFileBuilder (org.sonar.api.batch.fs.internal.TestInputFileBuilder)2 Before (org.junit.Before)1 DefaultFileSystem (org.sonar.api.batch.fs.internal.DefaultFileSystem)1 DefaultInputDir (org.sonar.api.batch.fs.internal.DefaultInputDir)1 DefaultInputFile (org.sonar.api.batch.fs.internal.DefaultInputFile)1 MetricFinder (org.sonar.api.batch.measure.MetricFinder)1 ActiveRulesBuilder (org.sonar.api.batch.rule.internal.ActiveRulesBuilder)1 DefaultHighlighting (org.sonar.api.batch.sensor.highlighting.internal.DefaultHighlighting)1 Settings (org.sonar.api.config.Settings)1 DefaultHighlightable (org.sonar.scanner.source.DefaultHighlightable)1