For the integration test, I want to have .save() intentionally to check for else -condition.
My class under testing does the following:
From UserService.groovy:
User user = User.findByXyz(xyz) if (user) { // foo if (user.save()) { // bar } else { // I WANT TO GET HERE } }
The approaches I tried so far have failed:
What I tried in UserServiceTests.groovy:
def uControl = mockFor(User) uControl.demand.save { flush -> null } // in order to test a failing user.save() def enabledUser = userService.enableUser(u.confirmationToken) uControl.verify() // or the following: User.metaClass.'static'.save = { flush -> null } // fails *all* other tests too
How can I correctly jump to an else block from an integration test?
source share