Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-4420

Unable to mock static method with mockFor or stubFor

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Not A Problem
    • 1.7.3
    • None
    • mocks and stubs
    • None

    Description

      Attempting to use instructions in http://docs.codehaus.org/display/GROOVY/Using+MockFor+and+StubFor to mock a static method.

      I get groovy.lang.MissingPropertyException: No such property: static for class: groovy.mock.interceptor.Demand
      in:

      import groovy.mock.interceptor.StubFor
      
      class StorefrontService { 
          String useStaticMethod(String forDeviceModel) { return Compatibility.list(forDeviceModel) }
      }
      
      class Compatibility {
          static def list(String deviceModel) { return 'static-' + it }
      }
      
      def mock = new StubFor(Compatibility)
      mock.demand.static.list { return 'static-mock-' + deviceModel }
      mock.use {
          println new StorefrontService().useStaticMethod('bc')
      }
      

      Attachments

        1. StubForCompatibilityError.groovy
          1 kB
          Olivier Gourment

        Activity

          People

            Unassigned Unassigned
            ogourment Olivier Gourment
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: