Package com.github.nylle.javafixture
Class Fixture
- java.lang.Object
-
- com.github.nylle.javafixture.Fixture
-
- Direct Known Subclasses:
JavaFixture
public class Fixture extends Object
-
-
Constructor Summary
Constructors Constructor Description Fixture()Creates a newFixturewith default configuration:Fixture(Configuration configuration)Creates a newFixturewith given configuration
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description <T> voidaddManyTo(Collection<T> result, SpecimenType<T> type)Adds objects of the specifiedSpecimenType<T>, recursively populated with random values, to the specifiedCollection<T>The number of objects created is specified in theConfigurationunderstreamSize(default: 3)<T> voidaddManyTo(Collection<T> result, Class<T> type)Adds objects of the specifiedClass<T>, recursively populated with random values, to the specifiedCollection<T>The number of objects created is specified in theConfigurationunderstreamSize(default: 3)<T> ISpecimenBuilder<T>build(SpecimenType<T> type)Creates aISpecimenBuilder<T>to customise the object of typeTto be created<T> ISpecimenBuilder<T>build(Class<T> type)Creates aISpecimenBuilder<T>to customise the object of typeTto be createdstatic Configurationconfiguration()Returns a new default configuration with the following values<T> Tconstruct(SpecimenType<T> type)Creates a new object of the specified type, using a random constructor if available<T> Tconstruct(Class<T> type)Creates a new object of the specified type, using a random constructor if available<T> Tcreate(SpecimenType<T> type)Creates a new object of the specified type, recursively populated with random values<T> Tcreate(Class<T> type)Creates a new object of the specified type, recursively populated with random values<T> Stream<T>createMany(SpecimenType<T> type)Creates aStreamof objects of the specified type, recursively populated with random values<T> Stream<T>createMany(Class<T> type)Creates aStreamof objects of the specified type, recursively populated with random values<T> Optional<T>createOptional(Class<T> type)Creates a new optional of the specified type, recursively populated with random valuesstatic Fixturefixture()Creates a newFixturewith default configuration:
-
-
-
Constructor Detail
-
Fixture
public Fixture()
Creates a newFixturewith default configuration:- maxCollectionSize = 10
- minCollectionSize = 2
- streamSize = 3
- usePositiveNumbersOnly = false
- clock = Clock.fixed(Instant.now(), ZoneOffset.UTC)
-
Fixture
public Fixture(Configuration configuration)
Creates a newFixturewith given configuration- Parameters:
configuration- the configuration
-
-
Method Detail
-
fixture
public static Fixture fixture()
Creates a newFixturewith default configuration:- maxCollectionSize = 10
- minCollectionSize = 2
- streamSize = 3
- usePositiveNumbersOnly = false
- clock = Clock.fixed(Instant.now(), ZoneOffset.UTC)
-
configuration
public static Configuration configuration()
Returns a new default configuration with the following values- maxCollectionSize = 10
- minCollectionSize = 2
- streamSize = 3
- usePositiveNumbersOnly = false
- clock = Clock.fixed(Instant.now(), ZoneOffset.UTC)
- Returns:
Configuration
-
create
public <T> T create(Class<T> type)
Creates a new object of the specified type, recursively populated with random values- Type Parameters:
T- the type of the object to be created- Parameters:
type- theClass<T>based on which the object is created- Returns:
- a new object of the specified
Class<T>
-
createOptional
public <T> Optional<T> createOptional(Class<T> type)
Creates a new optional of the specified type, recursively populated with random values- Type Parameters:
T- the type of the object to be created- Parameters:
type- theClass<T>based on which the object is created- Returns:
- a new
Optionalof the specifiedClass<T>
-
create
public <T> T create(SpecimenType<T> type)
Creates a new object of the specified type, recursively populated with random values- Type Parameters:
T- the type of the object to be created- Parameters:
type- theSpecimenType<T>based on which the object is created- Returns:
- a new object of the specified type
T
-
construct
public <T> T construct(Class<T> type)
Creates a new object of the specified type, using a random constructor if available- Type Parameters:
T- the type of the object to be created- Parameters:
type- theClass<T>based on which the object is created- Returns:
- a new object of the specified type
T
-
construct
public <T> T construct(SpecimenType<T> type)
Creates a new object of the specified type, using a random constructor if available- Type Parameters:
T- the type of the object to be created- Parameters:
type- theSpecimenType<T>based on which the object is created- Returns:
- a new object of the specified type
T
-
createMany
public <T> Stream<T> createMany(Class<T> type)
Creates aStreamof objects of the specified type, recursively populated with random values- Type Parameters:
T- the type of the objects to be created- Parameters:
type- theClass<T>based on which the objects are created- Returns:
- a
Streamof objects of the specified typeT
-
createMany
public <T> Stream<T> createMany(SpecimenType<T> type)
Creates aStreamof objects of the specified type, recursively populated with random values- Type Parameters:
T- the type of the objects to be created- Parameters:
type- theSpecimenType<T>based on which the objects are created- Returns:
- a
Streamof objects of the specified typeT
-
build
public <T> ISpecimenBuilder<T> build(Class<T> type)
Creates aISpecimenBuilder<T>to customise the object of typeTto be created- Type Parameters:
T- the type of the object to be created- Parameters:
type- theClass<T>based on which the object is created- Returns:
- a builder for further customisation
-
build
public <T> ISpecimenBuilder<T> build(SpecimenType<T> type)
Creates aISpecimenBuilder<T>to customise the object of typeTto be created- Type Parameters:
T- the type of the object to be created- Parameters:
type- theSpecimenType<T>based on which the object is created- Returns:
- a builder for further customisation
-
addManyTo
public <T> void addManyTo(Collection<T> result, Class<T> type)
Adds objects of the specifiedClass<T>, recursively populated with random values, to the specifiedCollection<T>The number of objects created is specified in theConfigurationunderstreamSize(default: 3)- Type Parameters:
T- the type of the collection and the objects to be added- Parameters:
result- the collection the created objects should be added totype- theClass<T>based on which the objects are created
-
addManyTo
public <T> void addManyTo(Collection<T> result, SpecimenType<T> type)
Adds objects of the specifiedSpecimenType<T>, recursively populated with random values, to the specifiedCollection<T>The number of objects created is specified in theConfigurationunderstreamSize(default: 3)- Type Parameters:
T- the type of the collection and the objects to be added- Parameters:
result- the collection the created objects should be added totype- theSpecimenType<T>based on which the objects are created
-
-