Refactored test handlers into a helper method.