Refactor test to reduce repated code