Skip to content

Instantly share code, notes, and snippets.

@jbrisbin
Created September 13, 2011 21:12
Show Gist options
  • Save jbrisbin/1215194 to your computer and use it in GitHub Desktop.
Save jbrisbin/1215194 to your computer and use it in GitHub Desktop.
StateMachine implementation for Java test code
@Test
public void testSimpleStateMachine() throws ExecutionException, InterruptedException {
final StateMachine m = new StateMachine("first");
m.on("first", new Handler<StringBuffer>() {
@Override public void handle(StringBuffer sb) {
sb.append("1");
m.state("second", sb);
}
});
m.on("second", new Handler<StringBuffer>() {
@Override public void handle(StringBuffer sb) {
sb.append("2");
m.state("third", sb);
}
});
m.on("third", new Handler<StringBuffer>() {
@Override public void handle(StringBuffer sb) {
sb.append("3");
m.state(null, sb);
}
});
Promise<StringBuffer> p = m.run(new StringBuffer());
assertEquals("Buffer was properly mutated", "123", p.get().toString());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment