Groovy
  1. Groovy
  2. GROOVY-2271

Mocks are not used by the delegate of a closure

    Details

      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()
      }
      
      1. 2271Patch_v16X.txt
        0.9 kB
        Roshan Dawrani
      2. MockClosureTest.groovy
        0.8 kB
        Hans Dockter

        Activity

          People

          • Assignee:
            Roshan Dawrani
            Reporter:
            Hans Dockter
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development