Move logic from registerTask to method that can be called from tests.