Created
February 11, 2015 02:32
-
-
Save hekailiang/bdcff9e17be240e3c0c0 to your computer and use it in GitHub Desktop.
TerminateOnDemandTest
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.squirrelframework.foundation.fsm; | |
import org.junit.Test; | |
import org.squirrelframework.foundation.fsm.annotation.ContextInsensitive; | |
import org.squirrelframework.foundation.fsm.impl.AbstractStateMachine; | |
import static org.junit.Assert.assertEquals; | |
/** | |
* Created by kailianghe on 2/11/15. | |
*/ | |
public class TerminateOnDemandTest { | |
@Test | |
public void testTerminateOnDemand() { | |
FSM fsm = createFSM(); | |
fsm.fire(Event.TERMINATE); | |
assertEquals(StateMachineStatus.TERMINATED, fsm.getStatus()); | |
} | |
private static FSM createFSM() { | |
StateMachineBuilder<FSM, State, Event, Void> builder = | |
StateMachineBuilderFactory.create(FSM.class, State.class, Event.class, Void.class); | |
builder.externalTransition().from(State.INIT).to(State.TERMINATE).on(Event.TERMINATE); | |
builder.onEntry(State.TERMINATE).perform(new AnonymousAction<FSM, State, Event, Void>() { | |
@Override | |
public void execute(State from, State to, Event event, Void context, FSM stateMachine) { | |
// let's assume we are ready to go wild already and just fire event | |
stateMachine.terminate(); | |
} | |
}); | |
return builder.newStateMachine(State.INIT); | |
} | |
@ContextInsensitive | |
private static class FSM extends AbstractStateMachine<FSM, State, Event, Void> { | |
} | |
private static enum State { | |
INIT, | |
TERMINATE | |
} | |
private static enum Event { | |
TERMINATE, | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment