Change tests to use the throws() functions.

This is instead of having a big try-catch block and a variable to track
whether an exception was thrown or not. Keeps it simpler.
Replace _isValidState with isValidState

The version with the leading underscore isn't defined, the one without
the leading underscore is the correct one.
Add more tests for the StateMachine class.

Tests for the setContextDefaults, setInitialState and addState methods.