5

Can anyone please let me know how to demand static methods of a class. I have tried with below code & it's not working with it:

import groovy.mock.interceptor.MockFor

final mockCl = new MockFor(ClassName) 
mockCl.demand.static.methodName(1) { return 'something' } 

With this it's giving below exception:

groovy.lang.MissingPropertyException: No such property: static for   class: groovy.mock.interceptor.Demand at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:53) at org.codehaus.groovy.runtime.callsite.GetEffectivePogoPropertySite.getProperty(GetEffectivePogoPropertySite.java:87)

Can someone point me how to mock static methods in JUNIT with grails 3.

Charu Jain
  • 701
  • 1
  • 5
  • 16

1 Answers1

2

Try:

YourClass.metaClass.static.methodName = { return 'something }
Mike W
  • 3,489
  • 2
  • 9
  • 14
  • Thanks Mike for the reply it's working with : YourClass.metaClass.static.methodName = { return 'something } Please edit your answer then I will accept it as a reply. – Charu Jain Feb 13 '17 at 08:10