spock.genesis.generators.values.ByteArrayGenerator.groovy Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of spock-genesis Show documentation
Show all versions of spock-genesis Show documentation
Mostly lazy data generators for property based testing using the Spock test framework
The newest version!
package spock.genesis.generators.values
import groovy.transform.CompileStatic
import spock.genesis.generators.InfiniteGenerator
import spock.genesis.generators.InfiniteIterator
@CompileStatic
class ByteArrayGenerator extends InfiniteGenerator {
static final int DEFAULT_LENGTH_LIMIT = 1024 * 10
final WholeNumberGenerator lengthSource
ByteArrayGenerator() {
this.lengthSource = new WholeNumberGenerator(DEFAULT_LENGTH_LIMIT)
}
ByteArrayGenerator(int maxLength) {
this.lengthSource = new WholeNumberGenerator(maxLength)
}
ByteArrayGenerator(int minLength, int maxLength) {
this.lengthSource = new WholeNumberGenerator(minLength, maxLength)
}
ByteArrayGenerator(IntRange range) {
this.lengthSource = new WholeNumberGenerator(range)
}
@Override
InfiniteIterator iterator() {
new InfiniteIterator() {
private final InfiniteIterator length = lengthSource.iterator()
@Override
byte[] next() {
byte[] bytes = new byte[length.next()]
random.nextBytes(bytes)
bytes
}
}
}
@Override
ByteArrayGenerator seed(Long seed) {
lengthSource.seed(seed)
super.seed(seed)
this
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy