From: Freddy Mallet Date: Fri, 29 Apr 2011 09:14:42 +0000 (+0200) Subject: Slightly improve fix bug of violation tracking when past violation has no checksum. X-Git-Tag: 2.8~76 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=71e1d5887f78d55989ec3383d9138a870c24c9ca;p=sonarqube.git Slightly improve fix bug of violation tracking when past violation has no checksum. --- diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/ViolationPersisterDecorator.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/ViolationPersisterDecorator.java index 4ad673c0bc5..ece114c8144 100644 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/ViolationPersisterDecorator.java +++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/ViolationPersisterDecorator.java @@ -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) { diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/ViolationPersisterDecoratorTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/ViolationPersisterDecoratorTest.java index 51c83a460eb..dda507ee931 100644 --- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/ViolationPersisterDecoratorTest.java +++ b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/ViolationPersisterDecoratorTest.java @@ -19,18 +19,22 @@ */ 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 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; }