diff options
author | Julien Lancelot <julien.lancelot@sonarsource.com> | 2014-10-08 15:13:54 +0200 |
---|---|---|
committer | Julien Lancelot <julien.lancelot@sonarsource.com> | 2014-10-08 15:30:46 +0200 |
commit | 99fa2be3429f1612edd016d1260c08d97ebc8404 (patch) | |
tree | d641ee3264379abf1e55eba2e5492122da473992 /sonar-batch | |
parent | d5d20d0f777ba89b49575846c8f96afd316829f4 (diff) | |
download | sonarqube-99fa2be3429f1612edd016d1260c08d97ebc8404.tar.gz sonarqube-99fa2be3429f1612edd016d1260c08d97ebc8404.zip |
Fix quality flaws
Diffstat (limited to 'sonar-batch')
-rw-r--r-- | sonar-batch/src/main/java/org/sonar/batch/issue/ScanIssueStorage.java | 12 | ||||
-rw-r--r-- | sonar-batch/src/test/java/org/sonar/batch/issue/ScanIssueStorageTest.java | 2 |
2 files changed, 9 insertions, 5 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/issue/ScanIssueStorage.java b/sonar-batch/src/main/java/org/sonar/batch/issue/ScanIssueStorage.java index 9f3ae235db8..18cbd39daba 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/issue/ScanIssueStorage.java +++ b/sonar-batch/src/main/java/org/sonar/batch/issue/ScanIssueStorage.java @@ -19,6 +19,7 @@ */ package org.sonar.batch.issue; +import com.google.common.annotations.VisibleForTesting; import org.sonar.api.BatchComponent; import org.sonar.api.database.model.Snapshot; import org.sonar.api.issue.Issue; @@ -55,7 +56,7 @@ public class ScanIssueStorage extends IssueStorage implements BatchComponent { protected void doInsert(DbSession session, Date now, DefaultIssue issue) { IssueMapper issueMapper = session.getMapper(IssueMapper.class); long componentId = componentId(issue); - long projectId = projectId(issue); + long projectId = projectId(); int ruleId = ruleId(issue); IssueDto dto = IssueDto.toDtoForInsert(issue, componentId, projectId, ruleId, now); issueMapper.insert(dto); @@ -63,7 +64,7 @@ public class ScanIssueStorage extends IssueStorage implements BatchComponent { protected void doUpdate(DbSession session, Date now, DefaultIssue issue) { IssueMapper issueMapper = session.getMapper(IssueMapper.class); - IssueDto dto = IssueDto.toDtoForUpdate(issue, projectId(issue), now); + IssueDto dto = IssueDto.toDtoForUpdate(issue, projectId(), now); if (Issue.STATUS_CLOSED.equals(issue.status()) || issue.selectedAt() == null) { // Issue is closed by scan or changed by end-user issueMapper.update(dto); @@ -78,7 +79,8 @@ public class ScanIssueStorage extends IssueStorage implements BatchComponent { } } - protected long componentId(DefaultIssue issue) { + @VisibleForTesting + long componentId(DefaultIssue issue) { Snapshot snapshot = snapshotCache.get(issue.componentKey()); if (snapshot != null) { return snapshot.getResourceId(); @@ -92,7 +94,9 @@ public class ScanIssueStorage extends IssueStorage implements BatchComponent { return resourceDto.getId(); } - protected long projectId(DefaultIssue issue) { + + @VisibleForTesting + long projectId() { return projectTree.getRootProject().getId(); } diff --git a/sonar-batch/src/test/java/org/sonar/batch/issue/ScanIssueStorageTest.java b/sonar-batch/src/test/java/org/sonar/batch/issue/ScanIssueStorageTest.java index 983d560d70d..7c7972f75f2 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/issue/ScanIssueStorageTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/issue/ScanIssueStorageTest.java @@ -100,7 +100,7 @@ public class ScanIssueStorageTest extends AbstractDaoTestCase { public void should_load_project_id() throws Exception { when(projectTree.getRootProject()).thenReturn((Project) new Project("struts").setId(100)); - long projectId = storage.projectId(new DefaultIssue().setComponentKey("struts:Action.java")); + long projectId = storage.projectId(); assertThat(projectId).isEqualTo(100); } |