j-easy/easy-random

Pass Field object to the Randomizer

GiancarloCubeta opened this issue · 1 comments

In Randomizer interface

Change method from:
public String getRandomValue()
to
public String getRandomValue(Field field)

This will make every randomizer more versatile.
For example a StringRandomizer could generate a random value with a prefix equal to the name of the field it is filling. This will help during debugging in checking the expected values.

Thank you for opening this feature request. What you are looking for is the ContextAwareRandomizer, which is an extension of Randomizer to make it aware of the current context (which contains the current field/object). Here is an example: https://github.com/j-easy/easy-random/blob/fc58f6129b385b7541a12235511cf5c0a6bc4eec/easy-random-core/src/test/java/org/jeasy/random/context/LastNameRandomizer.java

I am closing this issue for now as I believe the ContextAwareRandomizer is the way to go (no need to change the Randomizer#getRandomValue method), but feel free to add a comment if you need more support on this.