use of org.bukkit.event.Event 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()));
}
use of org.bukkit.event.Event 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);
}
}
use of org.bukkit.event.Event 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);
}
}
use of org.bukkit.event.Event 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);
}
}
use of org.bukkit.event.Event in project Glowstone by GlowstoneMC.
the class GlowPlayerTest method testGiveExp.
@Test
public void testGiveExp() {
entity.giveExp(20);
verify(eventFactory, times(2)).callEvent(argThat(input -> {
if (input instanceof PlayerExpChangeEvent) {
PlayerExpChangeEvent event = (PlayerExpChangeEvent) input;
assertEquals(20, event.getAmount());
return true;
} else if (input instanceof PlayerLevelChangeEvent) {
PlayerLevelChangeEvent event = (PlayerLevelChangeEvent) input;
assertSame(entity, event.getPlayer());
assertEquals(2, event.getNewLevel());
assertEquals(1, event.getOldLevel());
return true;
}
return false;
}));
assertEquals(2, entity.getLevel());
assertEquals(0.17, entity.getExp(), 0.1);
assertEquals(20, entity.getTotalExperience());
}
Aggregations