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

Update Javadoc to mention that static methods do not take into account configuration parameters #259

Closed
mavasbel opened this issue Jul 6, 2017 · 3 comments
Milestone

Comments

@mavasbel
Copy link

mavasbel commented Jul 6, 2017

Hello, I have been using this amazingly util library and I think I encountered that when I want to generate list or streams of some object, the enhancedRandom does not respect the provided parameters.

This is the code I am using (you can change the "generatingClass" to check the behaviour):

EnhancedRandom rand = EnhancedRandomBuilder.aNewEnhancedRandom();
Randomizer<Long> longRand = () -> (long) (rand.nextInt(99) + 1);
Randomizer<Integer> intRand = () -> rand.nextInt(200) + 1;
Randomizer<Double> doubleRand = () -> rand.nextDouble() * 100.0;
EnhancedRandom enhancedRandom = EnhancedRandomBuilder.aNewEnhancedRandomBuilder()
		.scanClasspathForConcreteTypes(true).overrideDefaultInitialization(true).collectionSizeRange(0, 10)
		.stringLengthRange(8, 15).dateRange(LocalDate.of(1980, 1, 1), LocalDate.now())
		.timeRange(LocalTime.of(1, 0, 0), LocalTime.of(23, 0, 0)).randomize(Long.class, longRand)
		.randomize(Integer.class, intRand).randomize(Double.class, doubleRand).build();

Class generatingClass = Integer.class;
Integer listSize = longRand.getRandomValue().intValue();
List randomInstances = new ArrayList<>(listSize);
IntStream.rangeClosed(1, listSize)
		.forEach(i -> randomInstances.add(enhancedRandom.nextObject(generatingClass)));
logger.info("objectsOneByOne: " + randomInstances);
logger.info("objectsList: " + enhancedRandom.randomListOf(listSize, generatingClass));

And this is the output:

INFO - objectsOneByOne: [35, 23, 108, 125, 196, 37, 70, 76, 185, 181, 122, 184, 27, 47, 16, 153, 167, 199, 139, 158, 48, 21, 185, 129, 39, 41, 170, 103, 96, 57, 55, 166, 178, 13, 64, 191, 82, 25, 177, 58, 84, 161, 170, 153, 168, 124, 10, 141, 109, 95, 143, 84, 69, 42, 93, 164, 180, 184, 33, 10, 61, 104, 32, 11, 115, 176, 96, 156, 82, 161, 123, 164, 144, 93, 76, 166]
INFO - objectsList: [-1514334470, -2075070463, 224962436, 1935331690, 251248171, 1653112232, 1853228944, 749510790, 2140227420, 970819133, 64786774, 2068590833, 1235969804, 1185862399, 258063342, 208674894, 2024303305, -849290998, -2005634300, -1905198479, 2033135882, -2073512300, -1793719094, 1722794562, -1786623429, -692895629, 1401912112, -706632473, -908224744, 959505378, 210162770, -20890847, -555812803, -1416142717, 105565746, -666370826, -49159426, -34169177, 1550006694, -1315386480, 1709109108, 449717709, -1931540333, -1393642139, 1486730200, -1541081239, 1857588059, -160343913, -1483177709, -235023899, 1027314067, -1644001380, 901174421, 2107514860, -1965006343, -433122271, -1417899163, 264116197, -1379287643, -1197022165, -1504091528, 1948045245, 1883464317, 1346286975, -1994084281, -614774551, 327270638, 1002451780, -849853541, -1867663189, -1984243496, -1175240218, 996434858, -601714541, -239373879, 1351984444]

@PascalSchumacher
Copy link
Collaborator

PascalSchumacher commented Jul 6, 2017

Hi marcovb279,

sorry for the confusion, but static methods of EnhancedRandom like randomListOf do not use the configuration created with EnhancedRandomBuilder. If you use EnhancedRandom#objects to generate a Stream (collect it to a List, Set etc. if you require a different collection type) it should work.

Cheers,
Pascal

@fmbenhassine
Copy link
Member

Hi @marcovb279

As @PascalSchumacher said, static methods do not take into account configuration parameters. Sorry for the confusion.

@PascalSchumacher This is not the first time this confusion occurs ( see issue #254 and issue #198 ). It is time to document it clearly in the wiki and Javadoc. I will take care of that.

@marcovb279 Give it a try with EnhancedRandom#objects, it should work fine. If it is the case, don't hesitate to close the issue.

Kind regards
Mahmoud

fmbenhassine added a commit that referenced this issue Jul 6, 2017
…tic methods do not take into account configuration parameters set with the builder
@mavasbel
Copy link
Author

mavasbel commented Jul 7, 2017

Thank you for the clarification @PascalSchumacher @benas, I hadn't noticed the static methods.

I have tested with EnhancedRandom#objects and it works fine.

I close the issue.

Regards

@mavasbel mavasbel closed this as completed Jul 7, 2017
@fmbenhassine fmbenhassine added this to the v3.8.0 milestone Mar 18, 2018
@fmbenhassine fmbenhassine changed the title EnhancedRandom seems to not respect rules when generate collections or streams Update Javadoc to mention that static methods do not take into account configuration parameters Jan 26, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants