Replace a method with parameters by a closure in metaclass <p>I have two class:</p> <pre><code>class Foo { String doSomething(String a, String b) { return 'Not Working' } } class Bar { String methodIWannaTest() { return new Foo().doSomething('val1', 'val2') } } </code></pre> <p>And I want to replace 'doSomething' in a test but it dosent work</p> <pre><code>class BarTests { @Test void testMethodIWannaTest() { Foo.metaClass.doSomething {String a, String b -&gt; return 'Working'} assert new Bar().methodIWannaTest() == 'Working' //THIS TEST FAIL, return 'Not Working' } } </code></pre> <p>*I know the test doesn't really make sens, it's just to show my point</p> <p>What do I do wrong ? Is it possible to do it without using 'mockFor' ?</p>