Created
September 13, 2011 21:12
-
-
Save jbrisbin/1215194 to your computer and use it in GitHub Desktop.
StateMachine implementation for Java test code
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
@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