Fix milestone 11 simulation flow

This commit is contained in:
George
2026-06-07 12:22:59 +01:00
parent 9f9b85e1f2
commit 3edc507af2
8 changed files with 463 additions and 5 deletions
@@ -3,6 +3,8 @@ package com.livingworld.events;
import static org.junit.jupiter.api.Assertions.*;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.ArrayList;
import java.util.List;
import org.junit.jupiter.api.Test;
@@ -122,6 +124,36 @@ public class LivingWorldEventBusTest {
assertEquals(2, bus.getPublishedEventCount());
}
@Test
void multipleEventsAtSameTickAreAllDelivered() {
LivingWorldEventBus bus = new LivingWorldEventBus();
List<String> delivered = new ArrayList<>();
bus.register("soil", event -> delivered.add(event.eventType()));
bus.register("water", event -> delivered.add(event.eventType()));
bus.publish(new BaseLivingWorldEvent("soil", 10L, "soil"));
bus.publish(new BaseLivingWorldEvent("water", 10L, "water"));
assertEquals(List.of("soil", "water"), delivered);
assertEquals(2, bus.getPublishedEventCount());
}
@Test
void recursivelyPublishedEventIsQueuedAndDelivered() {
LivingWorldEventBus bus = new LivingWorldEventBus();
List<String> delivered = new ArrayList<>();
bus.register("first", event -> {
delivered.add("first");
bus.publish(new BaseLivingWorldEvent("second", event.simulationTick(), "first"));
});
bus.register("second", event -> delivered.add("second"));
bus.publish(new BaseLivingWorldEvent("first", 10L, "test"));
assertEquals(List.of("first", "second"), delivered);
assertEquals(2, bus.getPublishedEventCount());
}
@Test
void getListenerCountReturnsCorrectNumberOfListeners() {
LivingWorldEventBus bus = new LivingWorldEventBus();
@@ -178,4 +210,4 @@ public class LivingWorldEventBusTest {
}
}
}
}
}