
smallcheck.generators.EnumGen Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of java-smallcheck Show documentation
Show all versions of java-smallcheck Show documentation
An implementation of SmallCheck for Java as a JUnit extension.
The newest version!
package smallcheck.generators;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.stream.Stream;
/**
*
*/
public class EnumGen> extends SeriesGen {
private final T[] values;
public EnumGen(T...values) {
this.values = values;
}
public EnumGen(Class enumClass) {
try {
Method m = enumClass.getMethod("values");
m.setAccessible(true);
Object valuesObj = m.invoke(null);
@SuppressWarnings("unchecked")
T[] values = (T[]) valuesObj;
this.values = values;
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
throw new RuntimeException(e);
}
}
@Override
public Stream generate(int depth) {
return Stream.of(values).limit(depth);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy