public class StubBuilder<T> extends Object
| Modifier and Type | Method and Description |
|---|---|
static <T> StubBuilder<T> |
aRandomStubOf(Class<T> type)
Return an instance of a
StubBuilder for the given type which is
populated with random values. |
static <T> StubBuilder<T> |
aRandomStubOf(TypeReference<T> type)
Return an instance of a
StubBuilder for the given generic type
which is populated with random values. |
T |
build()
Build the configured instance.
|
StubBuilder<T> |
collectionSizeOf(int size)
Configure the builder to set the size of a collections.
|
StubBuilder<T> |
collectionSizeRangeOf(int min,
int max)
Configure the builder to set the size of a collections to within a given
range.
|
<X> StubBuilder<T> |
factory(Class<X> type,
ValueFactory<X> factory)
Configure the builder to populate any properties of the given type with a
value created by the supplied value factory.
|
<X> StubBuilder<T> |
subtype(Class<X> supertype,
Class<? extends X>... subtypes)
Configure the builder to use any of of a particular subtype when
instantiating a super type.
|
<X> StubBuilder<T> |
subtype(Class<X> supertype,
Class<? extends X> subtype)
Configure the builder to use a particular subtype when instantiating a
super type.
|
<V> StubBuilder<T> |
with(Class<V> type,
ValueFactory<V> factory)
Configure the builder to populate any properties of the given type with a
value created by the supplied value factory.
|
public static <T> StubBuilder<T> aRandomStubOf(Class<T> type)
StubBuilder for the given type which is
populated with random values. For example:
Person aPerson = StubBuilder.aRandomInstanceOf(Person.class).build()
type - the type to return the StubBuilder forpublic static <T> StubBuilder<T> aRandomStubOf(TypeReference<T> type)
StubBuilder for the given generic type
which is populated with random values. For example:
MyTypevalue = StubBuilder.aRandomInstanceOf(new TypeReference<MyType<String>>(){}) .build()
type - the type to return the StubBuilder forpublic <V> StubBuilder<T> with(Class<V> type, ValueFactory<V> factory)
Person aPerson = StubBuilder.aRandomInstanceOf(Person.class)
.with(Date.class, ValueFactories.oneOf(APR(5,1975), APR(5,1985)))
.build()
type - the type of property to use the factory forfactory - the factory to use to create the valuepublic <X> StubBuilder<T> factory(Class<X> type, ValueFactory<X> factory)
Person aPerson = StubBuilder.aRandomInstanceOf(Person.class)
.factory(Date.class, ValueFactories.oneOf(APR(5,1975), APR(5,1985)))
.build()
type - the type of property to use the factory forfactory - the factory to use to create the valuepublic StubBuilder<T> collectionSizeOf(int size)
Person aPerson = StubBuilder.aRandomInstanceOf(Person.class)
.collectionSizeOf(5)
.build()
size - the size to create the collectionspublic StubBuilder<T> collectionSizeRangeOf(int min, int max)
Person aPerson = StubBuilder.aRandomInstanceOf(Person.class)
.collectionSizeRangeOf(2,10)
.build()
min - the minimum size to create the collectionsmax - the maximum size to create the collectionspublic <X> StubBuilder<T> subtype(Class<X> supertype, Class<? extends X> subtype)
ShapeSorter aSorter = StubBuilder.aRandomInstanceOf(ShapeSorter.class)
.subtype(Shape.class, Square.class)
.build()
supertype - the type of the super typesubtype - the subtype to use when instantiating the super typepublic <X> StubBuilder<T> subtype(Class<X> supertype, Class<? extends X>... subtypes)
ShapeSorter aSorter = StubBuilder.aRandomInstanceOf(ShapeSorter.class)
.subtype(Shape.class, Square.class, Circle.class, Triangle.class)
.build()
supertype - the type of the super typesubtypes - the subtypes to pick from when instantiating the super
typepublic T build()
Person aPerson = StubBuilder.aRandomInstanceOf(Person.class).build()
Copyright © 2018. All rights reserved.