Start isolating Java stuff

Make the code testable (and mockable).
Start adding midje tests