]> source.dussan.org Git - sonarqube.git/commitdiff
Fix bug on UpdateReviewsDecorator when a violation has no line number
authorFabrice Bellingard <bellingard@gmail.com>
Wed, 4 Jan 2012 08:56:50 +0000 (09:56 +0100)
committerFabrice Bellingard <bellingard@gmail.com>
Wed, 4 Jan 2012 08:59:11 +0000 (09:59 +0100)
plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/UpdateReviewsDecorator.java
plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/UpdateReviewsDecoratorTest.java
plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/sensors/UpdateReviewsDecoratorTest/fixture.xml
plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/sensors/UpdateReviewsDecoratorTest/shouldUpdateReviews-result.xml

index 790f09295110bc5428e6e12434bf58cca0669d79..b6c6e0081e324d0968ceaafe8aa8874583a67a17 100644 (file)
@@ -105,7 +105,8 @@ public class UpdateReviewsDecorator implements Decorator {
     if (violation != null) {
       String message = violation.getMessage();
       Integer line = violation.getLineId();
-      if ( !review.getTitle().equals(message) || !review.getResourceLine().equals(line)) {
+      if ( !review.getTitle().equals(message) || (review.getResourceLine() == null && line != null)
+          || (review.getResourceLine() != null && !review.getResourceLine().equals(line))) {
         updateReviewQuery.setParameter(1, message).setParameter(2, line).setParameter(3, review.getId()).executeUpdate();
       }
     }
index 2a8797cf97996dc08291dfcf850e4a61e2ec5e15..01ff4f73906106abe1fd8ba960cfc967f19322c9 100644 (file)
@@ -51,12 +51,12 @@ public class UpdateReviewsDecoratorTest extends AbstractDbUnitTestCase {
     Snapshot snapshot = new Snapshot();
     snapshot.setResourceId(1);
     when(resourcePersister.getSnapshot(resource)).thenReturn(snapshot);
-    
+
     Project project = mock(Project.class);
     when(project.getRoot()).thenReturn(project);
-    
+
     violationTrackingDecorator = mock(ViolationTrackingDecorator.class);
-    
+
     reviewsDecorator = new UpdateReviewsDecorator(resourcePersister, getSession(), violationTrackingDecorator);
   }
 
@@ -80,10 +80,14 @@ public class UpdateReviewsDecoratorTest extends AbstractDbUnitTestCase {
     when(v3.getLineId()).thenReturn(3);
     Violation v4 = mock(Violation.class);
     when(v4.getMessage()).thenReturn("message 4");
-    when(v4.getLineId()).thenReturn(4);    
+    when(v4.getLineId()).thenReturn(4);
+    // specific case when a violation has no line number
+    Violation v5 = mock(Violation.class);
+    when(v5.getMessage()).thenReturn("message 5");
+    when(v5.getLineId()).thenReturn(null);
     DecoratorContext context = mock(DecoratorContext.class);
-    when(context.getViolations()).thenReturn(Lists.newArrayList(v1,v2,v3,v4));
-    
+    when(context.getViolations()).thenReturn(Lists.newArrayList(v1, v2, v3, v4, v5));
+
     RuleFailureModel rf1 = mock(RuleFailureModel.class);
     when(rf1.getPermanentId()).thenReturn(1);
     when(violationTrackingDecorator.getReferenceViolation(v1)).thenReturn(rf1);
@@ -96,12 +100,14 @@ public class UpdateReviewsDecoratorTest extends AbstractDbUnitTestCase {
     RuleFailureModel rf4 = mock(RuleFailureModel.class);
     when(rf4.getPermanentId()).thenReturn(4);
     when(violationTrackingDecorator.getReferenceViolation(v4)).thenReturn(rf4);
-    
+    RuleFailureModel rf5 = mock(RuleFailureModel.class);
+    when(rf5.getPermanentId()).thenReturn(5);
+    when(violationTrackingDecorator.getReferenceViolation(v5)).thenReturn(rf5);
+
     setupData("fixture");
-    
+
     reviewsDecorator.decorate(resource, context);
-    
-    
+
     checkTables("shouldUpdateReviews", new String[] { "updated_at" }, new String[] { "reviews" });
   }
 }
index 62e91386059ab12bcaaa577d6f9f390cc79d259b..71bfcf97fac3bea39881753962c4b7018acdf66d 100644 (file)
     rule_id="[null]"
     manual_violation="false"
     manual_severity="false"/>
+  <reviews
+    id="5"
+    status="OPEN"
+    rule_failure_permanent_id="5"
+    resource_id="1"
+    title="message 5"
+    resource_line="[null]"
+    rule_id="[null]"
+    manual_violation="false"
+    manual_severity="false"/>
 
 </dataset>
\ No newline at end of file
index 83dd96b6121aed5f79ac4594181c6afe1085052c..cb41697da88bff5e62c210b9296ac92de780e110 100644 (file)
     rule_id="[null]"
     manual_violation="false"
     manual_severity="false"/>
+  <reviews
+    id="5"
+    status="OPEN"
+    rule_failure_permanent_id="5"
+    resource_id="1"
+    title="message 5"
+    resource_line="[null]"
+    created_at="[null]" user_id="[null]" assignee_id="[null]" resolution="[null]" severity="[null]" project_id="[null]"
+    rule_id="[null]"
+    manual_violation="false"
+    manual_severity="false"/>
 
 </dataset>
\ No newline at end of file