unit testing - mock domain class created by another domain class with spock -


i'm trying test domain class called enitycontact. inside class there method called initialize populates fields when needed. in order method creates instances of other domain classes: aisuser, entity , cperson. aisuser domain class returned call securityutil.retrievecurrentaisuser(false).

class entitycontact extends baseobject implements initializable{      ....      @override     void initialize() {         println "initaliazing"         ismain = false         creationdate = new date()         createdby = cperson.get(securityutil.retrievecurrentaisuser(false).id)         entity = new entity()         entity.setid(long.valueof(0)) //id has initialized value     } } 

what trying find way return mocks of classes define in specification.

any ideas?

in groovy you can mock static methods using metaclass.

securityutil.metaclass.'static'.retrievecurrentaisuser = { boolean param -> } 

Comments

Popular posts from this blog

c++ - CryptStringToBinary API behavior -

java.util.scanner - How to read and add only numbers to array from a text file -

iphone - Three second countdown in cocos2d -