groovy - UnsupportedOperationException when using Method Pointer Operator and MockFor -
i had test. using mockfor , working , happy. until changed , forced use method pointer operator, , happiness memory.
here constricted example of problem
import groovy.mock.interceptor.* // testing againts interface, not actual class // not negociable. interface person { void sayhello(name); } // setup (can whatever need) def personmock = new mockfor(person) personmock.demand.sayhello { name -> println "hello $name" } def person = personmock.proxyinstance() // end setup // exercise (can not change) def closuremethod = person.&sayhello.curry("groovy!") closuremethod() // end exercise personmock.verify(person)
which safest , simplest way fix test? currently, test fails java.lang.unsupportedoperationexception
even when testing against interface, nothing prevents me creating mock class implements interface , poor-men verify demands.
import groovy.mock.interceptor.* // testing against interface, not actual class // not negociable. interface person { void sayhello(name); } class personmock implements person { def calls = [] void sayhello(name) { calls << "sayhello" } } // setup (can whatever need) def person = new personmock() // end setup // exercise (can not change) def closuremethod = person.&sayhello.curry("groovy!") closuremethod() // end exercise assert person.calls == ['sayhello']
Comments
Post a Comment