From 99babc5b5a31baf795a59ebfa4fd97237622dbf3 Mon Sep 17 00:00:00 2001 From: Vyacheslav Boyko Date: Thu, 14 Jul 2022 13:57:22 +0300 Subject: [PATCH] if startingAt beforeHandler must not be called --- src/main/java/me/bvn13/fsm/Fsm.java | 1 - src/test/java/me/bvn13/fsm/tests/FsmTest.java | 8 ++++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/main/java/me/bvn13/fsm/Fsm.java b/src/main/java/me/bvn13/fsm/Fsm.java index 1253454..39b1a81 100644 --- a/src/main/java/me/bvn13/fsm/Fsm.java +++ b/src/main/java/me/bvn13/fsm/Fsm.java @@ -252,7 +252,6 @@ public class Fsm { throw new NotInitializedException(format("Unable to find state '%s'", name), e); } this.done = currentState.isFinish(); - this.currentState.beforeEvent(); } private void switchToNextState(E event) { diff --git a/src/test/java/me/bvn13/fsm/tests/FsmTest.java b/src/test/java/me/bvn13/fsm/tests/FsmTest.java index 963e62a..a02e733 100644 --- a/src/test/java/me/bvn13/fsm/tests/FsmTest.java +++ b/src/test/java/me/bvn13/fsm/tests/FsmTest.java @@ -149,7 +149,7 @@ public class FsmTest { .withAfterHandler(fsm -> initAfter.set(true)) .withProcessor((fsm, event) -> initProcess.set(true)) .end() - .state("intermediate-1") + .state("intermediate") .withBeforeHandler(fsm -> intermediateBefore.set(true)) .withAfterHandler(fsm -> intermediateAfter.set(true)) .withProcessor((fsm, event) -> intermediateProcess.set(true)) @@ -161,11 +161,11 @@ public class FsmTest { .end() .withTransition() .from("init") - .to("intermediate-1") + .to("intermediate") .checking((fsm, event) -> true) .end() .withTransition() - .from("intermediate-1") + .from("intermediate") .to("finish") .checking((fsm, event) -> true) .end() @@ -180,7 +180,7 @@ public class FsmTest { Assert.assertFalse(initBefore.get()); Assert.assertFalse(initProcess.get()); Assert.assertFalse(initAfter.get()); - Assert.assertTrue(intermediateBefore.get()); + Assert.assertFalse(intermediateBefore.get()); Assert.assertTrue(intermediateAfter.get()); Assert.assertTrue(intermediateProcess.get()); Assert.assertTrue(finishBefore.get());