com.github.nylle.javafixture.JavaFixture Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of javafixture Show documentation
Show all versions of javafixture Show documentation
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.
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