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

        Hans Dockter created issue -
        Paul King made changes -
        Field Original Value New Value
        Component/s mocks and stubs [ 13113 ]
        Roshan Dawrani made changes -
        Attachment 2271Patch_v16X.txt [ 37601 ]
        Roshan Dawrani made changes -
        Assignee Roshan Dawrani [ roshandawrani ]
        Roshan Dawrani made changes -
        Fix Version/s 1.6-rc-1 [ 14009 ]
        Fix Version/s 1.6 [ 13832 ]
        Fix Version/s 1.5.8 [ 14630 ]
        Resolution Fixed [ 1 ]
        Fix Version/s 1.7-beta-1 [ 14014 ]
        Status Open [ 1 ] Resolved [ 5 ]
        Paul King made changes -
        Status Resolved [ 5 ] Closed [ 6 ]
        Mark Thomas made changes -
        Project Import Sun Apr 05 13:32:57 UTC 2015 [ 1428240777691 ]
        Mark Thomas made changes -
        Workflow jira [ 12731347 ] Default workflow, editable Closed status [ 12743275 ]
        Mark Thomas made changes -
        Project Import Mon Apr 06 02:11:23 UTC 2015 [ 1428286283443 ]
        Mark Thomas made changes -
        Workflow jira [ 12969503 ] Default workflow, editable Closed status [ 12977251 ]

          People

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

            Dates

            • Created:
              Updated:
              Resolved:

              Development