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.
Try:
YourClass.metaClass.static.methodName = { return 'something }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With