Various fixes for ErrorProne warnings
Add @FormatMethod/@FormatString in log wrappers
Add @RunWith(Junit4.class) to all tests
Use correct branches in test (the test was testing the wrong thing!)
Change-Id: Iaa17ba1f5c1618b87a2281d9bf4d4b93d617d56c
diff --git a/BUILD b/BUILD
index bca5173..1bcc32f 100644
--- a/BUILD
+++ b/BUILD
@@ -12,9 +12,10 @@
],
resources = glob(["java/Documentation/**/*.md"]),
deps = [
+ "@error-prone-annotations//jar",
+ "@istack-commons-runtime//jar",
"@jaxb-api//jar",
"@jaxb-runtime//jar",
- "@istack-commons-runtime//jar",
],
)
diff --git a/java/com/googlesource/gerrit/plugins/supermanifest/SuperManifestRefUpdatedListener.java b/java/com/googlesource/gerrit/plugins/supermanifest/SuperManifestRefUpdatedListener.java
index e8860fb..91ee090 100644
--- a/java/com/googlesource/gerrit/plugins/supermanifest/SuperManifestRefUpdatedListener.java
+++ b/java/com/googlesource/gerrit/plugins/supermanifest/SuperManifestRefUpdatedListener.java
@@ -18,6 +18,8 @@
import com.google.common.annotations.VisibleForTesting;
import com.google.common.flogger.FluentLogger;
+import com.google.errorprone.annotations.FormatMethod;
+import com.google.errorprone.annotations.FormatString;
import com.google.gerrit.entities.Project;
import com.google.gerrit.extensions.annotations.PluginName;
import com.google.gerrit.extensions.api.projects.BranchInput;
@@ -124,15 +126,18 @@
this.permissionBackend = permissionBackend;
}
- private void warn(String formatStr, Object... args) {
+ @FormatMethod
+ private void warn(@FormatString String formatStr, Object... args) {
logger.atWarning().log("%s: %s", canonicalWebUrl, String.format(formatStr, args));
}
- private void error(String formatStr, Object... args) {
+ @FormatMethod
+ private void error(@FormatString String formatStr, Object... args) {
logger.atSevere().log("%s: %s", canonicalWebUrl, String.format(formatStr, args));
}
- private void info(String formatStr, Object... args) {
+ @FormatMethod
+ private void info(@FormatString String formatStr, Object... args) {
logger.atInfo().log("%s: %s", canonicalWebUrl, String.format(formatStr, args));
}
diff --git a/javatests/com/googlesource/gerrit/plugins/supermanifest/ConfigEntryTest.java b/javatests/com/googlesource/gerrit/plugins/supermanifest/ConfigEntryTest.java
index dd7aae1..61391db 100644
--- a/javatests/com/googlesource/gerrit/plugins/supermanifest/ConfigEntryTest.java
+++ b/javatests/com/googlesource/gerrit/plugins/supermanifest/ConfigEntryTest.java
@@ -19,7 +19,10 @@
import org.eclipse.jgit.errors.ConfigInvalidException;
import org.eclipse.jgit.lib.Config;
import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+@RunWith(JUnit4.class)
public class ConfigEntryTest {
@Test
diff --git a/javatests/com/googlesource/gerrit/plugins/supermanifest/GerritRemoteReaderTest.java b/javatests/com/googlesource/gerrit/plugins/supermanifest/GerritRemoteReaderTest.java
index 4b4c832..c204f72 100644
--- a/javatests/com/googlesource/gerrit/plugins/supermanifest/GerritRemoteReaderTest.java
+++ b/javatests/com/googlesource/gerrit/plugins/supermanifest/GerritRemoteReaderTest.java
@@ -15,7 +15,10 @@
import org.eclipse.jgit.revwalk.RevCommit;
import org.junit.Before;
import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+@RunWith(JUnit4.class)
public class GerritRemoteReaderTest {
private static final String MASTER = "refs/heads/master";
diff --git a/javatests/com/googlesource/gerrit/plugins/supermanifest/GerritSuperManifestRepoManagerTest.java b/javatests/com/googlesource/gerrit/plugins/supermanifest/GerritSuperManifestRepoManagerTest.java
index 9dad5ea..61483c3 100644
--- a/javatests/com/googlesource/gerrit/plugins/supermanifest/GerritSuperManifestRepoManagerTest.java
+++ b/javatests/com/googlesource/gerrit/plugins/supermanifest/GerritSuperManifestRepoManagerTest.java
@@ -11,7 +11,10 @@
import org.eclipse.jgit.lib.Repository;
import org.junit.Before;
import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+@RunWith(JUnit4.class)
public class GerritSuperManifestRepoManagerTest {
private static final String CANONICAL_WEB_URL = "https://example.com/gerrit/";
diff --git a/javatests/com/googlesource/gerrit/plugins/supermanifest/RepoSuperManifestIT.java b/javatests/com/googlesource/gerrit/plugins/supermanifest/RepoSuperManifestIT.java
index aad0d4f..8f40cdc 100644
--- a/javatests/com/googlesource/gerrit/plugins/supermanifest/RepoSuperManifestIT.java
+++ b/javatests/com/googlesource/gerrit/plugins/supermanifest/RepoSuperManifestIT.java
@@ -618,10 +618,10 @@
// This branch should not exist
BranchApi branch3 = gApi.projects().name(superKey.get()).branch("refs/heads/src3");
- assertThrows(ResourceNotFoundException.class, () -> branch2.file("project1"));
+ assertThrows(ResourceNotFoundException.class, () -> branch3.file("project1"));
BranchApi branch4 = gApi.projects().name(superKey.get()).branch("refs/heads/src4");
- assertThat(branch1.file("project1").getContentType()).isEqualTo("x-git/gitlink; charset=UTF-8");
+ assertThat(branch4.file("project1").getContentType()).isEqualTo("x-git/gitlink; charset=UTF-8");
}
// TODO - should add tests for all the error handling in configuration parsing?
}