Skip to content

Instantly share code, notes, and snippets.

@robfletcher
Created March 21, 2013 23:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robfletcher/5217772 to your computer and use it in GitHub Desktop.
Save robfletcher/5217772 to your computer and use it in GitHub Desktop.
package spock.extensions.state
class StateMachine<E extends Enum> {
private final String name
private E currentState
StateMachine(String name, E initialState) {
this.name = name
currentState = initialState
}
void becomes(E newState) {
currentState = newState
}
void is(E expectedState) {
assert currentState == expectedState, "$name state should be $expectedState but is $currentState"
}
void isNot(E expectedState) {
assert currentState != expectedState, "$name state should not be $expectedState but it is"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment