Details
-
Type:
Bug
-
Status:
Closed
-
Priority:
Major
-
Resolution: Fixed
-
Affects Version/s: None
-
Fix Version/s: 1.6-rc-1, 1.5.8, 1.7-beta-1
-
Component/s: mocks and stubs
-
Labels:None
-
Testcase included:yes
-
Number of attachments :
Description
The following script leads to an exception. The closure does not delegate to the Mock.
import groovy.mock.interceptor.StubFor class Foo { def createBar() { throw new RuntimeException("We should never get here!") } } StubFor fooStub = new StubFor(Foo) fooStub.demand.createBar { "I'm a mock" } Closure closure = { createBar() } fooStub.use { Foo foo = new Foo() assert "I'm a mock" == foo.createBar() closure.delegate = foo assert "I'm a mock" == closure.call() }
Slight variation: