Fix IDE warnings
Refactor test to stop IDE complaining about possible NPEs.
Also requires slightly less code.