Create test for event priorities

This commit is contained in:
Dabo Ross 2013-09-05 21:40:28 -07:00 committed by md_5
parent 024288e587
commit 07e330b005
2 changed files with 60 additions and 1 deletions

View File

@ -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
{
}
}