Refactoring tests to remove duplication