From 834ac24b38c9af5b84bce428a48943d5a5838434 Mon Sep 17 00:00:00 2001 From: md_5 Date: Mon, 13 May 2013 18:36:12 +1000 Subject: [PATCH] Add EventBus test, which fails, now to fix! --- .../md_5/bungee/api/plugin/EventBusTest.java | 42 +++++++++++++++++++ pom.xml | 6 +++ 2 files changed, 48 insertions(+) create mode 100644 api/src/test/java/net/md_5/bungee/api/plugin/EventBusTest.java diff --git a/api/src/test/java/net/md_5/bungee/api/plugin/EventBusTest.java b/api/src/test/java/net/md_5/bungee/api/plugin/EventBusTest.java new file mode 100644 index 00000000..e7d1705c --- /dev/null +++ b/api/src/test/java/net/md_5/bungee/api/plugin/EventBusTest.java @@ -0,0 +1,42 @@ +package net.md_5.bungee.api.plugin; + +import com.google.common.eventbus.EventBus; +import com.google.common.eventbus.Subscribe; +import java.util.concurrent.CountDownLatch; +import org.junit.Assert; +import org.junit.Test; + +public class EventBusTest +{ + + private final EventBus bus = new EventBus(); + private final CountDownLatch latch = new CountDownLatch( 1 ); + + @Test + public void testNestedEvents() + { + bus.register( this ); + bus.post( new FirstEvent() ); + } + + @Subscribe + public void firstListener(FirstEvent event) + { + bus.post( new SecondEvent() ); + Assert.assertEquals( latch.getCount(), 0 ); + } + + @Subscribe + public void secondListener(SecondEvent event) + { + latch.countDown(); + } + + public static class FirstEvent extends Event + { + } + + public static class SecondEvent extends Event + { + } +} diff --git a/pom.xml b/pom.xml index 3b0df8dc..1ba8d95d 100644 --- a/pom.xml +++ b/pom.xml @@ -63,6 +63,12 @@ + + junit + junit + 4.11 + test + org.projectlombok lombok