From f1ceb5e0194d51056c75108b3b15409b014e5779 Mon Sep 17 00:00:00 2001 From: George Date: Sun, 7 Jun 2026 13:33:49 +0100 Subject: [PATCH] Lock lifecycle transition matrix --- .../RegionLifecycleControllerTest.java | 29 ++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/src/test/java/com/livingworld/regions/RegionLifecycleControllerTest.java b/src/test/java/com/livingworld/regions/RegionLifecycleControllerTest.java index 4887639..739cf9c 100644 --- a/src/test/java/com/livingworld/regions/RegionLifecycleControllerTest.java +++ b/src/test/java/com/livingworld/regions/RegionLifecycleControllerTest.java @@ -1,6 +1,7 @@ package com.livingworld.regions; import static org.junit.jupiter.api.Assertions.*; +import java.util.Set; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; @@ -10,6 +11,18 @@ import org.junit.jupiter.api.Test; */ class RegionLifecycleControllerTest { + private static final Set EXPECTED_TRANSITIONS = Set.of( + "UNLOADED->LOADING", + "LOADING->ACTIVE", + "LOADING->FAILED", + "ACTIVE->DIRTY", + "DIRTY->SAVING", + "SAVING->ACTIVE", + "SAVING->FAILED", + "ACTIVE->UNLOADING", + "UNLOADING->UNLOADED", + "FAILED->LOADING"); + // ------------------------------------------------------------------ // Allowed transitions // ------------------------------------------------------------------ @@ -18,6 +31,20 @@ class RegionLifecycleControllerTest { @DisplayName("Allowed transitions") class AllowedTransitions { + @Test + @DisplayName("complete transition matrix matches the lifecycle design") + void completeTransitionMatrixMatchesDesign() { + for (RegionLifecycleState from : RegionLifecycleState.values()) { + for (RegionLifecycleState to : RegionLifecycleState.values()) { + String transition = from.name() + "->" + to.name(); + assertEquals( + EXPECTED_TRANSITIONS.contains(transition), + RegionLifecycleController.canTransition(from, to), + transition); + } + } + } + @Test @DisplayName("UNLOADED -> LOADING is allowed") void unloadedToLoading() { @@ -305,4 +332,4 @@ class RegionLifecycleControllerTest { assertEquals(RegionLifecycleState.FAILED, region.getLifecycleState()); } } -} \ No newline at end of file +}