Skip to content

Instantly share code, notes, and snippets.

Last active August 29, 2015 14:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marlly/4750601a91181b96e32f to your computer and use it in GitHub Desktop.
Save marlly/4750601a91181b96e32f to your computer and use it in GitHub Desktop.
Example of annotation driven events using EventBus (Google Guava library)
import static org.mockito.Mockito.verify;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Spy;
import org.mockito.runners.MockitoJUnitRunner;
public class TestAnnotationDrivenEvent {
private final EventBus eventBus = new EventBus();
private final MessageRecievedEventConsumer listener = new MessageRecievedEventConsumer();
public void registerListener() {
public void fireEvent() {
Message msg = new Message("marlly", "Interface vs annotation driven events", "Post about differences between those event architectures");
MessageRecievedEvent msgEvent = new MessageRecievedEvent(msg);;
public class Message {
private final String sender;
private final String subject;
private final String text;
public Message(String sender, String subject, String text) {
this.sender = sender;
this.subject = subject;
this.text = text;
public String getSender() {
return sender;
public String getSubject() {
return subject;
public String getText() {
return text;
public class MessageRecievedEvent {
private final Message msg;
public MessageRecievedEvent(Message msg) {
this.msg = msg;
public Message getMsg() {
return msg;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class MessageRecievedEventConsumer {
private static final Logger LOG = LoggerFactory.getLogger(MessageRecievedEventConsumer.class);
public void messageRecieved(MessageRecievedEvent e) {"messageRecieved(), msg: {}", e.getMsg());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment