Fix tests on MacOS

 due to different behaviours of File.getCanonicalPath for temp dir.

Also cleaned up imports etc as I was here.