-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(core): add a test for BoxEventManager
- Loading branch information
1 parent
fee9369
commit 48479c4
Showing
1 changed file
with
41 additions
and
0 deletions.
There are no files selected for viewing
41 changes: 41 additions & 0 deletions
41
core/src/test/java/net/okocraft/box/core/model/manager/event/BoxEventManagerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package net.okocraft.box.core.model.manager.event; | ||
|
||
import net.okocraft.box.api.event.BoxEvent; | ||
import net.okocraft.box.test.shared.scheduler.ScheduledTask; | ||
import net.okocraft.box.test.shared.scheduler.TestScheduler; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.time.Duration; | ||
import java.util.concurrent.CompletableFuture; | ||
|
||
class BoxEventManagerTest { | ||
|
||
@Test | ||
void testInitializeAsyncCaller() { | ||
var manager = BoxEventManager.create(); | ||
var event = new BoxEvent(); | ||
|
||
{ // Checks if the EventManager#callAsync can be called without BoxScheduler | ||
var future = new CompletableFuture<BoxEvent>(); | ||
manager.callAsync(event, future::complete); | ||
Assertions.assertSame(event, future.join()); | ||
} | ||
|
||
{ // Checks if it calls an event async by BoxScheduler | ||
var scheduler = new TestScheduler(true); | ||
manager.initializeAsyncEventCaller(scheduler); | ||
|
||
var future = new CompletableFuture<BoxEvent>(); | ||
manager.callAsync(event, future::complete); | ||
scheduler.checkTask(task -> { | ||
Assertions.assertEquals(task.delay(), Duration.ofSeconds(0)); | ||
Assertions.assertEquals(task.interval(), Duration.ofSeconds(0)); | ||
Assertions.assertEquals(task.type(), ScheduledTask.Type.ASYNC); | ||
}); | ||
Assertions.assertSame(event, future.join()); | ||
} | ||
} | ||
|
||
// Other methods are just delegating to EventServiceProvider. | ||
} |