Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 252
Charu Jain Avatar asked Oct 29 '22 12:10

Charu Jain


1 Answers

Try:

YourClass.metaClass.static.methodName = { return 'something }
like image 131
Mike W Avatar answered Nov 16 '22 09:11

Mike W