Lock lifecycle transition matrix

This commit is contained in:
George
2026-06-07 13:33:49 +01:00
parent a46a945850
commit f1ceb5e019
@@ -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<String> 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());
}
}
}
}