I having a grails function, where I am using a separate Thread:
def testFunction() {
//.....
Thread.start() {
testService.somefunction()
}
//...
}
In the unit test, I'm mocking the service function like this:
def "test testfunction" {
//...
1 * testService.somefunction(_)
//..
}
However, I get the unmatched invocations error, because Spock didn't detect that the method was executed on the separate thread.
1 * testService.somefunction(_) (0 invocations)
Unmatched invocations (ordered by similarity):
I tried using this http://spock-framework.readthedocs.org/en/latest/new_and_noteworthy.html#polling-conditions, but didn't have any success.
Updated to include a code sample:
void "test without errors"() {
def conditions = new PollingConditions(timeout: 15)
def cmdList = new ArrayList<CommandClass>()
parseService.parseFile(file, _) >> commandList
nextService.create(_) >> commandList
controller.controllerService = nextService
controller.controllerParseService = parseService
when:
controller.testFunction()
then:
conditions.eventually {
assert response.contentAsString == "SUCCESS"
}
}