Fix wrong event object comparison

- Classic case of using == vs. equals if Strings are involved.
- In DefaultStateMachineExecutor change event comparison
  from == to equals.
- Tests using enums naturally work, but some tests using Strings
  had a wrong checks.
- Fixes #253
This commit is contained in:
Janne Valkealahti
2016-09-26 10:29:01 +01:00
parent 29f67fdbf8
commit 8fc7592404
2 changed files with 11 additions and 11 deletions

View File

@@ -106,8 +106,8 @@ public class ShowcaseUmlTests extends AbstractBuildTests {
.expectStates("S0", "S2", "S21", "S211").and()
.step()
.sendEvent("H")
.expectVariable("foo", 0)
.expectTransition(0)
.expectVariable("foo", 1)
.expectTransition(1)
.expectStates("S0", "S2", "S21", "S211").and()
.step()
.sendEvent("K")
@@ -115,9 +115,9 @@ public class ShowcaseUmlTests extends AbstractBuildTests {
.expectStates("S0", "S1", "S11").and()
.step()
.sendEvent("A")
.expectStateChanged(0)
.expectStateEntered(0)
.expectStateExited(0)
.expectStateChanged(2)
.expectStateEntered(2)
.expectStateExited(2)
.expectStates("S0", "S1", "S11").and()
.build();
plan.test();
@@ -286,8 +286,8 @@ public class ShowcaseUmlTests extends AbstractBuildTests {
.expectStates("S0", "S2", "S21", "S211").and()
.step()
.sendEvent("H")
.expectVariable("foo", 0)
.expectTransition(0)
.expectVariable("foo", 1)
.expectTransition(1)
.expectStates("S0", "S2", "S21", "S211").and()
.build();
plan.test();
@@ -315,8 +315,8 @@ public class ShowcaseUmlTests extends AbstractBuildTests {
.expectStates("S0", "S2", "S21", "S211").and()
.step()
.sendEvent("H")
.expectVariable("foo", 0)
.expectTransition(0)
.expectVariable("foo", 1)
.expectTransition(1)
.expectStates("S0", "S2", "S21", "S211").and()
.build();
plan.test();

View File

@@ -366,8 +366,8 @@ public class DefaultStateMachineExecutor<S, E> extends LifecycleObjectSupport im
Trigger<S, E> tri = e.getKey();
E ee = tri.getEvent();
Transition<S, E> tra = e.getValue();
if (event == ee) {
if (tra.getSource().getId() == id && !trans.contains(tra)) {
if (event.equals(ee)) {
if (tra.getSource().getId().equals(id) && !trans.contains(tra)) {
trans.add(tra);
continue;
}