'demand' of static method is not working with 'new MockFor' in Grails-3.2.4 'Junit Testing'

736 Views Asked by At

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.

1

There are 1 best solutions below

1
On BEST ANSWER

Try:

YourClass.metaClass.static.methodName = { return 'something }