Bus { public <T> void post(T event) { if (event == null) { throw new NullPointerException("Event cannot be null"); } synchronized (listenerLock) { for (Map.Entry<Class, List<Subscription>> entry : currentThreadListeners.entrySet()) { checkAndPost(entry.getKey(), event, entry.getValue(), ThreadMode.CURRENT); } for (Map.Entry<Class, List<Subscription>> entry : mainThreadListeners.entrySet()) { checkAndPost(entry.getKey(), event, entry.getValue(), ThreadMode.MAIN); } for (Map.Entry<Class, List<Subscription>> entry : backgroundThreadListeners.entrySet()) { checkAndPost(entry.getKey(), event, entry.getValue(), ThreadMode.BACKGROUND); } } int counter = eventCounter.incrementAndGet(); log("EventCounter: " + counter); if (counter >= eventCleanupCount) { eventCounter.set(0); Observable.just(0) .subscribeOn(backgroundScheduler) .subscribe(new Consumer<Integer>() { @Override public void accept(Integer integer) { cleanupReferences(); } }); } } private  Bus(@NonNull Scheduler mainScheduler, @NonNull Scheduler currentScheduler, @NonNull Scheduler backgroundScheduler, int eventCleanupCount); @NonNull static Bus getDefault(); synchronized static void setDefault(@NonNull Bus bus); static void setDebug(boolean enable); void setRegistry(@Nullable Registry registry); void register(@NonNull T target); void register(@NonNull Subscription<? super T> subscription); void unregister(@NonNull T target); void post(T event); @Deprecated void postSticky(T event); @Deprecated boolean removeSticky(@NonNull Class<T> eventClass); @Nullable @Deprecated T getSticky(@NonNull Class<T> eventClass);  }
@Test public void testPost() { Bus bus = new Bus.Builder() .setMainScheduler(Schedulers.trampoline()) .setBackgroundScheduler(Schedulers.trampoline()) .setCurrentScheduler(Schedulers.trampoline()) .build(); String uid = UUID.randomUUID().toString(); setTestUid(uid); bus.register(subscriptionMain); bus.register(subscriptionBackground); bus.register(subscriptionCurrent); bus.post(new Foo(uid)); setTestUid(null); bus.unregister(subscriptionMain); bus.unregister(subscriptionBackground); bus.unregister(subscriptionCurrent); bus.post(new Foo("FAIL")); assertEquals(3, eventCount); }