diff --git a/controls/src/main/java/state_machine/State/StateContainer.java b/controls/src/main/java/state_machine/State/StateContainer.java index 4288d24..f05cd97 100644 --- a/controls/src/main/java/state_machine/State/StateContainer.java +++ b/controls/src/main/java/state_machine/State/StateContainer.java @@ -3,4 +3,5 @@ public interface StateContainer { public StateInterface getState(); + } diff --git a/controls/src/test/java/SimpleEnumStateMachineTests.java b/controls/src/test/java/SimpleEnumStateMachineTests.java index f3e702e..57f8da9 100644 --- a/controls/src/test/java/SimpleEnumStateMachineTests.java +++ b/controls/src/test/java/SimpleEnumStateMachineTests.java @@ -1,11 +1,11 @@ package coppercore.controls.test; import static org.junit.jupiter.api.Assertions.assertEquals; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Test; import coppercore.controls.StateMachine; import coppercore.controls.StateMachineConfiguration; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; public class SimpleEnumStateMachineTests { diff --git a/controls/src/test/java/StateContainerStateMachineTests.java b/controls/src/test/java/StateContainerStateMachineTests.java index cdfa501..914109b 100644 --- a/controls/src/test/java/StateContainerStateMachineTests.java +++ b/controls/src/test/java/StateContainerStateMachineTests.java @@ -1,20 +1,43 @@ package coppercore.controls.test; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Test; - import coppercore.controls.PeriodicStateInterface; import coppercore.controls.StateContainer; import coppercore.controls.StateMachine; import coppercore.controls.StateMachineConfiguration; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + +import coppercore.controls.StateInterface; + public class StateContainerStateMachineTests { - static class IdleState implements PeriodicStateInterface {}; - static class ReadyState implements PeriodicStateInterface {}; - static class WaitingState implements PeriodicStateInterface {}; - static class DoneState implements PeriodicStateInterface {}; - static class ShutdownState implements PeriodicStateInterface {}; + static class IdleState implements PeriodicStateInterface { + public static void customOnEntry(Transition transition){ + + } + + public static void customOnExit(Transition transition){ + + } + + public static void customTransitionAction(Transition transition){ + + } + } + ; + + static class ReadyState implements PeriodicStateInterface {} + ; + + static class WaitingState implements PeriodicStateInterface {} + ; + + static class DoneState implements PeriodicStateInterface {} + ; + + static class ShutdownState implements PeriodicStateInterface {} + ; static enum testStateContainer implements StateContainer { IDLE(new IdleState()), @@ -24,11 +47,12 @@ static enum testStateContainer implements StateContainer { SHUTDOWN(new ShutdownState()); private final PeriodicStateInterface state; + testStateContainer(PeriodicStateInterface state) { this.state = state; } - - public PeriodicStateInterface getState(){ + + public PeriodicStateInterface getState() { return state; } } @@ -42,15 +66,36 @@ static enum testEnumTriggers { ERROR } - public static StateMachineConfiguration stateContainerTestMachineConfig; + public static StateMachineConfiguration + stateContainerTestMachineConfig; @BeforeAll public static void setup() { stateContainerTestMachineConfig = new StateMachineConfiguration<>(); + stateContainerTestMachineConfig + .configureDefaultTransitionAction((State state, Transition transition) -> state.onEntry(transition)); + .addTransitionAction((State state, Transition transition) -> state.onEntry(transition)); + + + //stateContainerTestMachineConfig + // .registerBlankParent(testStateContainer.SOME_PARENT_STATE); Not in first Implemenation + + //stateContainerTestMachineConfig + // .configure(testStateContainer.SOME_STATE); Not in first Implemenation + stateContainerTestMachineConfig .configure(testStateContainer.IDLE) - .permit(testEnumTriggers.PREPARE, testStateContainer.READY); + //.parentState(testStateContainer.SOME_STATE) Not in first Implemenation + .permit(testEnumTriggers.PREPARE, testStateContainer.READY) + .permitInternal(testEnumTriggers.PREPARE, testStateContainer.READY) + .addTransitionAction(testStateContainer.IDLE::customTransitionAction) + .disableDefaultTransitionAction() + .addOnEntryAction(testStateContainer.IDLE::customOnEntry) + .addOnExitAction(testStateContainer.IDLE::customOnExit) + .disableDefualtOnEntry() + .disableDefualtOnExit(); + stateContainerTestMachineConfig .configure(testStateContainer.READY) @@ -65,12 +110,19 @@ public static void setup() { .configure(testStateContainer.DONE) .permit(testEnumTriggers.PREPARE, testStateContainer.READY) .permit(testEnumTriggers.SHUTDOWN, testStateContainer.SHUTDOWN); + } @Test void stateMachineTransitionNoErrorTest() { StateMachine stateMachine = new StateMachine<>(stateContainerTestMachineConfig, testStateContainer.IDLE); + testStateContainer stateContainer = stateMachine.getCurrentState(); + //stateMachine.inState(testStateContainer.SOME_STATE); Not in first Implemenation //True + stateMachine.inState(testStateContainer.IDLE); //True + //stateMachine.inStateExactly(testStateContainer.SOME_STATE); Not in first Implemenation //False + //stateMachine.inState(testStateContainer.SOME_PARENT_STATE); Not in first Implemenation //False + stateContainer.getState().periodic(); } @Test