Here is a minimal HttpBuilder layout example that your test case will handle:
class MockHttpBuilder { def result def requestDelegate = [response: [:]] def request(Method method, Closure body) { body.delegate = requestDelegate body.call() if (result) requestDelegate.response.success() else requestDelegate.response.failure() } }
If the result field is true, it causes a success closure, otherwise failure .
EDIT: here is an example of using MockFor instead of the mock class:
import groovy.mock.interceptor.MockFor def requestDelegate = [response: [:]] def mock = new MockFor(HttpBuilder) mock.demand.request { Method method, Closure body -> body.delegate = requestDelegate body.call() requestDelegate.response.success() // or failure depending on what being tested } mock.use { assert isOk() == true }
ataylor
source share