Package com.github.nylle.javafixture
Class SpecimenBuilder<T>
- java.lang.Object
-
- com.github.nylle.javafixture.SpecimenBuilder<T>
-
- All Implemented Interfaces:
ISpecimenBuilder<T>
public class SpecimenBuilder<T> extends Object implements ISpecimenBuilder<T>
-
-
Constructor Summary
Constructors Constructor Description SpecimenBuilder(SpecimenType<T> type, Configuration configuration)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Tcreate()Stream<T>createMany()Stream<T>createMany(int size)Creates aStreamof objects based on thisISpecimenBuilder<T>with the specified sizeOptional<T>createOptional()<U> ISpecimenBuilder<T>with(SpecimenType<U> type, U value)Sets all fields with the specified type to the specified value during object creation.<U> ISpecimenBuilder<T>with(Class<U> type, U value)Sets all fields with the specified type to the specified value during object creation.ISpecimenBuilder<T>with(String fieldName, Object value)Sets the field with the specified name to the specified value during object creationISpecimenBuilder<T>with(Consumer<T> function)Applies the specified function to the created objectISpecimenBuilder<T>without(String fieldName)Omits the field with the specified name during object creation Primitives will receive their respective default-value, objects will be null
-
-
-
Constructor Detail
-
SpecimenBuilder
public SpecimenBuilder(SpecimenType<T> type, Configuration configuration)
-
-
Method Detail
-
create
public T create()
- Specified by:
createin interfaceISpecimenBuilder<T>- Returns:
- a new object based on this
ISpecimenBuilder<T>
-
createOptional
public Optional<T> createOptional()
- Specified by:
createOptionalin interfaceISpecimenBuilder<T>- Returns:
- a new
Optional<T>based on thisISpecimenBuilder<T>
-
createMany
public Stream<T> createMany()
- Specified by:
createManyin interfaceISpecimenBuilder<T>- Returns:
- a
Streamof objects based on thisISpecimenBuilder<T>
-
createMany
public Stream<T> createMany(int size)
Creates aStreamof objects based on thisISpecimenBuilder<T>with the specified size- Specified by:
createManyin interfaceISpecimenBuilder<T>- Parameters:
size- the size of theStreamto be created- Returns:
- a
Streamof objects based on thisISpecimenBuilder<T>
-
with
public ISpecimenBuilder<T> with(Consumer<T> function)
Applies the specified function to the created object- Specified by:
within interfaceISpecimenBuilder<T>- Parameters:
function- a function to customise the created object- Returns:
- this builder for further customisation
-
with
public ISpecimenBuilder<T> with(String fieldName, Object value)
Sets the field with the specified name to the specified value during object creation- Specified by:
within interfaceISpecimenBuilder<T>- Parameters:
fieldName- the name of the field to be setvalue- the value to be set to the field- Returns:
- this builder for further customisation
-
with
public <U> ISpecimenBuilder<T> with(Class<U> type, U value)
Sets all fields with the specified type to the specified value during object creation.- Specified by:
within interfaceISpecimenBuilder<T>- Type Parameters:
U- the type of the value- Parameters:
type- the type of the fields to be setvalue- the value to be set to the fields- Returns:
- this builder for further customisation
-
with
public <U> ISpecimenBuilder<T> with(SpecimenType<U> type, U value)
Sets all fields with the specified type to the specified value during object creation.- Specified by:
within interfaceISpecimenBuilder<T>- Type Parameters:
U- the type of the value- Parameters:
type- the type of the fields to be setvalue- the value to be set to the fields- Returns:
- this builder for further customisation
-
without
public ISpecimenBuilder<T> without(String fieldName)
Omits the field with the specified name during object creation Primitives will receive their respective default-value, objects will be null- Specified by:
withoutin interfaceISpecimenBuilder<T>- Parameters:
fieldName- the name of the field to be set- Returns:
- this builder for further customisation
-
-