View Javadoc
1   package com.google.code.beanmatchers;
2   
3   import java.util.Random;
4   
5   class EnumBasedValueGenerator implements TypeBasedValueGenerator {
6   
7     private final Random random;
8   
9     public EnumBasedValueGenerator(Random random) {
10      this.random = random;
11    }
12  
13    public <T> T generate(Class<T> type) {
14      T[] enumValues = type.getEnumConstants();
15      int enumIndex = random.nextInt(enumValues.length);
16      return enumValues[enumIndex];
17    }
18  }