Skip to content

Commit

Permalink
test(core): add a test for BoxEventManager
Browse files Browse the repository at this point in the history
  • Loading branch information
Siroshun09 committed Apr 11, 2024
1 parent fee9369 commit 48479c4
Showing 1 changed file with 41 additions and 0 deletions.
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.
}

0 comments on commit 48479c4

Please sign in to comment.