Search in sources :

Example 21 with SensorStorage

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

the class DefaultIssueTest method default_issue_has_no_quickfix.

@Test
public void default_issue_has_no_quickfix() {
    SensorStorage storage = mock(SensorStorage.class);
    DefaultIssue issue = new DefaultIssue(project, storage);
    assertThat(issue.isQuickFixAvailable()).isFalse();
}
Also used : SensorStorage(org.sonar.api.batch.sensor.internal.SensorStorage) Test(org.junit.Test)

Example 22 with SensorStorage

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

the class DefaultIssueTest method issue_can_have_quickfix.

@Test
public void issue_can_have_quickfix() {
    SensorStorage storage = mock(SensorStorage.class);
    DefaultIssue issue = new DefaultIssue(project, storage).setQuickFixAvailable(true);
    assertThat(issue.isQuickFixAvailable()).isTrue();
}
Also used : SensorStorage(org.sonar.api.batch.sensor.internal.SensorStorage) Test(org.junit.Test)

Example 23 with SensorStorage

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

the class DefaultIssueTest method move_directory_issue_to_project_root.

@Test
public void move_directory_issue_to_project_root() {
    SensorStorage storage = mock(SensorStorage.class);
    DefaultIssue issue = new DefaultIssue(project, storage).at(new DefaultIssueLocation().on(new DefaultInputDir("foo", "src/main").setModuleBaseDir(project.getBaseDir())).message("Wrong way!")).forRule(RuleKey.of("repo", "rule")).overrideSeverity(Severity.BLOCKER);
    assertThat(issue.primaryLocation().inputComponent()).isEqualTo(project);
    assertThat(issue.ruleKey()).isEqualTo(RuleKey.of("repo", "rule"));
    assertThat(issue.primaryLocation().textRange()).isNull();
    assertThat(issue.primaryLocation().message()).isEqualTo("[src/main] Wrong way!");
    assertThat(issue.overriddenSeverity()).isEqualTo(Severity.BLOCKER);
    issue.save();
    verify(storage).store(issue);
}
Also used : DefaultInputDir(org.sonar.api.batch.fs.internal.DefaultInputDir) SensorStorage(org.sonar.api.batch.sensor.internal.SensorStorage) Test(org.junit.Test)

Example 24 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 = Mockito.mock(SensorStorage.class);
    DefaultMeasure<Integer> newMeasure = new DefaultMeasure<Integer>(storage).forMetric(CoreMetrics.LINES).on(new TestInputFileBuilder("foo", "src/Foo.php").build()).withValue(3);
    Assertions.assertThat(newMeasure.inputComponent()).isEqualTo(new TestInputFileBuilder("foo", "src/Foo.php").build());
    Assertions.assertThat(newMeasure.metric()).isEqualTo(CoreMetrics.LINES);
    Assertions.assertThat(newMeasure.value()).isEqualTo(3);
    newMeasure.save();
    Mockito.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 25 with SensorStorage

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

the class DefaultAdHocRuleTest method fail_to_store_if_no_severity.

@Test
public void fail_to_store_if_no_severity() {
    SensorStorage storage = mock(SensorStorage.class);
    NewAdHocRule rule = new DefaultAdHocRule(storage).engineId("engine").ruleId("ruleId").name("name").description("desc").type(RuleType.CODE_SMELL);
    assertThatThrownBy(() -> rule.save()).isInstanceOf(IllegalStateException.class).hasMessageContaining("Severity is mandatory");
}
Also used : NewAdHocRule(org.sonar.api.batch.sensor.rule.NewAdHocRule) SensorStorage(org.sonar.api.batch.sensor.internal.SensorStorage) Test(org.junit.Test)

Aggregations

SensorStorage (org.sonar.api.batch.sensor.internal.SensorStorage)32 Test (org.junit.Test)27 TestInputFileBuilder (org.sonar.api.batch.fs.internal.TestInputFileBuilder)5 NewAdHocRule (org.sonar.api.batch.sensor.rule.NewAdHocRule)5 DefaultInputFile (org.sonar.api.batch.fs.internal.DefaultInputFile)4 DefaultIssue (org.sonar.api.batch.sensor.issue.internal.DefaultIssue)4 RuleKey (org.sonar.api.rule.RuleKey)4 Before (org.junit.Before)3 InputFile (org.sonar.api.batch.fs.InputFile)3 MetricFinder (org.sonar.api.batch.measure.MetricFinder)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Test (org.junit.jupiter.api.Test)2 AnalysisMode (org.sonar.api.batch.AnalysisMode)2 SensorContext (org.sonar.api.batch.SensorContext)2 DefaultFileSystem (org.sonar.api.batch.fs.internal.DefaultFileSystem)2 DefaultInputDir (org.sonar.api.batch.fs.internal.DefaultInputDir)2 DefaultInputModule (org.sonar.api.batch.fs.internal.DefaultInputModule)2 ActiveRulesBuilder (org.sonar.api.batch.rule.internal.ActiveRulesBuilder)2 SensorContext (org.sonar.api.batch.sensor.SensorContext)2