Convert PushResultProcessing to an interface

Instead of being an abstract class with methods that must be explicitly
overridden (even if they are no-op), convert it to an interface with
default empty methods. Also introduce a NO_OP instance. This allows to
have implementations that do nothing without having to explicitly add
all the boilerplate overrides.

Change-Id: I8a3cf6fc66f9a3857e5fa4949ca99c2c473702d6
diff --git a/src/main/java/com/googlesource/gerrit/plugins/replication/PushResultProcessing.java b/src/main/java/com/googlesource/gerrit/plugins/replication/PushResultProcessing.java
index ae0662d..39d361f 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/replication/PushResultProcessing.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/replication/PushResultProcessing.java
@@ -25,36 +25,54 @@
 import org.eclipse.jgit.transport.RemoteRefUpdate;
 import org.eclipse.jgit.transport.URIish;
 
-public abstract class PushResultProcessing {
+public interface PushResultProcessing {
+  public static final PushResultProcessing NO_OP = new PushResultProcessing() {};
 
-  abstract void onRefReplicatedToOneNode(
+  /**
+   * Invoked when a ref has been replicated to one node.
+   *
+   * @param project
+   * @param ref
+   * @param uri
+   * @param status
+   * @param refStatus
+   */
+  default void onRefReplicatedToOneNode(
       String project,
       String ref,
       URIish uri,
       RefPushResult status,
-      RemoteRefUpdate.Status refStatus);
+      RemoteRefUpdate.Status refStatus) {}
 
-  abstract void onRefReplicatedToAllNodes(String project, String ref, int nodesCount);
+  /**
+   * Invoked when a ref has been replicated to all nodes.
+   *
+   * @param project
+   * @param ref
+   * @param nodesCount
+   */
+  default void onRefReplicatedToAllNodes(String project, String ref, int nodesCount) {}
 
-  abstract void onAllRefsReplicatedToAllNodes(int totalPushTasksCount);
+  /**
+   * Invoked when all refs have been replicated to all nodes.
+   *
+   * @param totalPushTasksCount
+   */
+  default void onAllRefsReplicatedToAllNodes(int totalPushTasksCount) {}
 
   /**
    * Write message to standard out.
    *
    * @param message message text.
    */
-  void writeStdOut(String message) {
-    // Default doing nothing
-  }
+  default void writeStdOut(String message) {}
 
   /**
    * Write message to standard error.
    *
    * @param message message text.
    */
-  void writeStdErr(String message) {
-    // Default doing nothing
-  }
+  default void writeStdErr(String message) {}
 
   static String resolveNodeName(URIish uri) {
     StringBuilder sb = new StringBuilder();
@@ -70,7 +88,7 @@
     return sb.toString();
   }
 
-  public static class CommandProcessing extends PushResultProcessing {
+  public static class CommandProcessing implements PushResultProcessing {
     private WeakReference<StartCommand> sshCommand;
     private AtomicBoolean hasError = new AtomicBoolean();
 
@@ -79,7 +97,7 @@
     }
 
     @Override
-    void onRefReplicatedToOneNode(
+    public void onRefReplicatedToOneNode(
         String project,
         String ref,
         URIish uri,
@@ -115,7 +133,7 @@
     }
 
     @Override
-    void onRefReplicatedToAllNodes(String project, String ref, int nodesCount) {
+    public void onRefReplicatedToAllNodes(String project, String ref, int nodesCount) {
       StringBuilder sb = new StringBuilder();
       sb.append("Replication of ");
       sb.append(project);
@@ -128,7 +146,7 @@
     }
 
     @Override
-    void onAllRefsReplicatedToAllNodes(int totalPushTasksCount) {
+    public void onAllRefsReplicatedToAllNodes(int totalPushTasksCount) {
       if (totalPushTasksCount == 0) {
         return;
       }
@@ -141,7 +159,7 @@
     }
 
     @Override
-    void writeStdOut(String message) {
+    public void writeStdOut(String message) {
       StartCommand command = sshCommand.get();
       if (command != null) {
         command.writeStdOutSync(message);
@@ -149,7 +167,7 @@
     }
 
     @Override
-    void writeStdErr(String message) {
+    public void writeStdErr(String message) {
       StartCommand command = sshCommand.get();
       if (command != null) {
         command.writeStdErrSync(message);
@@ -157,7 +175,7 @@
     }
   }
 
-  public static class GitUpdateProcessing extends PushResultProcessing {
+  public static class GitUpdateProcessing implements PushResultProcessing {
     private static final FluentLogger logger = FluentLogger.forEnclosingClass();
 
     private final EventDispatcher dispatcher;
@@ -167,7 +185,7 @@
     }
 
     @Override
-    void onRefReplicatedToOneNode(
+    public void onRefReplicatedToOneNode(
         String project,
         String ref,
         URIish uri,
@@ -177,13 +195,10 @@
     }
 
     @Override
-    void onRefReplicatedToAllNodes(String project, String ref, int nodesCount) {
+    public void onRefReplicatedToAllNodes(String project, String ref, int nodesCount) {
       postEvent(new RefReplicationDoneEvent(project, ref, nodesCount));
     }
 
-    @Override
-    void onAllRefsReplicatedToAllNodes(int totalPushTasksCount) {}
-
     private void postEvent(RefEvent event) {
       try {
         dispatcher.postEvent(event);
diff --git a/src/test/java/com/googlesource/gerrit/plugins/replication/ReplicationIT.java b/src/test/java/com/googlesource/gerrit/plugins/replication/ReplicationIT.java
index 61a53f3..060150c 100644
--- a/src/test/java/com/googlesource/gerrit/plugins/replication/ReplicationIT.java
+++ b/src/test/java/com/googlesource/gerrit/plugins/replication/ReplicationIT.java
@@ -16,6 +16,7 @@
 
 import static com.google.common.truth.Truth.assertThat;
 import static com.google.gerrit.testing.GerritJUnit.assertThrows;
+import static com.googlesource.gerrit.plugins.replication.PushResultProcessing.NO_OP;
 import static java.util.stream.Collectors.toList;
 
 import com.google.common.flogger.FluentLogger;
@@ -46,8 +47,6 @@
 import org.eclipse.jgit.lib.Repository;
 import org.eclipse.jgit.revwalk.RevCommit;
 import org.eclipse.jgit.storage.file.FileBasedConfig;
-import org.eclipse.jgit.transport.RemoteRefUpdate;
-import org.eclipse.jgit.transport.URIish;
 import org.eclipse.jgit.util.FS;
 import org.junit.Test;
 
@@ -204,24 +203,6 @@
 
   @Test
   public void shouldCreateOneReplicationTaskWhenSchedulingRepoFullSync() throws Exception {
-    PushResultProcessing pushResultProcessing =
-        new PushResultProcessing() {
-
-          @Override
-          void onRefReplicatedToOneNode(
-              String project,
-              String ref,
-              URIish uri,
-              ReplicationState.RefPushResult status,
-              RemoteRefUpdate.Status refStatus) {}
-
-          @Override
-          void onRefReplicatedToAllNodes(String project, String ref, int nodesCount) {}
-
-          @Override
-          void onAllRefsReplicatedToAllNodes(int totalPushTasksCount) {}
-        };
-
     createTestProject("projectreplica");
 
     setReplicationDestination("foo", "replica", ALL_PROJECTS);
@@ -230,7 +211,7 @@
     plugin
         .getSysInjector()
         .getInstance(ReplicationQueue.class)
-        .scheduleFullSync(project, null, new ReplicationState(pushResultProcessing), true);
+        .scheduleFullSync(project, null, new ReplicationState(NO_OP), true);
 
     assertThat(listReplicationTasks(".*all.*")).hasSize(1);
   }