Unit testing middleware and handler code