Factored out duplicated code in test cases