StateContext may use wrong statemachine

- Tweaking to keep correct statemachine ref around
  so that StateContext passed to actions can be
  used to send events within submachines.
- This was missed due to missing test and i.e. cdplayer
  should transition into playing state directly via
  and event sent from action which when closed is
  checking if cd is inserted.
- Fixes #33
This commit is contained in:
Janne Valkealahti
2015-04-07 22:18:03 +01:00
parent 45ebce9c64
commit 487911b4de
4 changed files with 48 additions and 29 deletions

View File

@@ -196,8 +196,8 @@ public class Application {
@Override
public void execute(StateContext<States, Events> context) {
if (context.getTransition() != null
&& context.getTransition().getSource().getId() == States.CLOSED
&& context.getMessageHeader(Variables.CD) != null) {
&& context.getTransition().getTarget().getId() == States.CLOSED
&& context.getExtendedState().getVariables().get(Variables.CD) != null) {
context.getStateMachine().sendEvent(Events.PLAY);
}
}

View File

@@ -77,6 +77,18 @@ public class CdPlayerTests {
assertLcdStatusContains("cd1");
}
@Test
public void testPlayWithCdLoadedDeckOpen() throws Exception {
listener.reset(3, 0, 0);
player.eject();
player.load(library.getCollection().get(0));
player.play();
listener.stateChangedLatch.await(5, TimeUnit.SECONDS);
assertThat(listener.stateChangedCount, is(4));
assertThat(machine.getState().getIds(), contains(States.BUSY, States.PLAYING));
assertLcdStatusContains("cd1");
}
@Test
public void testPlayWithNoCdLoaded() throws Exception {
listener.reset(0, 0, 0);