mtedone / podam

PODAM - POjo DAta Mocker
https://mtedone.github.io/podam
MIT License
323 stars 750 forks source link

Fill boolean field with random value #274

Closed bernolanger closed 4 years ago

bernolanger commented 5 years ago

Hello, thanks for the useful library.

For unit testing I need to fill boolean values in my Pojos with random values.

I found that BooleanTypeManufacturerImpl.getBoolean() returns always true while other implementations, e.g. IntTypeManufacturerImpl.getInteger(), return random values.

Is this by intention or is there a config option that I've overseen?

Implementing my own BooleanProviderStrategy works, but I would like to have a generic way so that I don't have to implement it in each project.

daivanov commented 5 years ago

Hi,

Yes, this is by intention as there is not much sense in randomizing something having only 2 values and one of them is Java's default one. If there would be a property changing this behaviour apparently there still will be a need to write some code in every project to change that. And taking in account we speak about several lines of the code, I don't see much of the benefit here.

Thanks, Daniil

bernolanger commented 5 years ago

Thanks for the quick answer.

I agree with the argument that a property doesn't make (much) sense.

What I don't understand is the fixed Boolean value. If the intention is that each value should be initialized with something other than the default, the Integer should never be initialized which zero; which is possible in the current implementation - at least theoretically :-)

We use Podam in a scenario where we want to detect copy&paste errors in mapping classes, e.g.

oneObject.setValueA(otherObject.isValueA());
oneObject.setValueB(otherObject.isValueB());
oneObject.setValueC(otherObject.isValueB()); // <-- here

If all Booleans have the same value, these checks will never fail.

So my question is: Is there a chance that the fixed Boolean value will be replaced by a random one in the future?

Kind regards, Berno

daivanov commented 4 years ago

I don't see much value in this. People who needs that for some corner cases can implement their own type manufacturer, which is the reason type manufacturers were introduced.

Thanks, Daniil