I would like to mock a domain with everything as usual (mockDomain(Class)), but I would like to overwrite one of the domain’s methods (beforeDelete to be specific) with custom logic just for that one unit test.
How can this be achieved?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can override the beforeDelete method on your domain class using Groovy metaClass.
Domain class:
Unit Test:
–Output from testBeforeDelete–
Deleting Person 1
–Output from testBeforeDeleteOverrideBeforeDelete–
Do not touch me