Refactored some of the test code to be more reusable.