package com.example.tests;
import com.frotty27.hrtk.api.annotation.HytaleSuite;
import com.frotty27.hrtk.api.annotation.WorldTest;
import com.frotty27.hrtk.api.annotation.Tag;
import com.frotty27.hrtk.api.annotation.DisplayName;
import com.frotty27.hrtk.api.annotation.Order;
import com.frotty27.hrtk.api.assert_.HytaleAssert;
import com.frotty27.hrtk.api.assert_.SchedulingAssert;
import com.frotty27.hrtk.api.context.WorldTestContext;
import com.frotty27.hrtk.api.lifecycle.IsolationStrategy;
@HytaleSuite(value = "Scheduling Surface Tests", isolation = IsolationStrategy.DEDICATED_WORLD)
@Tag("scheduling")
public class SchedulingSurfaceTests {
@WorldTest
@Order(1)
@DisplayName("Test world is alive and running")
void worldIsAlive(WorldTestContext ctx) {
// assertWorldAlive checks that the world's isAlive() or isRunning() method
// returns true. A dead world cannot process ticks or scheduled tasks.
SchedulingAssert.assertWorldAlive(ctx.getWorld());
}
@WorldTest
@Order(2)
@DisplayName("Task can be dispatched to the world thread")
void dispatchTaskToWorldThread(WorldTestContext ctx) {
// executeOnWorldThread dispatches a Runnable onto the world's execution thread.
// Returns true if the dispatch succeeded.
boolean dispatched = SchedulingTestAdapter.executeOnWorldThread(
ctx.getWorld(),
() -> {
// This runs on the world thread, not the test thread.
// You can do world operations here safely.
}
);
HytaleAssert.assertTrue("Task should be dispatched successfully", dispatched);
}
@WorldTest
@Order(3)
@DisplayName("Scheduling API is available")
void schedulingApiAvailable(WorldTestContext ctx) {
// schedulingAvailable checks if the World class exposes an execute() method.
HytaleAssert.assertTrue(
"Scheduling API should be available",
SchedulingTestAdapter.schedulingAvailable()
);
}
}