This is a request to allow mocking of the project.exec(…) method (also project.copy and so on). This is important for validating calls to the command line. This is currently impossible as the Project class is an interface. When mocking is attempted using MockFor, it will always call the original method and never the mock. This is a long standing bug in Groovy. Tracked as GROOVY-3493 (reported originally in 2009):
“Cannot override methods via metaclass that are part of an interface implementation”
I believe this could be fixed if Project.groovy was changed so it was no longer an interface. I understand that it may have substantial implications which make this a difficult change. This problem may apply to other interfaces as well but Project was the most painful issue I encountered.
A more detailed description of why MockFor fails due to metaClass issues is described on this SO answer. It also describes a complex workaround using invokeMethod… which is effective but complex and hacky:
Here is the class: