Created
November 18, 2011 16:31
-
-
Save tobyweston/1376967 to your computer and use it in GitHub Desktop.
Is this how the Announcer is used?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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