From 0ff89430afcf4c43b797f376e7b676a63344365b Mon Sep 17 00:00:00 2001 From: Hector Oswaldo Caballero Date: Tue, 16 Jan 2018 22:14:00 -0500 Subject: [PATCH] [project.config] Override ValidationError equals() Change-Id: Iebea816ff95c57dbe778df88f2ccae0e0e34fc90 --- .../gerrit/server/git/ValidationError.java | 18 +++++++++++++ .../gerrit/server/git/ProjectConfigTest.java | 26 ++++++++++--------- 2 files changed, 32 insertions(+), 12 deletions(-) diff --git a/java/com/google/gerrit/server/git/ValidationError.java b/java/com/google/gerrit/server/git/ValidationError.java index 9cefeafc9d..2fd65d2546 100644 --- a/java/com/google/gerrit/server/git/ValidationError.java +++ b/java/com/google/gerrit/server/git/ValidationError.java @@ -14,6 +14,7 @@ package com.google.gerrit.server.git; +import java.util.Objects; import org.slf4j.Logger; /** Indicates a problem with Git based data. */ @@ -48,4 +49,21 @@ public class ValidationError { public static Sink createLoggerSink(String message, Logger log) { return error -> log.error(message + error.getMessage()); } + + @Override + public boolean equals(Object o) { + if (o == this) { + return true; + } + if (o instanceof ValidationError) { + ValidationError that = (ValidationError) o; + return Objects.equals(this.message, that.message); + } + return false; + } + + @Override + public int hashCode() { + return Objects.hashCode(message); + } } diff --git a/javatests/com/google/gerrit/server/git/ProjectConfigTest.java b/javatests/com/google/gerrit/server/git/ProjectConfigTest.java index 8f198c7084..9a53435f13 100644 --- a/javatests/com/google/gerrit/server/git/ProjectConfigTest.java +++ b/javatests/com/google/gerrit/server/git/ProjectConfigTest.java @@ -16,7 +16,6 @@ package com.google.gerrit.server.git; import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertWithMessage; -import static com.google.common.truth.Truth8.assertThat; import com.google.common.collect.Iterables; import com.google.gerrit.common.data.AccessSection; @@ -516,12 +515,13 @@ public class ProjectConfigTest extends GerritBaseTests { .create(); ProjectConfig cfg = read(rev); assertThat(cfg.getCommentLinkSections()).isEmpty(); - assertThat(cfg.getValidationErrors().stream().map(ValidationError::getMessage)) + assertThat(cfg.getValidationErrors()) .containsExactly( - "project.config: Invalid pattern \"(bugs{+#?)(d+)\" in commentlink.bugzilla.match: " - + "Illegal repetition near index 4\n" - + "(bugs{+#?)(d+)\n" - + " ^"); + new ValidationError( + "project.config: Invalid pattern \"(bugs{+#?)(d+)\" in commentlink.bugzilla.match: " + + "Illegal repetition near index 4\n" + + "(bugs{+#?)(d+)\n" + + " ^")); } @Test @@ -536,10 +536,11 @@ public class ProjectConfigTest extends GerritBaseTests { .create(); ProjectConfig cfg = read(rev); assertThat(cfg.getCommentLinkSections()).isEmpty(); - assertThat(cfg.getValidationErrors().stream().map(ValidationError::getMessage)) + assertThat(cfg.getValidationErrors()) .containsExactly( - "project.config: Error in pattern \"(bugs#?)(d+)\" in commentlink.bugzilla.match: " - + "Raw html replacement not allowed"); + new ValidationError( + "project.config: Error in pattern \"(bugs#?)(d+)\" in commentlink.bugzilla.match: " + + "Raw html replacement not allowed")); } @Test @@ -550,10 +551,11 @@ public class ProjectConfigTest extends GerritBaseTests { .create(); ProjectConfig cfg = read(rev); assertThat(cfg.getCommentLinkSections()).isEmpty(); - assertThat(cfg.getValidationErrors().stream().map(ValidationError::getMessage)) + assertThat(cfg.getValidationErrors()) .containsExactly( - "project.config: Error in pattern \"(bugs#?)(d+)\" in commentlink.bugzilla.match: " - + "commentlink.bugzilla must have either link or html"); + new ValidationError( + "project.config: Error in pattern \"(bugs#?)(d+)\" in commentlink.bugzilla.match: " + + "commentlink.bugzilla must have either link or html")); } private ProjectConfig read(RevCommit rev) throws IOException, ConfigInvalidException {