From 07e330b00575e91a36c0d3c8fff83e15cbd1ad5e Mon Sep 17 00:00:00 2001 From: Dabo Ross Date: Thu, 5 Sep 2013 21:40:28 -0700 Subject: [PATCH] Create test for event priorities --- .../net/md_5/bungee/event/EventPriority.java | 2 +- .../md_5/bungee/event/EventPriorityTest.java | 59 +++++++++++++++++++ 2 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 event/src/test/java/net/md_5/bungee/event/EventPriorityTest.java diff --git a/event/src/main/java/net/md_5/bungee/event/EventPriority.java b/event/src/main/java/net/md_5/bungee/event/EventPriority.java index e21898d6..f8aac6a8 100644 --- a/event/src/main/java/net/md_5/bungee/event/EventPriority.java +++ b/event/src/main/java/net/md_5/bungee/event/EventPriority.java @@ -42,4 +42,4 @@ public enum EventPriority MONITOR( 5 ); @Getter private final int priority; -} \ No newline at end of file +} diff --git a/event/src/test/java/net/md_5/bungee/event/EventPriorityTest.java b/event/src/test/java/net/md_5/bungee/event/EventPriorityTest.java new file mode 100644 index 00000000..8dc3f5d9 --- /dev/null +++ b/event/src/test/java/net/md_5/bungee/event/EventPriorityTest.java @@ -0,0 +1,59 @@ +package net.md_5.bungee.event; + +import java.util.concurrent.CountDownLatch; +import org.junit.Assert; +import org.junit.Test; + +public class EventPriorityTest +{ + + private final EventBus bus = new EventBus(); + private final CountDownLatch latch = new CountDownLatch( 5 ); + + @Test + public void testPriority() + { + bus.register( this ); + bus.post( new PriorityTestEvent() ); + Assert.assertEquals( 0, latch.getCount() ); + } + + @EventHandler(priority = EventPriority.LOWEST) + public void onLowestPriority(PriorityTestEvent event) + { + Assert.assertEquals( latch.getCount(), 5 ); + latch.countDown(); + } + + @EventHandler(priority = EventPriority.LOW) + public void onLowPriority(PriorityTestEvent event) + { + Assert.assertEquals( latch.getCount(), 4 ); + latch.countDown(); + } + + @EventHandler + public void onNormalPriority(PriorityTestEvent event) + { + Assert.assertEquals( latch.getCount(), 3 ); + latch.countDown(); + } + + @EventHandler(priority = EventPriority.HIGH) + public void onHighPriority(PriorityTestEvent event) + { + Assert.assertEquals( 2, latch.getCount() ); + latch.countDown(); + } + + @EventHandler(priority = EventPriority.HIGHEST) + public void onHighestPriority(PriorityTestEvent event) + { + Assert.assertEquals( 1, latch.getCount() ); + latch.countDown(); + } + + public static class PriorityTestEvent + { + } +}