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

com.github.nylle.javafixture.JavaFixture Maven / Gradle / Ivy

Go to download

JavaFixture is the attempt to bring Mark Seemann's AutoFixture for .NET to the Java world. Its purpose is to generate full object graphs for use in test suites with a fluent API for customising the test objects during generation.

There is a newer version: 2.11.0
Show newest version
package com.github.nylle.javafixture;

import java.util.Collection;
import java.util.stream.Collectors;
import java.util.stream.Stream;


public class JavaFixture {

    private final SpecimenBuilderProvider provider;

    public JavaFixture() {
        this(new Configuration());
    }

    public JavaFixture(Configuration configuration) {
        this.provider = new SpecimenBuilderProvider(configuration);
    }

    public  T create(Class typeReference) {
        var specimenBuilder = provider.newBuilder(typeReference);
        return specimenBuilder.create();
    }

    public  Stream createMany(Class typeReference) {
        var specimenBuilder = provider.newBuilder(typeReference);
        return specimenBuilder.createMany();
    }

    public  ISpecimenBuilder build(Class typeReference) {
        return provider.newBuilder(typeReference);
    }

    public  void addManyTo(Collection result, Class typeReference) {
        var specimenBuilder = provider.newBuilder(typeReference);
        result.addAll(specimenBuilder.createMany().collect(Collectors.toList()));
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy