All Downloads are FREE. Search and download functionalities are using the official Maven repository.

spock.genesis.generators.LimitedGenerator.groovy Maven / Gradle / Ivy

Go to download

Mostly lazy data generators for property based testing using the Spock test framework

The newest version!
package spock.genesis.generators

import groovy.transform.CompileStatic
import spock.genesis.extension.ExtensionMethods

@CompileStatic
class LimitedGenerator extends GeneratorDecorator {

    final int iterationLimit

    LimitedGenerator(Iterable iterable, int iterationLimit) {
        super(ExtensionMethods.toGenerator(iterable))
        this.iterationLimit = iterationLimit
    }

    UnmodifiableIterator iterator() {
        final Iterator ITERATOR = super.iterator()
        new UnmodifiableIterator() {
            private int iteration = 0

            @Override
            boolean hasNext() {
                ITERATOR.hasNext() && iteration < iterationLimit
            }

            @Override
            E next() {
                iteration++
                ITERATOR.next()
            }
        }
    }

    @Override
    boolean isFinite() {
        true
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy