Refactors to remove duplication in tests