Search in sources :

Example 1 with TestEvent

use of org.bukkit.event.TestEvent in project Bukkit by Bukkit.

the class PluginManagerTest method testSyncSameThread.

@Test
public void testSyncSameThread() {
    final Event event = new TestEvent(false);
    pm.callEvent(event);
}
Also used : TestEvent(org.bukkit.event.TestEvent) Event(org.bukkit.event.Event) TestEvent(org.bukkit.event.TestEvent) Test(org.junit.Test)

Example 2 with TestEvent

use of org.bukkit.event.TestEvent in project Bukkit by Bukkit.

the class PluginManagerTest method testSyncLocked.

@Test
public void testSyncLocked() throws InterruptedException {
    final Event event = new TestEvent(false);
    Thread secondThread = new Thread(new Runnable() {

        public void run() {
            try {
                synchronized (pm) {
                    pm.callEvent(event);
                }
            } catch (Throwable ex) {
                store.value = ex;
            }
        }
    });
    secondThread.start();
    secondThread.join();
    if (store.value != null) {
        throw new RuntimeException((Throwable) store.value);
    }
}
Also used : TestEvent(org.bukkit.event.TestEvent) Event(org.bukkit.event.Event) TestEvent(org.bukkit.event.TestEvent) Test(org.junit.Test)

Example 3 with TestEvent

use of org.bukkit.event.TestEvent in project Bukkit by Bukkit.

the class PluginManagerTest method testAsyncLocked.

@Test
public void testAsyncLocked() throws InterruptedException {
    final Event event = new TestEvent(true);
    Thread secondThread = new Thread(new Runnable() {

        public void run() {
            try {
                synchronized (pm) {
                    pm.callEvent(event);
                }
            } catch (Throwable ex) {
                store.value = ex;
            }
        }
    });
    secondThread.start();
    secondThread.join();
    assertThat(store.value, is(instanceOf(IllegalStateException.class)));
    assertThat(event.getEventName() + " cannot be triggered asynchronously from inside synchronized code.", is(((Throwable) store.value).getMessage()));
}
Also used : TestEvent(org.bukkit.event.TestEvent) Event(org.bukkit.event.Event) TestEvent(org.bukkit.event.TestEvent) Test(org.junit.Test)

Example 4 with TestEvent

use of org.bukkit.event.TestEvent in project Bukkit by Bukkit.

the class PluginManagerTest method testSyncUnlocked.

@Test
public void testSyncUnlocked() throws InterruptedException {
    final Event event = new TestEvent(false);
    Thread secondThread = new Thread(new Runnable() {

        public void run() {
            try {
                pm.callEvent(event);
            } catch (Throwable ex) {
                store.value = ex;
            }
        }
    });
    secondThread.start();
    secondThread.join();
    if (store.value != null) {
        throw new RuntimeException((Throwable) store.value);
    }
}
Also used : TestEvent(org.bukkit.event.TestEvent) Event(org.bukkit.event.Event) TestEvent(org.bukkit.event.TestEvent) Test(org.junit.Test)

Example 5 with TestEvent

use of org.bukkit.event.TestEvent in project Bukkit by Bukkit.

the class PluginManagerTest method testAsyncUnlocked.

@Test
public void testAsyncUnlocked() throws InterruptedException {
    final Event event = new TestEvent(true);
    Thread secondThread = new Thread(new Runnable() {

        public void run() {
            try {
                pm.callEvent(event);
            } catch (Throwable ex) {
                store.value = ex;
            }
        }
    });
    secondThread.start();
    secondThread.join();
    if (store.value != null) {
        throw new RuntimeException((Throwable) store.value);
    }
}
Also used : TestEvent(org.bukkit.event.TestEvent) Event(org.bukkit.event.Event) TestEvent(org.bukkit.event.TestEvent) Test(org.junit.Test)

Aggregations

Event (org.bukkit.event.Event)5 TestEvent (org.bukkit.event.TestEvent)5 Test (org.junit.Test)5