Groovy HTTPBuilder Mocking the Client
This question is closely related to this question . The difference is that I'd like to follow the recommended approach of mocking the client. So, I have the following HTTPBuilder defined: protected readUrl() { def http = new HTTPBuilder("http://example.com") def status = http.request(Method.GET, ContentType.JSON) {req -> response.success = {resp, json -> result = json.toString() new Success<String>(result) } response.'401' = {resp -> final String errMsg = "Not Authorized" new Failed(Failable.Fail.ACCESS_DENIED, errMsg) } response.failure = {resp -> final String errMsg = "General failure ${resp