Merge "Clean up Validator code"
diff --git a/src/main/java/com/googlesource/gerrit/plugins/findowners/OwnersValidator.java b/src/main/java/com/googlesource/gerrit/plugins/findowners/OwnersValidator.java
index cf3efb4..deda93e 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/findowners/OwnersValidator.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/findowners/OwnersValidator.java
@@ -46,7 +46,6 @@
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
-import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -124,7 +123,7 @@
@Override
public List<CommitValidationMessage> onCommitReceived(CommitReceivedEvent receiveEvent)
throws CommitValidationException {
- List<CommitValidationMessage> messages = new LinkedList<>();
+ List<CommitValidationMessage> messages = new ArrayList<>();
try {
Project.NameKey project = receiveEvent.project.getNameKey();
PluginConfig cfg = cfgFactory.getFromProjectConfigWithInheritance(project, pluginName);
@@ -145,7 +144,7 @@
List<CommitValidationMessage> performValidation(
RevCommit c, RevWalk revWalk, String ownersFileName, boolean verbose) throws IOException {
// Collect all messages from all files.
- List<CommitValidationMessage> messages = new LinkedList<>();
+ List<CommitValidationMessage> messages = new ArrayList<>();
// Collect all email addresses from all files and check each address only once.
Map<String, Set<String>> email2lines = new HashMap<>();
Map<String, ObjectId> content = getChangedOwners(c, revWalk, ownersFileName);
diff --git a/src/test/java/com/googlesource/gerrit/plugins/findowners/OwnersValidatorTest.java b/src/test/java/com/googlesource/gerrit/plugins/findowners/OwnersValidatorTest.java
index bd6de95..08c8dfe 100644
--- a/src/test/java/com/googlesource/gerrit/plugins/findowners/OwnersValidatorTest.java
+++ b/src/test/java/com/googlesource/gerrit/plugins/findowners/OwnersValidatorTest.java
@@ -31,8 +31,8 @@
import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
+import java.util.ArrayList;
import java.util.HashMap;
-import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -254,6 +254,17 @@
return makeCommit(rw, repo, message, fileBytes);
}
+ private static RevCommit makeCommit(
+ RevWalk rw, Repository repo, String message, Map<File, byte[]> files)
+ throws IOException, GitAPIException {
+ try (Git git = new Git(repo)) {
+ if (files != null) {
+ addFiles(git, files);
+ }
+ return rw.parseCommit(git.commit().setMessage(message).call());
+ }
+ }
+
private List<String> validate(RevWalk rw, RevCommit c, boolean verbose, PluginConfig cfg)
throws Exception {
MockedEmails myEmails = new MockedEmails();
@@ -284,24 +295,13 @@
ac.call();
}
- private static RevCommit makeCommit(
- RevWalk rw, Repository repo, String message, Map<File, byte[]> files)
- throws IOException, GitAPIException {
- try (Git git = new Git(repo)) {
- if (files != null) {
- addFiles(git, files);
- }
- return rw.parseCommit(git.commit().setMessage(message).call());
- }
- }
-
private static List<String> transformMessages(List<CommitValidationMessage> messages) {
return Lists.transform(
messages,
new Function<CommitValidationMessage, String>() {
@Override
public String apply(CommitValidationMessage input) {
- String pre = (input.isError()) ? "ERROR: " : "MSG: ";
+ String pre = input.isError() ? "ERROR: " : "MSG: ";
return pre + input.getMessage();
}
});
@@ -309,7 +309,7 @@
@Test
public void testTransformer() {
- List<CommitValidationMessage> messages = new LinkedList<>();
+ List<CommitValidationMessage> messages = new ArrayList<>();
messages.add(new CommitValidationMessage("a message", false));
messages.add(new CommitValidationMessage("an error", true));
Set<String> expected = ImmutableSet.of("ERROR: an error", "MSG: a message");