refactor the middleware class out for tests