Switch FakeClock to use FeedObservable

PiperOrigin-RevId: 250762226
Change-Id: Ie63ad64c6bb5103ed232b56b7d8e021c580df945
diff --git a/src/main/java/com/google/android/libraries/feed/common/concurrent/testing/FakeMainThreadRunner.java b/src/main/java/com/google/android/libraries/feed/common/concurrent/testing/FakeMainThreadRunner.java
index 62e8ada..dfdc152 100644
--- a/src/main/java/com/google/android/libraries/feed/common/concurrent/testing/FakeMainThreadRunner.java
+++ b/src/main/java/com/google/android/libraries/feed/common/concurrent/testing/FakeMainThreadRunner.java
@@ -70,7 +70,7 @@
     this.fakeClock = fakeClock;
     this.fakeThreadUtils = fakeThreadUtils;
     this.shouldQueueTasks = shouldQueueTasks;
-    fakeClock.addClockUpdateListener(
+    fakeClock.registerObserver(
         (newCurrentTime, newElapsedRealtime) -> runTasksBefore(newElapsedRealtime));
   }
 
diff --git a/src/main/java/com/google/android/libraries/feed/common/feedobservable/ObservableNotifier.java b/src/main/java/com/google/android/libraries/feed/common/feedobservable/ObservableNotifier.java
index 9863f24..dfc1e97 100644
--- a/src/main/java/com/google/android/libraries/feed/common/feedobservable/ObservableNotifier.java
+++ b/src/main/java/com/google/android/libraries/feed/common/feedobservable/ObservableNotifier.java
@@ -17,7 +17,7 @@
 import com.google.android.libraries.feed.common.functional.Consumer;
 
 /** A FeedObservable implementation that allows calling a notify method on all observers. */
-public final class ObservableNotifier<ObserverT> extends FeedObservable<ObserverT> {
+public class ObservableNotifier<ObserverT> extends FeedObservable<ObserverT> {
 
   /** Calls all the registered listeners using the given listener method. */
   public void notifyListeners(Consumer<ObserverT> listenerMethod) {
diff --git a/src/main/java/com/google/android/libraries/feed/common/time/testing/BUILD b/src/main/java/com/google/android/libraries/feed/common/time/testing/BUILD
index 287a59c..4f2a10d 100644
--- a/src/main/java/com/google/android/libraries/feed/common/time/testing/BUILD
+++ b/src/main/java/com/google/android/libraries/feed/common/time/testing/BUILD
@@ -7,6 +7,7 @@
     testonly = 1,
     srcs = glob(["*.java"]),
     deps = [
+        "//src/main/java/com/google/android/libraries/feed/common/feedobservable",
         "//src/main/java/com/google/android/libraries/feed/common/logging",
         "//src/main/java/com/google/android/libraries/feed/common/time",
         "@maven//:com_google_truth_truth",
diff --git a/src/main/java/com/google/android/libraries/feed/common/time/testing/FakeClock.java b/src/main/java/com/google/android/libraries/feed/common/time/testing/FakeClock.java
index fd440af..5a6e4d0 100644
--- a/src/main/java/com/google/android/libraries/feed/common/time/testing/FakeClock.java
+++ b/src/main/java/com/google/android/libraries/feed/common/time/testing/FakeClock.java
@@ -16,16 +16,15 @@
 
 import static com.google.common.truth.Truth.assertThat;
 
+import com.google.android.libraries.feed.common.feedobservable.ObservableNotifier;
 import com.google.android.libraries.feed.common.logging.Logger;
 import com.google.android.libraries.feed.common.time.Clock;
-import java.util.HashSet;
-import java.util.Set;
+import com.google.android.libraries.feed.common.time.testing.FakeClock.ClockUpdateListener;
 
 /** Fake implementation of {@link Clock} for testing. */
-public class FakeClock implements Clock {
+public class FakeClock extends ObservableNotifier<ClockUpdateListener> implements Clock {
   private static final String TAG = "FakeClock";
 
-  private final Set<ClockUpdateListener> listeners;
   private long currentTime;
   private long elapsedRealtimeMs;
 
@@ -36,7 +35,6 @@
   public FakeClock(long currentTime, long elapsedRealtime) {
     this.currentTime = currentTime;
     elapsedRealtimeMs = elapsedRealtime;
-    this.listeners = new HashSet<>();
   }
 
   /**
@@ -94,13 +92,7 @@
   }
 
   private void onClockUpdated(long currentTime, long elapsedRealtime) {
-    for (ClockUpdateListener listener : listeners) {
-      listener.onClockUpdated(currentTime, elapsedRealtime);
-    }
-  }
-
-  public void addClockUpdateListener(ClockUpdateListener listener) {
-    listeners.add(listener);
+    notifyListeners(listener -> listener.onClockUpdated(currentTime, elapsedRealtime));
   }
 
   /** Listener for when the clock time is updated. */