I am trying to figure out how to write my Test cases for a service I am going to write.
The service will use HTTPBuilder to request a response from some URL. The HTTPBuilder request only needs to check the response for a success or failure. The service implementation will be be something as simple as:
boolean isOk() {
httpBuilder.request(GET) {
response.success = { return true }
response.failure = { return false }
}
}
So, I want to be able to mock the HTTPBuilder so that I can set the response to be either success/failure in my test so I can assert that my service's isOk
method returns True when the response is a success and False, when the response is a failure.
Can any one help with how I can mock the HTTPBuilder request and set the response in a GroovyTestCase?