ForgeRule - xgouchet/Elmyr GitHub Wiki
class ForgeRule : Forge, MethodRule
A JUnit rule to keep your test class clean and automate the creation of fake data.
It provides a Forge with the seed reset on each test, and will inject forgery on fields/properties annotated with Forgery.
In case of failure, the seed of the Forge is printed to the System.err output stream, allowing you to reproduce consistently failing tests.
Parameters
ruleSeed - the seed to reset the Forge for each test
Constructors
<init>
ForgeRule(ruleSeed: Long = 0L)
A JUnit rule to keep your test class clean and automate the creation of fake data.
It provides a Forge with the seed reset on each test, and will inject forgery on fields/properties annotated with Forgery.
In case of failure, the seed of the Forge is printed to the System.err output stream, allowing you to reproduce consistently failing tests.
Parameters
ruleSeed - the seed to reset the Forge for each test
Functions
apply
fun apply(base: Statement, method: FrameworkMethod, target: Any): Statement
Inheritdoc
withFactory
fun <reified T : Any> withFactory(forgeryFactory: ForgeryFactory<T>): ForgeRule
Adds a factory to the forge. This is the best way to extend a forge and provides means to create custom forgeries.
Parameters
T - the type the ForgeryFactory will be able to forge
forgeryFactory - the factory to be used
Return the same ForgeRule instance, perfect to chain calls
fun <T : Any> withFactory(clazz: Class<T>, forgeryFactory: ForgeryFactory<T>): ForgeRule
Adds a factory to the forge. This is the best way to extend a forge and provides means to create custom forgeries.
Parameters
T - the type the ForgeryFactory will be able to forge
clazz - the class of type T
forgeryFactory - the factory to be used
Return the same ForgeRule instance, perfect to chain calls