Refactor test a bit to reduce code duplication