File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Groovy and the fly likes Unit testing a closure with Spock Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Languages » Groovy
Bookmark "Unit testing a closure with Spock" Watch "Unit testing a closure with Spock" New topic
Author

Unit testing a closure with Spock

Red Maxwell
Greenhorn

Joined: Aug 18, 2012
Posts: 1
How would one unit test code within a closure using Spock?

// example groovy code

def someObject
def someOtherObject

def x = someCollection.collect{ item ->
someObject.doSomething(item)
}

// example Spock test snippet


then:
1 * someObjectMock.filter() >> foo
2 * someOtherObjectMock.find() >> bar

So here's the question: how to test the someObject.doSomething(item) in the above closure?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Unit testing a closure with Spock
 
Similar Threads
Still fuzzy on the Expando class - have any good examples of its use?
Example of using Groovy Closure for a different programming style
WA #2 ..... word association
What exactly are closures?
WA #1.....word association