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:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user