Skip to content

Instantly share code, notes, and snippets.

@tobyweston
Created November 18, 2011 16:31
Show Gist options
  • Save tobyweston/1376967 to your computer and use it in GitHub Desktop.
Save tobyweston/1376967 to your computer and use it in GitHub Desktop.
Is this how the Announcer is used?
package auctionsniper.util;
import org.jmock.Expectations;
import org.jmock.Mockery;
import org.jmock.integration.junit4.JMock;
import org.junit.Test;
import org.junit.runner.RunWith;
import java.util.EventListener;
@RunWith(JMock.class)
public class AnnouncerTest {
private final Mockery context = new Mockery();
private final ExampleListener listener = context.mock(ExampleListener.class);
private final Example example = new Example();
@Test
public void exampleShowingAnActionFiresEvent() {
context.checking(new Expectations() {{
one(listener).exampleEvent();
}});
example.addListener(listener);
example.exampleAction();
}
private interface ExampleListener extends EventListener {
public void exampleEvent();
}
private static class Example {
private final Announcer<ExampleListener> announcer = Announcer.to(ExampleListener.class);
public void addListener(ExampleListener listener) {
announcer.addListener(listener);
}
public void removeListener(ExampleListener listener) {
announcer.removeListener(listener);
}
public void exampleAction() {
// some old stuff
announcer.announce().exampleEvent();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment