diff options
Diffstat (limited to 'sonar-plugin-api-impl')
2 files changed, 23 insertions, 16 deletions
diff --git a/sonar-plugin-api-impl/src/main/java/org/sonar/api/batch/sensor/issue/internal/DefaultExternalIssue.java b/sonar-plugin-api-impl/src/main/java/org/sonar/api/batch/sensor/issue/internal/DefaultExternalIssue.java index eca02788543..93c298d76ea 100644 --- a/sonar-plugin-api-impl/src/main/java/org/sonar/api/batch/sensor/issue/internal/DefaultExternalIssue.java +++ b/sonar-plugin-api-impl/src/main/java/org/sonar/api/batch/sensor/issue/internal/DefaultExternalIssue.java @@ -20,11 +20,11 @@ package org.sonar.api.batch.sensor.issue.internal; import javax.annotation.Nullable; +import org.sonar.api.batch.fs.internal.DefaultInputProject; import org.sonar.api.batch.rule.Severity; import org.sonar.api.batch.sensor.internal.SensorStorage; import org.sonar.api.batch.sensor.issue.ExternalIssue; import org.sonar.api.batch.sensor.issue.NewExternalIssue; -import org.sonar.api.batch.fs.internal.DefaultInputProject; import org.sonar.api.rule.RuleKey; import org.sonar.api.rules.RuleType; @@ -86,7 +86,6 @@ public class DefaultExternalIssue extends AbstractDefaultIssue<DefaultExternalIs requireNonNull(this.engineId, "Engine id is mandatory on external issue"); requireNonNull(this.ruleId, "Rule id is mandatory on external issue"); checkState(primaryLocation != null, "Primary location is mandatory on every external issue"); - checkState(primaryLocation.inputComponent().isFile(), "External issues must be located in files"); checkState(primaryLocation.message() != null, "External issues must have a message"); checkState(severity != null, "Severity is mandatory on every external issue"); checkState(type != null, "Type is mandatory on every external issue"); diff --git a/sonar-plugin-api-impl/src/test/java/org/sonar/api/batch/sensor/issue/internal/DefaultExternalIssueTest.java b/sonar-plugin-api-impl/src/test/java/org/sonar/api/batch/sensor/issue/internal/DefaultExternalIssueTest.java index b59b0d1d9ab..9659c371e22 100644 --- a/sonar-plugin-api-impl/src/test/java/org/sonar/api/batch/sensor/issue/internal/DefaultExternalIssueTest.java +++ b/sonar-plugin-api-impl/src/test/java/org/sonar/api/batch/sensor/issue/internal/DefaultExternalIssueTest.java @@ -26,16 +26,13 @@ import org.junit.Test; import org.junit.rules.ExpectedException; import org.junit.rules.TemporaryFolder; import org.sonar.api.batch.bootstrap.ProjectDefinition; -import org.sonar.api.batch.fs.InputComponent; +import org.sonar.api.batch.fs.internal.DefaultInputFile; +import org.sonar.api.batch.fs.internal.DefaultInputProject; +import org.sonar.api.batch.fs.internal.TestInputFileBuilder; import org.sonar.api.batch.rule.Severity; import org.sonar.api.batch.sensor.internal.SensorStorage; -import org.sonar.api.batch.sensor.issue.internal.DefaultExternalIssue; import org.sonar.api.rule.RuleKey; import org.sonar.api.rules.RuleType; -import org.sonar.api.batch.fs.internal.DefaultInputFile; -import org.sonar.api.batch.fs.internal.DefaultInputProject; -import org.sonar.api.batch.fs.internal.TestInputFileBuilder; -import org.sonar.api.batch.sensor.issue.internal.DefaultIssueLocation; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; @@ -92,35 +89,46 @@ public class DefaultExternalIssueTest { } @Test - public void fail_to_store_if_no_type() { + public void build_project_issue() { SensorStorage storage = mock(SensorStorage.class); DefaultExternalIssue issue = new DefaultExternalIssue(project, storage) .at(new DefaultIssueLocation() - .on(inputFile) - .at(inputFile.selectLine(1)) + .on(project) .message("Wrong way!")) .forRule(RuleKey.of("repo", "rule")) .remediationEffortMinutes(10l) + .type(RuleType.BUG) .severity(Severity.BLOCKER); - exception.expect(IllegalStateException.class); - exception.expectMessage("Type is mandatory"); + assertThat(issue.primaryLocation().inputComponent()).isEqualTo(project); + assertThat(issue.ruleKey()).isEqualTo(RuleKey.of("external_repo", "rule")); + assertThat(issue.engineId()).isEqualTo("repo"); + assertThat(issue.ruleId()).isEqualTo("rule"); + assertThat(issue.primaryLocation().textRange()).isNull(); + assertThat(issue.remediationEffort()).isEqualTo(10l); + assertThat(issue.type()).isEqualTo(RuleType.BUG); + assertThat(issue.severity()).isEqualTo(Severity.BLOCKER); + assertThat(issue.primaryLocation().message()).isEqualTo("Wrong way!"); + issue.save(); + + verify(storage).store(issue); } @Test - public void fail_to_store_if_primary_location_is_not_a_file() { + public void fail_to_store_if_no_type() { SensorStorage storage = mock(SensorStorage.class); DefaultExternalIssue issue = new DefaultExternalIssue(project, storage) .at(new DefaultIssueLocation() - .on(mock(InputComponent.class)) + .on(inputFile) + .at(inputFile.selectLine(1)) .message("Wrong way!")) .forRule(RuleKey.of("repo", "rule")) .remediationEffortMinutes(10l) .severity(Severity.BLOCKER); exception.expect(IllegalStateException.class); - exception.expectMessage("External issues must be located in files"); + exception.expectMessage("Type is mandatory"); issue.save(); } |