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.register( new EventPriorityListenerPartner() );
        bus.post( new PriorityTestEvent() );
        Assert.assertEquals( 0, latch.getCount() );
    }

    @EventHandler(priority = Byte.MIN_VALUE)
    public void onMinPriority(PriorityTestEvent event)
    {
        Assert.assertEquals( 5, latch.getCount() );
        latch.countDown();
    }

    @EventHandler(priority = EventPriority.LOWEST)
    public void onLowestPriority(PriorityTestEvent event)
    {
        Assert.assertEquals( 4, latch.getCount() );
        latch.countDown();
    }

    @EventHandler
    public void onNormalPriority(PriorityTestEvent event)
    {
        Assert.assertEquals( 3, latch.getCount() );
        latch.countDown();
    }

    @EventHandler(priority = EventPriority.HIGHEST)
    public void onHighestPriority(PriorityTestEvent event)
    {
        Assert.assertEquals( 2, latch.getCount() );
        latch.countDown();
    }

    @EventHandler(priority = Byte.MAX_VALUE)
    public void onMaxPriority(PriorityTestEvent event)
    {
        Assert.assertEquals( 1, latch.getCount() );
        latch.countDown();
    }

    public static class PriorityTestEvent
    {
    }

    public class EventPriorityListenerPartner
    {

        @EventHandler(priority = EventPriority.HIGH)
        public void onHighPriority(PriorityTestEvent event)
        {
            Assert.assertEquals( 2, latch.getCount() );
            latch.countDown();
        }

        @EventHandler(priority = EventPriority.LOW)
        public void onLowPriority(PriorityTestEvent event)
        {
            Assert.assertEquals( 4, latch.getCount() );
            latch.countDown();
        }
    }
}

@@ -266,10 +266,9 @@
 ch( 
-5 
+7
 );%0A%0A
@@ -643,17 +643,17 @@
 Equals( 
-5
+7
 , latch.
@@ -836,33 +836,33 @@
 t.assertEquals( 
-4
+6
 , latch.getCount
@@ -1016,9 +1016,9 @@
 ls( 
-3
+4
 , la
@@ -1720,33 +1720,33 @@
 t.assertEquals( 
-2
+3
 , latch.getCount
@@ -1939,33 +1939,33 @@
 t.assertEquals( 
-4
+5
 , latch.getCount

Fix EventBus unit test.