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

spock.genesis.extension.ExtensionMethods.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.extension

import groovy.transform.CompileStatic
import spock.genesis.generators.Generator
import spock.genesis.generators.IterableGenerator
import spock.genesis.generators.ObjectIteratorGenerator

@CompileStatic
class ExtensionMethods {

    static  Generator multiply(Integer qty, Generator generator) {
        generator * qty
    }

    static  Generator multiply(BigInteger qty, Generator generator) {
        generator * qty.toInteger()
    }

    static  Generator toGenerator(Iterable self, boolean finite = false) {
        if (Generator.isInstance(self)) {
            (Generator) self
        } else {
            new IterableGenerator(self, finite)
        }
    }

    static Generator toGenerator(String self) {
        new ObjectIteratorGenerator(self)
    }

    static Generator toGenerator(Object self) {
        new ObjectIteratorGenerator(self)
    }

    static  Generator> toGenerator(Map self) {
        new ObjectIteratorGenerator(self)
    }

    static  Generator toGenerator(Collection self) {
        new IterableGenerator(self)
    }

    static Generator toGenerator(Class clazz) {
        if (clazz.isEnum()) {
            toGenerator(clazz.iterator().collect())
        } else {
            toGenerator([clazz])
        }
    }

    static  Generator toGenerator(T... self) {
        new IterableGenerator(self)
    }

    static  Generator toGenerator(Iterator self) {
        new IterableGenerator(new Iterable () {
            @Override
            Iterator iterator() {
                self
            }
        })
    }

    static  Generator toGenerator(Generator self) {
        self
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy