Refactoring tests to use less repeated code