-
Notifications
You must be signed in to change notification settings - Fork 26
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
Equals tester does not perform a check with the attributes set to nulls #191
Comments
Problem is with One of possible solutions for this problem is to create objects with default constructors parameters ( Next problem to solve is to satisfy all conditions of lombok-generated equals method:
especially this one:
This bunch of conditions needs three different objects, let's say: but pojo-tester generates only two of them: So. We need to create one additional object for each field (recursively) with not null field value, which is very nontrivial. The easiest way is to write additional test is @SemionPar, are you willing to implement this? :) |
As you have written constructors can have validation checks so it might be tricky to use them, instead I think there is a simpler/better way - to use the Objenesis library, which does not use the existing constructors to instantiate the given class. Once a new instance is available the values of the fields can be changed using reflection. I think this is the only way to guarantee 100% test coverage. |
I was trying to minimize dependencies in pojo-tester but now, as you suggested, it could be better to use It would also simplify whole But know I think there is one way to make 100% coverage - we have to generate more distinct objects - let me (or you @adamsiemion? :) ) do this first when I have some more time. |
I did a little bit of research/tests and (as expected) it turns out not to be that trivial. Replacing
Is not enough, because objenesis cannot instantiate primitive types, which is not a big problem, but unfortunately objenesis cannot also instantiate a lot of commonly used Java classes, such as e.g. I have tried re-using the above class in
but unfortunately it does not work as some of the tests are failing, some are now hanging. I will keep investigating the issue and share my findings. @sta-szek are you ok with using EqualsVerifier classes in pojo-tester? |
@adamsiemion thanks for investigating, but I prefer not to use EqualsVerifier in pojo tester as a dependency.
And maybe perform more checks in EqualsTester's
Maybe we should compare all objects, not only first one? |
I have a class:
and a test
this test should result in 100% test coverage (I use Jacoco) of the Entity class, right? Unfortunately it does not. I used delombok to get the source code generated by lombok and from my research it seems that, in this case,
equals()
is never tested withname
equal tonull
and that is the reason why for this class branch coverage is 64%. Can you please add new tests to EqualsTester?A workaround for this issue is to add an additional test
The text was updated successfully, but these errors were encountered: