I want unit test to return the value of some code that looks something like this:
Groovy Service code to test:
def findByThisAndThat(something) {
:
def items = []
sql.eachRow(query, criteriaList, {
def item = new Item(name:it.NAME)
items.add(item)
})
[items: items, whatever:whatevervalue]
}
Unit test code:
void testFindByThisAndThatReturnsAMapContainingItems(){
Sql.metaClass.eachRow = { String query, List criteria, Closure c ->
}
def result = service.findByThisAndThat("", "")
assert result.items
assertEquals('test item', result.items[0].name)
}
How can i do this? Thank!
source
share