Refactoring test class to remove duplication