]> source.dussan.org Git - sonarqube.git/commitdiff
Slightly improve fix bug of violation tracking when past violation has no checksum.
authorFreddy Mallet <freddy.mallet@gmail.com>
Fri, 29 Apr 2011 09:14:42 +0000 (11:14 +0200)
committerFreddy Mallet <freddy.mallet@gmail.com>
Fri, 29 Apr 2011 09:14:42 +0000 (11:14 +0200)
plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/ViolationPersisterDecorator.java
plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/ViolationPersisterDecoratorTest.java

index 4ad673c0bc53acb5851e5ac662480085773821b4..ece114c814412d2b00a9c2d5f35fef52e4c867ce 100644 (file)
@@ -161,7 +161,7 @@ public class ViolationPersisterDecorator implements Decorator {
   }
 
   private boolean isSameLine(Violation newViolation, RuleFailureModel pastViolation) {
-    return pastViolation.getLine() == newViolation.getLineId();
+    return pastViolation.getLine() == newViolation.getLineId(); //When lines are null, we also return true
   }
 
   private boolean isSameMessage(Violation newViolation, RuleFailureModel pastViolation) {
index 51c83a460ebff1ac75f245cf40ffa891357e357e..dda507ee93155f923492906990894d31d4ea9e30 100644 (file)
  */
 package org.sonar.plugins.core.timemachine;
 
-import com.google.common.collect.Lists;
+import static org.hamcrest.Matchers.equalTo;
+import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.not;
+import static org.hamcrest.Matchers.nullValue;
+import static org.junit.Assert.assertThat;
+
+import java.util.List;
+import java.util.Map;
+
 import org.junit.Before;
 import org.junit.Test;
 import org.sonar.api.database.model.RuleFailureModel;
 import org.sonar.api.rules.Rule;
 import org.sonar.api.rules.Violation;
 
-import java.util.List;
-import java.util.Map;
-
-import static org.hamcrest.Matchers.*;
-import static org.junit.Assert.assertThat;
+import com.google.common.collect.Lists;
 
 public class ViolationPersisterDecoratorTest {
 
@@ -90,7 +94,7 @@ public class ViolationPersisterDecoratorTest {
 
   @Test
   public void pastMeasureHasNoChecksum() {
-    Violation newViolation = newViolation("message", 1, 50, "checksum1");
+    Violation newViolation = newViolation("message", 1, 50, null);
     RuleFailureModel pastViolation = newPastViolation("message", 1, 51, null);
 
     Map<Violation, RuleFailureModel> mapping = decorator.mapViolations(Lists.newArrayList(newViolation), Lists.newArrayList(pastViolation));
@@ -149,7 +153,9 @@ public class ViolationPersisterDecoratorTest {
     for (int i = decorator.checksums.size() - 1; i < lineId; i++) {
       decorator.checksums.add("");
     }
-    decorator.checksums.set(lineId - 1, ViolationPersisterDecorator.getChecksum(lineChecksum));
+    if (lineChecksum != null) {
+      decorator.checksums.set(lineId - 1, ViolationPersisterDecorator.getChecksum(lineChecksum));
+    }
     return violation;
   }