use of org.sonar.api.batch.sensor.internal.SensorStorage in project sonarqube by SonarSource.
the class DefaultCpdTokensTest method handle_exclusions_by_pattern.
@Test
public void handle_exclusions_by_pattern() {
SensorStorage sensorStorage = mock(SensorStorage.class);
Settings settings = new MapSettings();
settings.setProperty("sonar.cpd.exclusions", "src/Foo.java,another");
DefaultCpdTokens tokens = new DefaultCpdTokens(settings, sensorStorage).onFile(INPUT_FILE).addToken(INPUT_FILE.newRange(1, 2, 1, 5), "foo");
tokens.save();
verifyZeroInteractions(sensorStorage);
assertThat(tokens.getTokenLines()).isEmpty();
}
use of org.sonar.api.batch.sensor.internal.SensorStorage in project sonarqube by SonarSource.
the class DefaultIssueTest method build_directory_issue.
@Test
public void build_directory_issue() {
SensorStorage storage = mock(SensorStorage.class);
DefaultIssue issue = new DefaultIssue(storage).at(new DefaultIssueLocation().on(new DefaultInputDir("foo", "src")).message("Wrong way!")).forRule(RuleKey.of("repo", "rule")).overrideSeverity(Severity.BLOCKER);
assertThat(issue.primaryLocation().inputComponent()).isEqualTo(new DefaultInputDir("foo", "src"));
assertThat(issue.ruleKey()).isEqualTo(RuleKey.of("repo", "rule"));
assertThat(issue.primaryLocation().textRange()).isNull();
assertThat(issue.primaryLocation().message()).isEqualTo("Wrong way!");
assertThat(issue.overriddenSeverity()).isEqualTo(Severity.BLOCKER);
issue.save();
verify(storage).store(issue);
}
use of org.sonar.api.batch.sensor.internal.SensorStorage in project sonarqube by SonarSource.
the class DefaultHighlightableTest method should_store_highlighting_rules.
@Test
public void should_store_highlighting_rules() {
SensorStorage sensorStorage = mock(SensorStorage.class);
DefaultInputFile inputFile = new TestInputFileBuilder("foo", "src/Foo.php").initMetadata("azerty\nbla bla").build();
DefaultHighlightable highlightablePerspective = new DefaultHighlightable(inputFile, sensorStorage, mock(AnalysisMode.class));
highlightablePerspective.newHighlighting().highlight(0, 6, "k").highlight(7, 10, "cppd").done();
ArgumentCaptor<DefaultHighlighting> argCaptor = ArgumentCaptor.forClass(DefaultHighlighting.class);
verify(sensorStorage).store(argCaptor.capture());
assertThat(argCaptor.getValue().getSyntaxHighlightingRuleSet()).hasSize(2);
}
use of org.sonar.api.batch.sensor.internal.SensorStorage in project sonar-java by SonarSource.
the class JavaIssueTest method test_addFlow.
@Test
public void test_addFlow() throws Exception {
TestInputFileBuilder tifb = new TestInputFileBuilder("module", "relPath");
tifb.setModuleBaseDir(new java.io.File("").toPath());
tifb.setLines(3);
tifb.setOriginalLineOffsets(new int[] { 0, 10, 15 });
tifb.setLastValidOffset(25);
DefaultInputFile file = tifb.build();
RuleKey ruleKey = RuleKey.of("squid", "ruleKey");
SensorContext sensorContext = mock(SensorContext.class);
SensorStorage storage = mock(SensorStorage.class);
DefaultIssue newIssueEmptyFlow = new DefaultIssue(storage);
DefaultIssue newIssueWithFlow = new DefaultIssue(storage);
Mockito.when(sensorContext.newIssue()).thenReturn(newIssueEmptyFlow, newIssueWithFlow);
JavaIssue javaIssue = JavaIssue.create(sensorContext, ruleKey, null);
javaIssue.setPrimaryLocation(file, "main message", 1, 2, 1, 6);
javaIssue.addFlow(file, new ArrayList<>());
javaIssue.save();
Mockito.verify(storage, Mockito.times(1)).store(newIssueEmptyFlow);
assertThat(newIssueEmptyFlow.flows()).isEmpty();
javaIssue = JavaIssue.create(sensorContext, ruleKey, null);
javaIssue.setPrimaryLocation(file, "main message", 1, 2, 1, 6);
List<List<AnalyzerMessage>> flows = new ArrayList<>();
flows.add(Lists.newArrayList(new AnalyzerMessage(null, file.file(), new AnalyzerMessage.TextSpan(2, 2, 2, 4), "flow message 1", 0)));
flows.add(Lists.newArrayList(new AnalyzerMessage(null, file.file(), new AnalyzerMessage.TextSpan(3, 1, 3, 5), "flow message 2", 0)));
javaIssue.addFlow(file, flows);
javaIssue.save();
Mockito.verify(storage, Mockito.times(1)).store(newIssueWithFlow);
assertThat(newIssueWithFlow.flows()).hasSize(2);
}
use of org.sonar.api.batch.sensor.internal.SensorStorage in project sonarqube by SonarSource.
the class DefaultAdHocRuleTest method description_is_optional.
@Test
public void description_is_optional() {
SensorStorage storage = mock(SensorStorage.class);
new DefaultAdHocRule(storage).engineId("engine").ruleId("ruleId").name("name").severity(Severity.BLOCKER).type(RuleType.CODE_SMELL).save();
verify(storage).store(any(DefaultAdHocRule.class));
}
Aggregations