The project uses TestNg, Java11, Spring test
I am writing testNG tests for API I have a java object that has this kind of stucture:
class Object1
private Object2 o2;
private List<Object3> o3;
Where Object2
is not only composed of primitive attributes.
I would like to test if 2 Object1
are equals with these rules:
- if actual
o2
is null, don't fail even if the othero2
is not - if actual
o3
is null or empty, don't fail even if the othero3
is not - if actual
o3
is not null nor empty, compare only non nullObject3
fields
To sum up, I would like to assert that 2 objects are the same, ignoring null fields recursively.
I could do it
assertThat(actual).usingRecursiveComparison().ignoringActualNullFields().isEqualTo(other);
but the recursive null fields are not ignored.
How can I fix this?