
com.cookingfox.eventbus.testable.TestableEventBus Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of eventbus-adapter-java Show documentation
Show all versions of eventbus-adapter-java Show documentation
The EventBus Adapter wraps various EventBus implementations for Java and Android.
package com.cookingfox.eventbus.testable;
import com.cookingfox.eventbus.EventBus;
import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.*;
/**
* Simple event bus implementation that makes testing event-based application flows easier.
* - Executes all events on the posting thread.
* - Supports both annotation- and name convention based subscriber methods.
* - Helper methods such as {@link #getFirstPostedEvent()} and {@link #getLastPostedEvent()}.
*/
public class TestableEventBus implements EventBus {
//----------------------------------------------------------------------------------------------
// ENUMS
//----------------------------------------------------------------------------------------------
/**
* Defines whether to use annotation or name convention based subscriber methods.
*/
public enum MODE {
/**
* Use annotation based subscriber methods. Annotations need to be added using
* {@link #addAnnotation(Class)} or {@link #addAnnotations(Collection)}.
*/
ANNOTATION,
/**
* Use method name convention based subscriber methods. Name conventions need to be added
* using {@link #addMethodName(String)}, {@link #addMethodNames(String[])} or
* {@link #addMethodNames(Collection)}.
*/
METHOD_NAME
}
//----------------------------------------------------------------------------------------------
// PROPERTIES
//----------------------------------------------------------------------------------------------
/**
* {@link EventListener} VOs ordered by their event type.
*/
private final Map> listenersByEventType = new LinkedHashMap<>();
/**
* The selected subscriber mode.
*/
private final MODE mode;
/**
* A log of all the posted events, which can be queried using helper methods.
*/
private final LinkedList postedEvents = new LinkedList<>();
/**
* All registered subjects, to avoid duplicate registration.
*/
private final Set
© 2015 - 2025 Weber Informatics LLC | Privacy Policy