Skip to content

Commit

Permalink
test: test event cancel
Browse files Browse the repository at this point in the history
  • Loading branch information
smartcmd committed May 18, 2024
1 parent c873b1c commit 027b1c8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ public abstract class Event {
private boolean cancelled = false;

public boolean isCancelled() {
if (!(this instanceof CancellableEvent)) {
throw new EventException("Event is not Cancellable");
}
return cancelled;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.allaymc.server.eventbus;

import org.allaymc.api.eventbus.EventBus;
import org.allaymc.api.eventbus.EventException;
import org.allaymc.api.eventbus.EventHandler;
import org.junit.jupiter.api.Test;

Expand Down Expand Up @@ -60,4 +61,10 @@ void testUnregister() {
assertFalse(event.isCancelled());
eventBus.registerListener(this);
}

@Test
void testCannotCancelNormalEvent() {
var event = new TestEvent();
assertThrows(EventException.class, () -> event.setCancelled(true));
}
}

0 comments on commit 027b1c8

Please sign in to comment.