return null;
}
- private final boolean isSameChecksum(Violation newViolation, RuleFailureModel pastViolation) {
- return pastViolation.getChecksum().equals(getChecksumForLine(checksums, newViolation.getLineId()));
+ private boolean isSameChecksum(Violation newViolation, RuleFailureModel pastViolation) {
+ return pastViolation.getChecksum()!=null && StringUtils.equals(pastViolation.getChecksum(), getChecksumForLine(checksums, newViolation.getLineId()));
}
- private final boolean isSameLine(Violation newViolation, RuleFailureModel pastViolation) {
+ private boolean isSameLine(Violation newViolation, RuleFailureModel pastViolation) {
return pastViolation.getLine() == newViolation.getLineId();
}
- private final boolean isSameMessage(Violation newViolation, RuleFailureModel pastViolation) {
+ private boolean isSameMessage(Violation newViolation, RuleFailureModel pastViolation) {
return StringUtils.equals(RuleFailureModel.abbreviateMessage(newViolation.getMessage()), pastViolation.getMessage());
}
*/
package org.sonar.plugins.core.timemachine;
-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 com.google.common.collect.Lists;
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 com.google.common.collect.Lists;
+import java.util.List;
+import java.util.Map;
+
+import static org.hamcrest.Matchers.*;
+import static org.junit.Assert.assertThat;
public class ViolationPersisterDecoratorTest {
assertThat(mapping.get(newViolation), equalTo(pastViolation));
}
+ @Test
+ public void pastMeasureHasNoChecksum() {
+ Violation newViolation = newViolation("message", 1, 50, "checksum1");
+ RuleFailureModel pastViolation = newPastViolation("message", 1, 51, null);
+
+ Map<Violation, RuleFailureModel> mapping = decorator.mapViolations(Lists.newArrayList(newViolation), Lists.newArrayList(pastViolation));
+ assertThat(mapping.get(newViolation), is(nullValue()));
+ }
+
@Test
public void sameRuleAndMessageAndChecksumButDifferentLine() {
Violation newViolation = newViolation("message", 1, 50, "checksum1");
private Violation newViolation(String message, int lineId, int ruleId) {
Rule rule = Rule.create().setKey("rule");
rule.setId(ruleId);
- Violation violation = Violation.create(rule, null).setLineId(lineId).setMessage(message);
- return violation;
+ return Violation.create(rule, null).setLineId(lineId).setMessage(message);
}
private Violation newViolation(String message, int lineId, int ruleId, String lineChecksum) {
private RuleFailureModel newPastViolation(String message, int lineId, int ruleId, String lineChecksum) {
RuleFailureModel pastViolation = newPastViolation(message, lineId, ruleId);
- pastViolation.setChecksum(ViolationPersisterDecorator.getChecksum(lineChecksum));
+ if (lineChecksum != null) {
+ pastViolation.setChecksum(ViolationPersisterDecorator.getChecksum(lineChecksum));
+ }
return pastViolation;
}