Bukkit-API  1.7.9-R0.2
The inofficial Bukkit-API
TimedRegisteredListenerTest.java
1 package org.bukkit.plugin;
2 
3 import static org.hamcrest.Matchers.*;
4 import static org.junit.Assert.*;
5 
6 import org.bukkit.event.Event;
9 import org.bukkit.event.Listener;
14 import org.junit.Test;
15 
17 
18  @Test
19  public void testEventClass() throws EventException {
20  Listener listener = new Listener() {};
21  EventExecutor executor = new EventExecutor() {
22  public void execute(Listener listener, Event event) {}
23  };
24  TestPlugin plugin = new TestPlugin("Test");
25 
26  PlayerInteractEvent interactEvent = new PlayerInteractEvent(null, null, null, null, null);
27  PlayerMoveEvent moveEvent = new PlayerMoveEvent(null, null, null);
28  BlockBreakEvent breakEvent = new BlockBreakEvent(null, null);
29 
30  TimedRegisteredListener trl = new TimedRegisteredListener(listener, executor, EventPriority.NORMAL, plugin, false);
31 
32  // Ensure that the correct event type is reported for a single event
33  trl.callEvent(interactEvent);
34  assertThat(trl.getEventClass(), is((Object) PlayerInteractEvent.class));
35  // Ensure that no superclass is used in lieu of the actual event, after two identical event types
36  trl.callEvent(interactEvent);
37  assertThat(trl.getEventClass(), is((Object) PlayerInteractEvent.class));
38  // Ensure that the closest superclass of the two events is chosen
39  trl.callEvent(moveEvent);
40  assertThat(trl.getEventClass(), is((Object) PlayerEvent.class));
41  // As above, so below
42  trl.callEvent(breakEvent);
43  assertThat(trl.getEventClass(), is((Object) Event.class));
44  // In the name of being thorough, check that it never travels down the hierarchy again.
45  trl.callEvent(breakEvent);
46  assertThat(trl.getEventClass(), is((Object) Event.class));
47 
48  trl = new TimedRegisteredListener(listener, executor, EventPriority.NORMAL, plugin, false);
49 
50  trl.callEvent(breakEvent);
51  assertThat(trl.getEventClass(), is((Object) BlockBreakEvent.class));
52  // Test moving up the class hierarchy by more than one class at a time
53  trl.callEvent(moveEvent);
54  assertThat(trl.getEventClass(), is((Object) Event.class));
55  }
56 }