Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add utility method to adapt a Supplier to a Randomizer #343

Closed
fmbenhassine opened this issue Feb 22, 2019 · 0 comments
Closed

Add utility method to adapt a Supplier to a Randomizer #343

fmbenhassine opened this issue Feb 22, 2019 · 0 comments
Labels
Milestone

Comments

@fmbenhassine
Copy link
Member

As of v3.8, it is possible to use a Supplier as a Randomizer transparently thanks to a dynamic proxy created by random beans. However, this feature (introduced in #28) made the API verbose because we need to explicitly specify the type of the lambda expression when using EnhancedRandomBuilder#randomize. Here is an example:

EnhancedRandom enhancedRandom = EnhancedRandomBuilder.aNewEnhancedRandomBuilder()
                .randomize(String.class, (Randomizer<String>) () -> "foo")
                .build();

This is due to the fact the EnhancedRandomBuilder#randomize is overloaded with both a Randomizer and a Supplier.

IMO, this explicit cast is verbose and can be avoided by letting the user adapts the supplier if any. RB would provide a static method to create the proxy. This simple inversion of roles makes the API and its usage less verbose without compromising the feature.

fmbenhassine added a commit that referenced this issue Feb 22, 2019
@fmbenhassine fmbenhassine added this to the 3.9.0 milestone Feb 22, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant