]> source.dussan.org Git - sonarqube.git/commitdiff
Fix some quality flaws
authorSimon Brandhof <simon.brandhof@gmail.com>
Mon, 3 Jun 2013 04:51:08 +0000 (06:51 +0200)
committerSimon Brandhof <simon.brandhof@gmail.com>
Mon, 3 Jun 2013 04:51:08 +0000 (06:51 +0200)
sonar-batch/src/main/java/org/sonar/batch/index/ComponentDataPersister.java
sonar-core/src/main/java/org/sonar/core/issue/workflow/IssueWorkflow.java
sonar-core/src/main/java/org/sonar/core/issue/workflow/State.java
sonar-core/src/test/java/org/sonar/core/issue/workflow/IssueWorkflowTest.java

index 7d7532b250394366ea273753ba85f63a0f8f8272..c40701f150ec4e216fcc3245d2c9c0dba14e48d5 100644 (file)
@@ -48,12 +48,13 @@ public class ComponentDataPersister implements ScanPersister {
       String componentKey = componentEntry.getKey();
       Snapshot snapshot = componentEntry.getValue();
       for (Cache.Entry<Data> dataEntry : data.entries(componentKey)) {
-        if (dataEntry.value() != null) {
+        Data value = dataEntry.value();
+        if (value != null) {
           SnapshotDataDto dto = new SnapshotDataDto();
           dto.setSnapshotId(snapshot.getId());
           dto.setResourceId(snapshot.getResourceId());
           dto.setDataType(dataEntry.key());
-          dto.setData(dataEntry.value().writeString());
+          dto.setData(value.writeString());
           dao.insert(session, dto);
         }
       }
index bbd752f5e219ae5cfd79ee6182bdf7b1579829f9..12a8318fadf389d52cdb14f0f3f5e63bfb12c6e2 100644 (file)
@@ -160,7 +160,11 @@ public class IssueWorkflow implements BatchComponent, ServerComponent, Startable
   }
 
   public List<Transition> outTransitions(Issue issue) {
-    return machine.state(issue.status()).outManualTransitions(issue);
+    State state = machine.state(issue.status());
+    if (state == null) {
+      throw new IllegalArgumentException("Unknown status: " + issue.status());
+    }
+    return state.outManualTransitions(issue);
   }
 
   public void doAutomaticTransition(DefaultIssue issue, IssueChangeContext issueChangeContext) {
index 98388f22c535a36e9efb890a4f834ade4e29f6ad..5660152d5ad03dd13f9df86c64159dd2540e6a70 100644 (file)
@@ -27,7 +27,6 @@ import org.apache.commons.lang.StringUtils;
 import org.sonar.api.issue.Issue;
 
 import javax.annotation.CheckForNull;
-
 import java.util.List;
 import java.util.Set;
 
index 7ee3d8f29b0506c4419439dfa0f5ac3bbedaecf8..eda0b11523ac0ec248f26de437f1e7bfe232d3fe 100644 (file)
@@ -104,6 +104,20 @@ public class IssueWorkflowTest {
     assertThat(keys(transitions)).containsOnly("confirm", "resolve", "falsepositive");
   }
 
+  @Test
+  public void should_fail_if_unknown_status_when_listing_transitions() throws Exception {
+    workflow.start();
+
+    DefaultIssue issue = new DefaultIssue().setStatus("xxx");
+    try {
+      workflow.outTransitions(issue);
+      fail();
+    } catch (IllegalArgumentException e) {
+      assertThat(e).hasMessage("Unknown status: xxx");
+    }
+  }
+
+
   @Test
   public void should_do_automatic_transition() throws Exception {
     workflow.start();
@@ -178,7 +192,7 @@ public class IssueWorkflowTest {
 
 
   @Test
-  public void should_fail_if_unknown_status() throws Exception {
+  public void should_fail_if_unknown_status_on_automatic_trans() throws Exception {
     workflow.start();
 
     DefaultIssue issue = new DefaultIssue()