While writing Integration tests for spring applications, I tend to come across checks for different Multilevel Data Objects For Eg:
AssertNotNull("Node 10 is null", getNode1().getNode8().getNode10().getNode7());
This assertions works well provided that Objects A -> B -> C are not null, otherwise if any one of these is null, you end up with an NPE.
On a first view a plausible solution seems to all parent nodes sequentially
AssertNotNull("Node 1 is null", getNode1());
AssertNotNull("Node 8 is null", getNode1().getNode8());
AssertNotNull("Node 10 is null", getNode1().getNode8().getNode10());
AssertNotNull("Node 7 is null", getNode1().getNode8().getNode10().getNode7());
But if I start doing for every node I would end up having a bunch of cluttered up repeated code floating around.
As it is not development code and I would like to see the cause of the failure and not a raw NPE, specially when I have 100 such tests that assert these. What would be the best practice in this case to avoid NPE or not avoid it at all?