j-easy/easy-random

EnumSetRandomizer can produce "Collection is empty" exception

ahaverdings-deloitte opened this issue · 1 comments

The default implementation for EnumSetRandomizer takes a abs(new ByteRandomizer().getRandomValue()) as number of elements to randomly copy into the set. This randomizer can produce a 0 which in turn will cause a IllegalArgumentException > "Collection is empty" when fetching a new randomValue for the EnumSet.

Solution:
The minimum value for nbElements should be 1 so either there should be a different default randomizer or when the value is 0 it should become 1

That's a valid issue. Thank you for reporting it!