Query refactoring unit tests