PubSub { public void unsubscribe(@NonNull Subscriber<T> sub) { synchronized (subs) { if (!subs.remove(sub)) { Log.e(TAG, "Unexpected listener unsubscribed"); } } }  void post(T obj); void subscribe(@NonNull Subscriber<T> sub); void subscribeMain(@NonNull Subscriber<T> sub); void unsubscribe(@NonNull Subscriber<T> sub); void unsubscribeMain(@NonNull Subscriber<T> sub);  }
@Test public void unsubscribe() { final PubSub<String> events = new PubSub<>(); PubSub.Subscriber<String> listener = (msg) -> fail(); events.subscribe(listener); events.unsubscribe(listener); events.post("BASE"); }