Refactoring this test code so we can use it in other parts.