public interface CustomDao { List getIds() ModelObject getModelById(int id) } class ModelObject { int id } class CustomServiceUtil { CustomDao customDao public List createOutputSet() { List models = new ArrayList(); List ids = customDao.getIds(); for (Integer id in ids) { models.add(customDao.getModelById(id)); } return models } } class TestSpec extends Specification { def 'crazy closures'() { def mockDao = Mock(CustomDao) def idSet = [9,10] given: 'An initialized object' def customService = new CustomServiceUtil() customService.customDao = mockDao when: 'createOutput is called' def outputSet = customService.createOutputSet() then: 'the following methods should be called' 1*mockDao.getIds() >> { return idSet } idSet.each { mockDao.getModelById(it) >> {int id -> def tmp = new ModelObject() println "Inside stubbed closure with value of id as $id" tmp.id = id return tmp } } and: 'each compute package is accurate' 2 == outputSet.size() 9 == outputSet.get(0).getId() 10 == outputSet.get(1).getId() } } //Prints Inside stubbed closure with value of id as 9 Inside stubbed closure with value of id as 10