Fix ErrorProne warnings
The following warnings have been fixed:
* Field name is CONSTANT_CASE, but field is not static and final
* Use grouping parenthesis to make the operator precedence explicit
* Redundant throws clause
* Constant field declarations should use the immutable type (such as
ImmutableList) instead of the general collection interface type (such
as List)
* This field is only assigned during initialization; consider making it
final
* Can be replaced with simpler, equivalent code.
* Private methods that do not reference the enclosing instance should be
static
Change-Id: I1099d368174e3039824167c845dd94c1aa324bbd
Signed-off-by: Edwin Kempin <ekempin@google.com>
diff --git a/src/main/java/com/googlesource/gerrit/plugins/uploadvalidator/BlockedKeywordValidator.java b/src/main/java/com/googlesource/gerrit/plugins/uploadvalidator/BlockedKeywordValidator.java
index a84b62d..5c5dc12 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/uploadvalidator/BlockedKeywordValidator.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/uploadvalidator/BlockedKeywordValidator.java
@@ -59,8 +59,8 @@
import java.util.regex.Pattern;
public class BlockedKeywordValidator implements CommitValidationListener {
- private static String KEY_CHECK_BLOCKED_KEYWORD = "blockedKeyword";
- private static String KEY_CHECK_BLOCKED_KEYWORD_PATTERN =
+ private static final String KEY_CHECK_BLOCKED_KEYWORD = "blockedKeyword";
+ private static final String KEY_CHECK_BLOCKED_KEYWORD_PATTERN =
KEY_CHECK_BLOCKED_KEYWORD + "Pattern";
public static AbstractModule module() {
diff --git a/src/main/java/com/googlesource/gerrit/plugins/uploadvalidator/ContentTypeUtil.java b/src/main/java/com/googlesource/gerrit/plugins/uploadvalidator/ContentTypeUtil.java
index ab1752d..493a108 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/uploadvalidator/ContentTypeUtil.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/uploadvalidator/ContentTypeUtil.java
@@ -38,7 +38,7 @@
import java.util.regex.Pattern;
public class ContentTypeUtil {
- private static String KEY_BINARY_TYPES = "binaryTypes";
+ private static final String KEY_BINARY_TYPES = "binaryTypes";
public static AbstractModule module() {
return new AbstractModule() {
diff --git a/src/main/java/com/googlesource/gerrit/plugins/uploadvalidator/ContentTypeValidator.java b/src/main/java/com/googlesource/gerrit/plugins/uploadvalidator/ContentTypeValidator.java
index 99fd624..ed236e1 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/uploadvalidator/ContentTypeValidator.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/uploadvalidator/ContentTypeValidator.java
@@ -70,8 +70,8 @@
};
}
- public static String KEY_BLOCKED_CONTENT_TYPE = "blockedContentType";
- public static String KEY_BLOCKED_CONTENT_TYPE_WHITELIST =
+ public static final String KEY_BLOCKED_CONTENT_TYPE = "blockedContentType";
+ public static final String KEY_BLOCKED_CONTENT_TYPE_WHITELIST =
"blockedContentTypeWhitelist";
@VisibleForTesting
@@ -147,8 +147,8 @@
String contentType = contentTypeUtil.getContentType(os, path);
if ((contentTypeUtil.matchesAny(contentType, blockedTypes)
&& !whitelist)
- || !contentTypeUtil.matchesAny(contentType, blockedTypes)
- && whitelist) {
+ || (!contentTypeUtil.matchesAny(contentType, blockedTypes)
+ && whitelist)) {
messages.add(new CommitValidationMessage(
"found blocked content type (" + contentType + ") in file: "
+ path, true));
diff --git a/src/main/java/com/googlesource/gerrit/plugins/uploadvalidator/DuplicatePathnameValidator.java b/src/main/java/com/googlesource/gerrit/plugins/uploadvalidator/DuplicatePathnameValidator.java
index 6eb0276..72ae551 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/uploadvalidator/DuplicatePathnameValidator.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/uploadvalidator/DuplicatePathnameValidator.java
@@ -88,9 +88,9 @@
};
}
- public static String KEY_REJECT_DUPLICATE_PATHNAMES =
+ public static final String KEY_REJECT_DUPLICATE_PATHNAMES =
"rejectDuplicatePathnames";
- public static String KEY_REJECT_DUPLICATE_PATHNAMES_LOCALE =
+ public static final String KEY_REJECT_DUPLICATE_PATHNAMES_LOCALE =
"rejectDuplicatePathnamesLocale";
@VisibleForTesting
diff --git a/src/main/java/com/googlesource/gerrit/plugins/uploadvalidator/FileExtensionValidator.java b/src/main/java/com/googlesource/gerrit/plugins/uploadvalidator/FileExtensionValidator.java
index b8d2ae3..79cac3f 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/uploadvalidator/FileExtensionValidator.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/uploadvalidator/FileExtensionValidator.java
@@ -59,7 +59,8 @@
};
}
- public static String KEY_BLOCKED_FILE_EXTENSION = "blockedFileExtension";
+ public static final String KEY_BLOCKED_FILE_EXTENSION =
+ "blockedFileExtension";
private final String pluginName;
private final PluginConfigFactory cfgFactory;
diff --git a/src/main/java/com/googlesource/gerrit/plugins/uploadvalidator/FooterValidator.java b/src/main/java/com/googlesource/gerrit/plugins/uploadvalidator/FooterValidator.java
index 6127cbe..f4c5810 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/uploadvalidator/FooterValidator.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/uploadvalidator/FooterValidator.java
@@ -58,7 +58,7 @@
};
}
- public static String KEY_REQUIRED_FOOTER = "requiredFooter";
+ public static final String KEY_REQUIRED_FOOTER = "requiredFooter";
private final String pluginName;
private final PluginConfigFactory cfgFactory;
diff --git a/src/main/java/com/googlesource/gerrit/plugins/uploadvalidator/InvalidFilenameValidator.java b/src/main/java/com/googlesource/gerrit/plugins/uploadvalidator/InvalidFilenameValidator.java
index e347ca5..e2fd516 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/uploadvalidator/InvalidFilenameValidator.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/uploadvalidator/InvalidFilenameValidator.java
@@ -59,8 +59,9 @@
};
}
- public static String KEY_INVALID_FILENAME = "invalidFilename";
- public static String KEY_INVALID_FILENAME_PATTERN = KEY_INVALID_FILENAME + "Pattern";
+ public static final String KEY_INVALID_FILENAME = "invalidFilename";
+ public static final String KEY_INVALID_FILENAME_PATTERN =
+ KEY_INVALID_FILENAME + "Pattern";
private final String pluginName;
private final PluginConfigFactory cfgFactory;
diff --git a/src/main/java/com/googlesource/gerrit/plugins/uploadvalidator/InvalidLineEndingValidator.java b/src/main/java/com/googlesource/gerrit/plugins/uploadvalidator/InvalidLineEndingValidator.java
index 1d5868c..559b745 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/uploadvalidator/InvalidLineEndingValidator.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/uploadvalidator/InvalidLineEndingValidator.java
@@ -66,7 +66,7 @@
};
}
- public static String KEY_CHECK_REJECT_WINDOWS_LINE_ENDINGS =
+ public static final String KEY_CHECK_REJECT_WINDOWS_LINE_ENDINGS =
"rejectWindowsLineEndings";
private final String pluginName;
diff --git a/src/main/java/com/googlesource/gerrit/plugins/uploadvalidator/MaxPathLengthValidator.java b/src/main/java/com/googlesource/gerrit/plugins/uploadvalidator/MaxPathLengthValidator.java
index 9c2e612..53dc2e3 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/uploadvalidator/MaxPathLengthValidator.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/uploadvalidator/MaxPathLengthValidator.java
@@ -56,7 +56,7 @@
};
}
- public static String KEY_MAX_PATH_LENGTH = "maxPathLength";
+ public static final String KEY_MAX_PATH_LENGTH = "maxPathLength";
private final String pluginName;
private final PluginConfigFactory cfgFactory;
diff --git a/src/main/java/com/googlesource/gerrit/plugins/uploadvalidator/SubmoduleValidator.java b/src/main/java/com/googlesource/gerrit/plugins/uploadvalidator/SubmoduleValidator.java
index 5a24b59..5dd9ee5 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/uploadvalidator/SubmoduleValidator.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/uploadvalidator/SubmoduleValidator.java
@@ -58,7 +58,7 @@
};
}
- public static String KEY_CHECK_SUBMODULE = "rejectSubmodule";
+ public static final String KEY_CHECK_SUBMODULE = "rejectSubmodule";
private final String pluginName;
private final PluginConfigFactory cfgFactory;
diff --git a/src/main/java/com/googlesource/gerrit/plugins/uploadvalidator/SymlinkValidator.java b/src/main/java/com/googlesource/gerrit/plugins/uploadvalidator/SymlinkValidator.java
index eebd14c..572600c 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/uploadvalidator/SymlinkValidator.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/uploadvalidator/SymlinkValidator.java
@@ -59,7 +59,7 @@
};
}
- public static String KEY_CHECK_SYMLINK = "rejectSymlink";
+ public static final String KEY_CHECK_SYMLINK = "rejectSymlink";
private final String pluginName;
private final PluginConfigFactory cfgFactory;
diff --git a/src/test/java/com/googlesource/gerrit/plugins/uploadvalidator/BlockedKeywordValidatorTest.java b/src/test/java/com/googlesource/gerrit/plugins/uploadvalidator/BlockedKeywordValidatorTest.java
index 0a2722f..f201592 100644
--- a/src/test/java/com/googlesource/gerrit/plugins/uploadvalidator/BlockedKeywordValidatorTest.java
+++ b/src/test/java/com/googlesource/gerrit/plugins/uploadvalidator/BlockedKeywordValidatorTest.java
@@ -23,7 +23,6 @@
import com.google.gerrit.server.git.validators.CommitValidationMessage;
import org.eclipse.jgit.api.errors.GitAPIException;
-import org.eclipse.jgit.api.errors.NoFilepatternException;
import org.eclipse.jgit.revwalk.RevCommit;
import org.junit.Test;
@@ -46,8 +45,7 @@
.build();
}
- private RevCommit makeCommit()
- throws NoFilepatternException, IOException, GitAPIException {
+ private RevCommit makeCommit() throws IOException, GitAPIException {
Map<File, byte[]> files = new HashMap<>();
// invalid files
String content = "http://foo.bar.tld/?pw=myp4ssw0rdTefoobarstline2\n";
diff --git a/src/test/java/com/googlesource/gerrit/plugins/uploadvalidator/ContentTypeValidatorTest.java b/src/test/java/com/googlesource/gerrit/plugins/uploadvalidator/ContentTypeValidatorTest.java
index 7a509ce..edad751 100644
--- a/src/test/java/com/googlesource/gerrit/plugins/uploadvalidator/ContentTypeValidatorTest.java
+++ b/src/test/java/com/googlesource/gerrit/plugins/uploadvalidator/ContentTypeValidatorTest.java
@@ -21,7 +21,6 @@
import com.google.gerrit.server.git.validators.CommitValidationMessage;
import org.eclipse.jgit.api.errors.GitAPIException;
-import org.eclipse.jgit.api.errors.NoFilepatternException;
import org.eclipse.jgit.revwalk.RevCommit;
import org.junit.Before;
import org.junit.Test;
@@ -35,7 +34,7 @@
public class ContentTypeValidatorTest extends ValidatorTestCase {
- private static byte[] TEST_PDF = ("%PDF-1.4\n"
+ private static final byte[] TEST_PDF = ("%PDF-1.4\n"
+ "1 0 obj << /Type /Catalog /Outlines 2 0 R /Pages 3 0 R >>\n"
+ "endobj 2 0 obj << /Type /Outlines /Count 0 >>\n"
+ "endobj 3 0 obj << /Type /Pages /Kids [4 0 R] /Count 1\n"
@@ -90,8 +89,7 @@
assertThat(ContentTypeValidator.isWhitelist(EMPTY_PLUGIN_CONFIG)).isFalse();
}
- private RevCommit makeCommit()
- throws NoFilepatternException, IOException, GitAPIException {
+ private RevCommit makeCommit() throws IOException, GitAPIException {
Map<File, byte[]> files = new HashMap<>();
String content = "<?xml version=\"1.0\"?><a><b>c</b></a>";
diff --git a/src/test/java/com/googlesource/gerrit/plugins/uploadvalidator/DuplicatePathnameValidatorTest.java b/src/test/java/com/googlesource/gerrit/plugins/uploadvalidator/DuplicatePathnameValidatorTest.java
index 5ebb53f..2461bf6 100644
--- a/src/test/java/com/googlesource/gerrit/plugins/uploadvalidator/DuplicatePathnameValidatorTest.java
+++ b/src/test/java/com/googlesource/gerrit/plugins/uploadvalidator/DuplicatePathnameValidatorTest.java
@@ -43,14 +43,16 @@
import java.util.Set;
public class DuplicatePathnameValidatorTest extends ValidatorTestCase {
- private static final List<String> INITIAL_PATHNAMES = ImmutableList.of(
- "a" , "ab",
- "f1/a", "f1/ab",
- "f2/a", "f2/ab", "f2/sF1/a", "f2/sF1/ab");
+ private static final ImmutableList<String> INITIAL_PATHNAMES =
+ ImmutableList.of(
+ "a" , "ab",
+ "f1/a", "f1/ab",
+ "f2/a", "f2/ab", "f2/sF1/a", "f2/sF1/ab");
+
+ private final List<String> vistedPaths = Lists.newArrayList();
+ private final List<CommitValidationMessage> messages = Lists.newArrayList();
private TestRepository<Repository> testRepo;
- private List<String> vistedPaths = Lists.newArrayList();
- private List<CommitValidationMessage> messages = Lists.newArrayList();
private Set<String> changedPaths;
private DuplicatePathnameValidator validator;
@@ -82,8 +84,8 @@
runCheck(INITIAL_PATHNAMES, changedPaths, messages, vistedPaths);
assertThat(transformMessages(messages))
.containsExactly(transformMessage(conflict("f1/A", "f1/a")));
- assertThat(vistedPaths).containsExactlyElementsIn(ImmutableList.of("a",
- "ab", "f1", "f1/a", "f1/ab", "f2"));
+ assertThat(vistedPaths).containsExactly(
+ "a", "ab", "f1", "f1/a", "f1/ab", "f2");
}
@Test
@@ -92,8 +94,7 @@
runCheck(INITIAL_PATHNAMES, changedPaths, messages, vistedPaths);
assertThat(transformMessages(messages))
.containsExactly(transformMessage(conflict("F1", "f1")));
- assertThat(vistedPaths).containsExactlyElementsIn(
- ImmutableList.of("a", "ab", "f1", "f2"));
+ assertThat(vistedPaths).containsExactly("a", "ab", "f1", "f2");
}
@Test
@@ -103,8 +104,8 @@
assertThat(transformMessages(messages)).containsExactly(
transformMessage(conflict("F1", "f1")),
transformMessage(conflict("f2/sf1", "f2/sF1")));
- assertThat(vistedPaths).containsExactlyElementsIn(
- ImmutableList.of("a", "ab", "f1", "f2", "f2/a", "f2/ab", "f2/sF1"));
+ assertThat(vistedPaths).containsExactly(
+ "a", "ab", "f1", "f2", "f2/a", "f2/ab", "f2/sF1");
}
@Test
@@ -115,9 +116,8 @@
transformMessage(conflict("AB", "ab")),
transformMessage(conflict("f1/A", "f1/a")),
transformMessage(conflict("f2/Ab", "f2/ab")));
- assertThat(vistedPaths).containsExactlyElementsIn(
- ImmutableList.of("a", "ab", "f1", "f1/a", "f1/ab",
- "f2", "f2/a", "f2/ab", "f2/sF1"));
+ assertThat(vistedPaths).containsExactly(
+ "a", "ab", "f1", "f1/a", "f1/ab", "f2", "f2/a", "f2/ab", "f2/sF1");
}
@Test
@@ -125,8 +125,8 @@
changedPaths = Sets.newHashSet("a", "ab", "f1/ab");
runCheck(INITIAL_PATHNAMES, changedPaths, messages, vistedPaths);
assertThat(messages).isEmpty();
- assertThat(vistedPaths).containsExactlyElementsIn(ImmutableList.of("a",
- "ab", "f1", "f1/a", "f1/ab", "f2"));
+ assertThat(vistedPaths).containsExactly(
+ "a", "ab", "f1", "f1/a", "f1/ab", "f2");
}
@Test
diff --git a/src/test/java/com/googlesource/gerrit/plugins/uploadvalidator/FakeGroupMembership.java b/src/test/java/com/googlesource/gerrit/plugins/uploadvalidator/FakeGroupMembership.java
index 9edec40..102c6a4 100644
--- a/src/test/java/com/googlesource/gerrit/plugins/uploadvalidator/FakeGroupMembership.java
+++ b/src/test/java/com/googlesource/gerrit/plugins/uploadvalidator/FakeGroupMembership.java
@@ -17,7 +17,7 @@
import com.google.gerrit.reviewdb.client.AccountGroup.UUID;
import com.google.gerrit.server.account.GroupMembership;
-import java.util.Arrays;
+import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import java.util.stream.Collectors;
@@ -27,7 +27,7 @@
private final Set<String> memberOfGroup = new HashSet<>();
public FakeGroupMembership(String... memberOfGroup) {
- this.memberOfGroup.addAll(Arrays.asList(memberOfGroup));
+ Collections.addAll(this.memberOfGroup, memberOfGroup);
}
@Override
diff --git a/src/test/java/com/googlesource/gerrit/plugins/uploadvalidator/InvalidFilenameValidatorTest.java b/src/test/java/com/googlesource/gerrit/plugins/uploadvalidator/InvalidFilenameValidatorTest.java
index a278496..a620824 100644
--- a/src/test/java/com/googlesource/gerrit/plugins/uploadvalidator/InvalidFilenameValidatorTest.java
+++ b/src/test/java/com/googlesource/gerrit/plugins/uploadvalidator/InvalidFilenameValidatorTest.java
@@ -20,7 +20,6 @@
import com.google.gerrit.server.git.validators.CommitValidationMessage;
import org.eclipse.jgit.api.errors.GitAPIException;
-import org.eclipse.jgit.api.errors.NoFilepatternException;
import org.eclipse.jgit.revwalk.RevCommit;
import org.junit.Test;
@@ -31,7 +30,7 @@
import java.util.Set;
public class InvalidFilenameValidatorTest extends ValidatorTestCase {
- private Set<String> getInvalidFilenames() {
+ private static Set<String> getInvalidFilenames() {
Set<String> filenames = new HashSet<>();
filenames.add("test#");
filenames.add("test%");
@@ -43,8 +42,7 @@
return filenames;
}
- private RevCommit makeCommit()
- throws NoFilepatternException, IOException, GitAPIException {
+ private RevCommit makeCommit() throws IOException, GitAPIException {
Set<File> files = new HashSet<>();
for (String filenames : getInvalidFilenames()) {
files.add(new File(repo.getDirectory().getParent(), filenames));
diff --git a/src/test/java/com/googlesource/gerrit/plugins/uploadvalidator/InvalidLineEndingValidatorTest.java b/src/test/java/com/googlesource/gerrit/plugins/uploadvalidator/InvalidLineEndingValidatorTest.java
index 50981be..04f3e09 100644
--- a/src/test/java/com/googlesource/gerrit/plugins/uploadvalidator/InvalidLineEndingValidatorTest.java
+++ b/src/test/java/com/googlesource/gerrit/plugins/uploadvalidator/InvalidLineEndingValidatorTest.java
@@ -22,7 +22,6 @@
import com.google.gerrit.server.git.validators.CommitValidationMessage;
import org.eclipse.jgit.api.errors.GitAPIException;
-import org.eclipse.jgit.api.errors.NoFilepatternException;
import org.eclipse.jgit.revwalk.RevCommit;
import org.junit.Test;
@@ -34,8 +33,7 @@
import java.util.Map;
public class InvalidLineEndingValidatorTest extends ValidatorTestCase {
- private RevCommit makeCommit()
- throws NoFilepatternException, IOException, GitAPIException {
+ private RevCommit makeCommit() throws IOException, GitAPIException {
Map<File, byte[]> files = new HashMap<>();
// invalid line endings
String content = "Testline1\r\n"
@@ -62,9 +60,8 @@
new ContentTypeUtil(PATTERN_CACHE), null, null, null);
List<CommitValidationMessage> m = validator.performValidation(repo, c,
EMPTY_PLUGIN_CONFIG);
- assertThat(TestUtils.transformMessages(m))
- .containsExactlyElementsIn(ImmutableSet.of(
- "ERROR: found carriage return (CR) character in file: foo.txt"));
+ assertThat(TestUtils.transformMessages(m)).containsExactly(
+ "ERROR: found carriage return (CR) character in file: foo.txt");
}
@Test
diff --git a/src/test/java/com/googlesource/gerrit/plugins/uploadvalidator/ListVisitedPathsFilter.java b/src/test/java/com/googlesource/gerrit/plugins/uploadvalidator/ListVisitedPathsFilter.java
index b5672b0..23aa5a4 100644
--- a/src/test/java/com/googlesource/gerrit/plugins/uploadvalidator/ListVisitedPathsFilter.java
+++ b/src/test/java/com/googlesource/gerrit/plugins/uploadvalidator/ListVisitedPathsFilter.java
@@ -14,8 +14,6 @@
package com.googlesource.gerrit.plugins.uploadvalidator;
-import org.eclipse.jgit.errors.IncorrectObjectTypeException;
-import org.eclipse.jgit.errors.MissingObjectException;
import org.eclipse.jgit.treewalk.TreeWalk;
import org.eclipse.jgit.treewalk.filter.TreeFilter;
@@ -31,8 +29,7 @@
}
@Override
- public boolean include(TreeWalk walker)
- throws MissingObjectException, IncorrectObjectTypeException, IOException {
+ public boolean include(TreeWalk walker) throws IOException {
visitedPaths.add(walker.getPathString());
return true;
}
diff --git a/src/test/java/com/googlesource/gerrit/plugins/uploadvalidator/MaxPathLengthValidatorTest.java b/src/test/java/com/googlesource/gerrit/plugins/uploadvalidator/MaxPathLengthValidatorTest.java
index c9b98f8..4ce9dba 100644
--- a/src/test/java/com/googlesource/gerrit/plugins/uploadvalidator/MaxPathLengthValidatorTest.java
+++ b/src/test/java/com/googlesource/gerrit/plugins/uploadvalidator/MaxPathLengthValidatorTest.java
@@ -22,7 +22,6 @@
import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.api.errors.GitAPIException;
-import org.eclipse.jgit.api.errors.NoFilepatternException;
import org.eclipse.jgit.revwalk.RevCommit;
import org.junit.Test;
@@ -40,8 +39,7 @@
return (TOO_LONG.length() + GOOD.length()) / 2;
}
- private RevCommit makeCommit()
- throws NoFilepatternException, IOException, GitAPIException {
+ private RevCommit makeCommit() throws IOException, GitAPIException {
Set<File> files = new HashSet<>();
files.add(TestUtils.createEmptyFile(TOO_LONG, repo));
files.add(TestUtils.createEmptyFile(GOOD, repo));
diff --git a/src/test/java/com/googlesource/gerrit/plugins/uploadvalidator/RefAwareValidatorConfigTest.java b/src/test/java/com/googlesource/gerrit/plugins/uploadvalidator/RefAwareValidatorConfigTest.java
index 80b78ea..111b16b 100644
--- a/src/test/java/com/googlesource/gerrit/plugins/uploadvalidator/RefAwareValidatorConfigTest.java
+++ b/src/test/java/com/googlesource/gerrit/plugins/uploadvalidator/RefAwareValidatorConfigTest.java
@@ -23,8 +23,9 @@
import org.junit.Test;
public class RefAwareValidatorConfigTest {
- private Project.NameKey projectName = new Project.NameKey("testProject");
- private IdentifiedUser anyUser = new FakeUserProvider().get();
+ private final Project.NameKey projectName =
+ new Project.NameKey("testProject");
+ private final IdentifiedUser anyUser = new FakeUserProvider().get();
@Test
public void isEnabledForAllRefsByDefault() throws Exception {
diff --git a/src/test/java/com/googlesource/gerrit/plugins/uploadvalidator/SkipValidationTest.java b/src/test/java/com/googlesource/gerrit/plugins/uploadvalidator/SkipValidationTest.java
index 6a8fda1..9fbb1cb 100644
--- a/src/test/java/com/googlesource/gerrit/plugins/uploadvalidator/SkipValidationTest.java
+++ b/src/test/java/com/googlesource/gerrit/plugins/uploadvalidator/SkipValidationTest.java
@@ -23,8 +23,9 @@
import org.junit.Test;
public class SkipValidationTest {
- private Project.NameKey projectName = new Project.NameKey("testProject");
- private IdentifiedUser anyUser = new FakeUserProvider().get();
+ private final Project.NameKey projectName =
+ new Project.NameKey("testProject");
+ private final IdentifiedUser anyUser = new FakeUserProvider().get();
@Test
public void dontSkipByDefault() throws Exception {
diff --git a/src/test/java/com/googlesource/gerrit/plugins/uploadvalidator/SubmoduleValidatorTest.java b/src/test/java/com/googlesource/gerrit/plugins/uploadvalidator/SubmoduleValidatorTest.java
index bb14073..5019764 100644
--- a/src/test/java/com/googlesource/gerrit/plugins/uploadvalidator/SubmoduleValidatorTest.java
+++ b/src/test/java/com/googlesource/gerrit/plugins/uploadvalidator/SubmoduleValidatorTest.java
@@ -23,7 +23,6 @@
import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.api.SubmoduleAddCommand;
import org.eclipse.jgit.api.errors.GitAPIException;
-import org.eclipse.jgit.api.errors.NoFilepatternException;
import org.eclipse.jgit.revwalk.RevCommit;
import org.junit.Test;
@@ -35,7 +34,7 @@
public class SubmoduleValidatorTest extends ValidatorTestCase {
private RevCommit makeCommitWithSubmodule()
- throws NoFilepatternException, IOException, GitAPIException {
+ throws IOException, GitAPIException {
try (Git git = new Git(repo)) {
SubmoduleAddCommand addCommand = git.submoduleAdd();
addCommand.setURI(repo.getDirectory().getCanonicalPath());
@@ -52,12 +51,11 @@
List<CommitValidationMessage> m =
SubmoduleValidator.performValidation(repo, c);
assertThat(TestUtils.transformMessages(m))
- .containsExactlyElementsIn(ImmutableSet.of(
- "ERROR: submodules are not allowed: modules/library"));
+ .containsExactly("ERROR: submodules are not allowed: modules/library");
}
private RevCommit makeCommitWithoutSubmodule()
- throws NoFilepatternException, IOException, GitAPIException {
+ throws IOException, GitAPIException {
Map<File, byte[]> files = new HashMap<>();
files.put(new File(repo.getDirectory().getParent(), "foo.txt"), null);
return TestUtils.makeCommit(repo, "Commit with empty test files.", files);
diff --git a/src/test/java/com/googlesource/gerrit/plugins/uploadvalidator/SymlinkValidatorTest.java b/src/test/java/com/googlesource/gerrit/plugins/uploadvalidator/SymlinkValidatorTest.java
index 9529a0b..a4c2127 100644
--- a/src/test/java/com/googlesource/gerrit/plugins/uploadvalidator/SymlinkValidatorTest.java
+++ b/src/test/java/com/googlesource/gerrit/plugins/uploadvalidator/SymlinkValidatorTest.java
@@ -21,7 +21,6 @@
import com.google.gerrit.server.git.validators.CommitValidationMessage;
import org.eclipse.jgit.api.errors.GitAPIException;
-import org.eclipse.jgit.api.errors.NoFilepatternException;
import org.eclipse.jgit.revwalk.RevCommit;
import org.junit.Test;
@@ -36,7 +35,7 @@
public class SymlinkValidatorTest extends ValidatorTestCase {
private RevCommit makeCommitWithSymlink()
- throws NoFilepatternException, IOException, GitAPIException {
+ throws IOException, GitAPIException {
Map<File, byte[]> files = new HashMap<>();
File link = new File(repo.getDirectory().getParent(), "foo.txt");
Files.createSymbolicLink(link.toPath(), Paths.get("bar.txt"));
@@ -62,7 +61,7 @@
}
private RevCommit makeCommitWithoutSymlink()
- throws NoFilepatternException, IOException, GitAPIException {
+ throws IOException, GitAPIException {
Map<File, byte[]> files = new HashMap<>();
files.put(new File(repo.getDirectory().getParent(), "foo.txt"), null);
return TestUtils.makeCommit(repo, "Commit with empty test files.", files);
diff --git a/src/test/java/com/googlesource/gerrit/plugins/uploadvalidator/TestUtils.java b/src/test/java/com/googlesource/gerrit/plugins/uploadvalidator/TestUtils.java
index 0f102fa..ab17832 100644
--- a/src/test/java/com/googlesource/gerrit/plugins/uploadvalidator/TestUtils.java
+++ b/src/test/java/com/googlesource/gerrit/plugins/uploadvalidator/TestUtils.java
@@ -27,7 +27,6 @@
import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.api.RmCommand;
import org.eclipse.jgit.api.errors.GitAPIException;
-import org.eclipse.jgit.api.errors.NoFilepatternException;
import org.eclipse.jgit.dircache.DirCacheEntry;
import org.eclipse.jgit.junit.TestRepository;
import org.eclipse.jgit.lib.Config;
@@ -71,8 +70,7 @@
}
public static RevCommit makeCommit(Repository repo, String message,
- Set<File> files)
- throws IOException, NoFilepatternException, GitAPIException {
+ Set<File> files) throws IOException, GitAPIException {
Map<File, byte[]> tmp = new HashMap<>();
for (File f : files) {
tmp.put(f, null);
@@ -81,8 +79,7 @@
}
public static RevCommit makeCommit(Repository repo, String message,
- Map<File, byte[]> files)
- throws IOException, NoFilepatternException, GitAPIException {
+ Map<File, byte[]> files) throws IOException, GitAPIException {
try (Git git = new Git(repo)) {
if (files != null) {
addFiles(git, files);
@@ -98,7 +95,7 @@
}
public static void removeFiles(Git git, Set<File> files)
- throws NoFilepatternException, GitAPIException {
+ throws GitAPIException {
RmCommand rmc = git.rm();
for (File f : files) {
rmc.addFilepattern(generateFilePattern(f, git));
@@ -107,7 +104,7 @@
}
private static void addFiles(Git git, Map<File, byte[]> files)
- throws IOException, NoFilepatternException, GitAPIException {
+ throws IOException, GitAPIException {
AddCommand ac = git.add();
for (File f : files.keySet()) {
if (!f.exists()) {