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");
}
}
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);
}
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);
}
Aggregations