Refactoring some test code