From 71e1d5887f78d55989ec3383d9138a870c24c9ca Mon Sep 17 00:00:00 2001 From: Freddy Mallet Date: Fri, 29 Apr 2011 11:14:42 +0200 Subject: [PATCH] Slightly improve fix bug of violation tracking when past violation has no checksum. --- .../ViolationPersisterDecorator.java | 2 +- .../ViolationPersisterDecoratorTest.java | 22 ++++++++++++------- 2 files changed, 15 insertions(+), 9 deletions(-) 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; } -- 2.39.5