
How to Design Extended Finite State Machine Test Models in Java 157
public class SimpleMBT {
public static final double RESET_PROBABILITY = 0.01;
protected FsmModel model_;
protected List<Method> methods_ = new ArrayList<Method>();
protected Random rand_ = new Random(42L); // use a fixed seed
SimpleMBT(FsmModel model) {
this.model_ = model;
for (Method m : model.getClass().getMethods()) {
if (m.getAnnotation(Action.class)!=null){
methods_.add(m);
}
}
}
/** Generate a random test sequence of length 1.
* @return the name of the action done, or "reset".
*/
public String generate() throws Exception {
if (rand_.nextDouble() < RESET_PROBABILITY){
model_.reset(true