Refactor rewrite test cases