Merge branch 'stable-3.2'

* stable-3.2:
  Remove white-box testing of exceptions in Cache<?,?>
  Remove unused Flogger instance
  Rename setUp to setupTestRepo because of implicit override
  Replace the deprecated RefDatabase.getRef with findRef
  MultiSiteRefUpdateTest: remove redundant IOException
  Do not mock Cache<?,?>
  Format build file with buildifier
  Remove unused wiremock dependency

Change-Id: I88e2c059be25a05dc2ed4d1486ee15e96f5546a2
diff --git a/BUILD b/BUILD
index ec555d5..0284dc6 100644
--- a/BUILD
+++ b/BUILD
@@ -17,9 +17,9 @@
     ],
     resources = glob(["src/main/resources/**/*"]),
     deps = [
-        "@global-refdb//jar",
-        "@events-broker//jar",
         ":replication-neverlink",
+        "@events-broker//jar",
+        "@global-refdb//jar",
     ],
 )
 
@@ -48,7 +48,6 @@
     visibility = ["//visibility:public"],
     exports = PLUGIN_DEPS + PLUGIN_TEST_DEPS + [
         ":multi-site__plugin",
-        "@wiremock//jar",
         "@global-refdb//jar",
         "@events-broker//jar",
         "//plugins/replication",
diff --git a/external_plugin_deps.bzl b/external_plugin_deps.bzl
index 30bfbc1..fee8aca 100644
--- a/external_plugin_deps.bzl
+++ b/external_plugin_deps.bzl
@@ -2,15 +2,9 @@
 
 def external_plugin_deps():
     maven_jar(
-        name = "wiremock",
-        artifact = "com.github.tomakehurst:wiremock-standalone:2.23.2",
-        sha1 = "4a920d6c04fd2444c7bc94880adc8313f5b31ba3",
-    )
-
-    maven_jar(
         name = "global-refdb",
         artifact = "com.gerritforge:global-refdb:3.1.2",
-        sha1 = "6ddee3de0f3fe9254453118ae1eca481ec03e957"
+        sha1 = "6ddee3de0f3fe9254453118ae1eca481ec03e957",
     )
 
     maven_jar(
diff --git a/src/main/java/com/googlesource/gerrit/plugins/multisite/validation/RefUpdateValidator.java b/src/main/java/com/googlesource/gerrit/plugins/multisite/validation/RefUpdateValidator.java
index dcc9030..89c6792 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/multisite/validation/RefUpdateValidator.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/multisite/validation/RefUpdateValidator.java
@@ -244,7 +244,7 @@
   }
 
   protected Ref getCurrentRef(String refName) throws IOException {
-    return MoreObjects.firstNonNull(refDb.getRef(refName), nullRef(refName));
+    return MoreObjects.firstNonNull(refDb.findRef(refName), nullRef(refName));
   }
 
   public static class CloseableSet<T extends AutoCloseable> implements AutoCloseable {
diff --git a/src/main/java/com/googlesource/gerrit/plugins/multisite/validation/ValidationModule.java b/src/main/java/com/googlesource/gerrit/plugins/multisite/validation/ValidationModule.java
index 481d288..4a34b7a 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/multisite/validation/ValidationModule.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/multisite/validation/ValidationModule.java
@@ -14,7 +14,6 @@
 
 package com.googlesource.gerrit.plugins.multisite.validation;
 
-import com.google.common.flogger.FluentLogger;
 import com.google.gerrit.extensions.config.FactoryModule;
 import com.google.gerrit.extensions.registration.DynamicItem;
 import com.google.gerrit.server.git.GitRepositoryManager;
@@ -33,8 +32,6 @@
 import com.googlesource.gerrit.plugins.replication.ReplicationPushFilter;
 
 public class ValidationModule extends FactoryModule {
-  private static final FluentLogger logger = FluentLogger.forEnclosingClass();
-
   private final Configuration cfg;
 
   public ValidationModule(Configuration cfg) {
diff --git a/src/test/java/com/googlesource/gerrit/plugins/multisite/forwarder/ForwardedCacheEvictionHandlerTest.java b/src/test/java/com/googlesource/gerrit/plugins/multisite/forwarder/ForwardedCacheEvictionHandlerTest.java
index 747da79..90ae8da 100644
--- a/src/test/java/com/googlesource/gerrit/plugins/multisite/forwarder/ForwardedCacheEvictionHandlerTest.java
+++ b/src/test/java/com/googlesource/gerrit/plugins/multisite/forwarder/ForwardedCacheEvictionHandlerTest.java
@@ -15,11 +15,10 @@
 package com.googlesource.gerrit.plugins.multisite.forwarder;
 
 import static com.google.common.truth.Truth.assertThat;
-import static org.mockito.Mockito.doAnswer;
 import static org.mockito.Mockito.doReturn;
-import static org.mockito.Mockito.verify;
 
 import com.google.common.cache.Cache;
+import com.google.common.cache.CacheBuilder;
 import com.google.gerrit.entities.Account;
 import com.google.gerrit.extensions.registration.DynamicMap;
 import com.googlesource.gerrit.plugins.multisite.cache.Constants;
@@ -30,19 +29,19 @@
 import org.junit.runner.RunWith;
 import org.mockito.Mock;
 import org.mockito.junit.MockitoJUnitRunner;
-import org.mockito.stubbing.Answer;
 
 @RunWith(MockitoJUnitRunner.class)
 public class ForwardedCacheEvictionHandlerTest {
 
   @Rule public ExpectedException exception = ExpectedException.none();
   @Mock private DynamicMap<Cache<?, ?>> cacheMapMock;
-  @Mock private Cache<?, ?> cacheMock;
+  private Cache<Object, Object> cacheUnderTest;
   private ForwardedCacheEvictionHandler handler;
 
   @Before
   public void setUp() throws Exception {
     handler = new ForwardedCacheEvictionHandler(cacheMapMock);
+    cacheUnderTest = CacheBuilder.newBuilder().build();
   }
 
   @Test
@@ -58,65 +57,22 @@
   @Test
   public void testSuccessfulCacheEviction() throws Exception {
     CacheEntry entry = new CacheEntry(Constants.GERRIT, Constants.ACCOUNTS, Account.id(123));
-    doReturn(cacheMock).when(cacheMapMock).get(entry.getPluginName(), entry.getCacheName());
+    cacheUnderTest.put(entry.getKey(), new Object());
+    doReturn(cacheUnderTest).when(cacheMapMock).get(entry.getPluginName(), entry.getCacheName());
 
     handler.evict(entry);
-    verify(cacheMock).invalidate(entry.getKey());
+    assertThat(cacheUnderTest.getIfPresent(entry.getKey())).isNull();
   }
 
   @Test
   public void testSuccessfulProjectListCacheEviction() throws Exception {
     CacheEntry entry = new CacheEntry(Constants.GERRIT, Constants.PROJECT_LIST, null);
-    doReturn(cacheMock).when(cacheMapMock).get(entry.getPluginName(), entry.getCacheName());
+    cacheUnderTest.put("foo", new Object());
+    cacheUnderTest.put("bar", new Object());
+    doReturn(cacheUnderTest).when(cacheMapMock).get(entry.getPluginName(), entry.getCacheName());
 
     handler.evict(entry);
-    verify(cacheMock).invalidateAll();
-  }
-
-  @Test
-  public void shouldSetAndUnsetForwardedContext() throws Exception {
-    CacheEntry entry = new CacheEntry(Constants.GERRIT, Constants.ACCOUNTS, Account.id(456));
-    doReturn(cacheMock).when(cacheMapMock).get(entry.getPluginName(), entry.getCacheName());
-
-    // this doAnswer is to allow to assert that context is set to forwarded
-    // while cache eviction is called.
-    doAnswer(
-            (Answer<Void>)
-                invocation -> {
-                  assertThat(Context.isForwardedEvent()).isTrue();
-                  return null;
-                })
-        .when(cacheMock)
-        .invalidate(entry.getKey());
-
-    assertThat(Context.isForwardedEvent()).isFalse();
-    handler.evict(entry);
-    assertThat(Context.isForwardedEvent()).isFalse();
-
-    verify(cacheMock).invalidate(entry.getKey());
-  }
-
-  @Test
-  public void shouldSetAndUnsetForwardedContextEvenIfExceptionIsThrown() throws Exception {
-    CacheEntry entry = new CacheEntry(Constants.GERRIT, Constants.ACCOUNTS, Account.id(789));
-    doReturn(cacheMock).when(cacheMapMock).get(entry.getPluginName(), entry.getCacheName());
-
-    doAnswer(
-            (Answer<Void>)
-                invocation -> {
-                  assertThat(Context.isForwardedEvent()).isTrue();
-                  throw new RuntimeException();
-                })
-        .when(cacheMock)
-        .invalidate(entry.getKey());
-
-    assertThat(Context.isForwardedEvent()).isFalse();
-    try {
-      handler.evict(entry);
-    } catch (RuntimeException e) {
-    }
-    assertThat(Context.isForwardedEvent()).isFalse();
-
-    verify(cacheMock).invalidate(entry.getKey());
+    assertThat(cacheUnderTest.getIfPresent("foo")).isNull();
+    assertThat(cacheUnderTest.getIfPresent("bar")).isNull();
   }
 }
diff --git a/src/test/java/com/googlesource/gerrit/plugins/multisite/validation/MultiSiteRefUpdateTest.java b/src/test/java/com/googlesource/gerrit/plugins/multisite/validation/MultiSiteRefUpdateTest.java
index 9e75c8f..d9e5c07 100644
--- a/src/test/java/com/googlesource/gerrit/plugins/multisite/validation/MultiSiteRefUpdateTest.java
+++ b/src/test/java/com/googlesource/gerrit/plugins/multisite/validation/MultiSiteRefUpdateTest.java
@@ -92,7 +92,7 @@
   }
 
   @Test
-  public void newUpdateShouldIncreaseRefUpdateFailureCountWhenFailing() throws IOException {
+  public void newUpdateShouldIncreaseRefUpdateFailureCountWhenFailing() {
 
     doReturn(false).when(sharedRefDb).isUpToDate(A_TEST_PROJECT_NAME_KEY, oldRef);
 
@@ -106,8 +106,7 @@
   }
 
   @Test
-  public void newUpdateShouldNotIncreaseSplitBrainPreventedCounterIfFailingSharedDbPostUpdate()
-      throws IOException {
+  public void newUpdateShouldNotIncreaseSplitBrainPreventedCounterIfFailingSharedDbPostUpdate() {
 
     doReturn(true).when(sharedRefDb).isUpToDate(A_TEST_PROJECT_NAME_KEY, oldRef);
     doReturn(false)
@@ -124,8 +123,7 @@
   }
 
   @Test
-  public void newUpdateShouldtIncreaseSplitBrainCounterIfFailingSharedDbPostUpdate()
-      throws IOException {
+  public void newUpdateShouldtIncreaseSplitBrainCounterIfFailingSharedDbPostUpdate() {
 
     doReturn(true).when(sharedRefDb).isUpToDate(A_TEST_PROJECT_NAME_KEY, oldRef);
     doReturn(false)
@@ -159,7 +157,7 @@
   }
 
   @Test
-  public void deleteShouldIncreaseRefUpdateFailureCountWhenFailing() throws IOException {
+  public void deleteShouldIncreaseRefUpdateFailureCountWhenFailing() {
 
     doReturn(false).when(sharedRefDb).isUpToDate(A_TEST_PROJECT_NAME_KEY, oldRef);
 
diff --git a/src/test/java/com/googlesource/gerrit/plugins/multisite/validation/RefUpdateValidatorTest.java b/src/test/java/com/googlesource/gerrit/plugins/multisite/validation/RefUpdateValidatorTest.java
index de93545..3f4d1bb 100644
--- a/src/test/java/com/googlesource/gerrit/plugins/multisite/validation/RefUpdateValidatorTest.java
+++ b/src/test/java/com/googlesource/gerrit/plugins/multisite/validation/RefUpdateValidatorTest.java
@@ -67,7 +67,7 @@
     newUpdateRef = newRef(refName, AN_OBJECT_ID_2);
     localRef = newRef(refName, AN_OBJECT_ID_3);
 
-    doReturn(localRef).when(localRefDb).getRef(refName);
+    doReturn(localRef).when(localRefDb).findRef(refName);
     doReturn(localRef).when(localRefDb).exactRef(refName);
     doReturn(oldUpdateRef).when(refUpdate).getRef();
     doReturn(newUpdateRef.getObjectId()).when(refUpdate).getNewObjectId();
@@ -118,7 +118,7 @@
     doReturn(true)
         .when(sharedRefDb)
         .compareAndPut(A_TEST_PROJECT_NAME_KEY, localRef, ObjectId.zeroId());
-    doReturn(localRef).doReturn(null).when(localRefDb).getRef(refName);
+    doReturn(localRef).doReturn(null).when(localRefDb).findRef(refName);
 
     Result result = refUpdateValidator.executeRefUpdate(refUpdate, () -> RefUpdate.Result.FORCED);
 
@@ -137,7 +137,7 @@
     doReturn(true)
         .when(sharedRefDb)
         .compareAndPut(A_TEST_PROJECT_NAME_KEY, localNullRef, newUpdateRef.getObjectId());
-    doReturn(localNullRef).doReturn(newUpdateRef).when(localRefDb).getRef(refName);
+    doReturn(localNullRef).doReturn(newUpdateRef).when(localRefDb).findRef(refName);
 
     Result result = refUpdateValidator.executeRefUpdate(refUpdate, () -> RefUpdate.Result.NEW);
 
diff --git a/src/test/java/com/googlesource/gerrit/plugins/multisite/validation/dfsrefdb/MultisiteReplicationPushFilterTest.java b/src/test/java/com/googlesource/gerrit/plugins/multisite/validation/dfsrefdb/MultisiteReplicationPushFilterTest.java
index 7e4593b..f2b57a1 100644
--- a/src/test/java/com/googlesource/gerrit/plugins/multisite/validation/dfsrefdb/MultisiteReplicationPushFilterTest.java
+++ b/src/test/java/com/googlesource/gerrit/plugins/multisite/validation/dfsrefdb/MultisiteReplicationPushFilterTest.java
@@ -68,7 +68,7 @@
   private TestRepository<InMemoryRepository> repo;
 
   @Before
-  public void setUp() throws Exception {
+  public void setupTestRepo() throws Exception {
     InMemoryRepository inMemoryRepo =
         gitRepositoryManager.createRepository(A_TEST_PROJECT_NAME_KEY);
     repo = new TestRepository<>(inMemoryRepo);