Refactor withValid for simple tests.