Grails 프로덕션 코드를 테스트하고 싶습니다. 아래 예제를 보았습니다. 문제는 HttpBuilder의 클라이언트 부분에서 MissimgMethodExceptions을 실행한다는 것입니다. 이것은 내가 테스트하고 싶은 제품 코드 : 사용 http://groovy.codehaus.org/Groovy+way+to+implement+interfacesMockFor를 사용하여 HttpBuilder에서 모의 클라이언트를 사용하는 방법?
: 여기에 멋있는 문서에 인터페이스를 조롱에 Groovy HTTPBuilder Mocking the Response을 일부 : 나는 어떤 여기에 HTTPBuilder를 조롱의 주제에 대한 도움말을 발견
class RunkeeperActivitiesRetrieverService {
def http = new RESTClient("http://api.runkeeper.com/")
def getActivities() {
http.client.clearRequestInterceptors();
http.client.addRequestInterceptor(new HttpRequestInterceptor() {
void process(HttpRequest httpRequest, HttpContext httpContext) {
httpRequest.addHeader('Authorization', 'Bearer xxxxxxxxxx')
}
})
//Do more with the httpBuilder
}
}
그 코드는 나는이 테스트 코드에 온 :
def mock = new MockFor(HTTPBuilder)
def impl = [
addRequestInterceptor : {HttpRequestInterceptor interceptor -> println "hi 4"+interceptor},
clearRequestInterceptors : {println "hi 88"}
]
def client = impl as HttpClient
mock.demand.getClient {return client}
mock.use{
service.http = new HTTPBuilder()
println service.getActivities()
}
불행하게도 그루비의 내 지식이 너무 throw되는 예외 해결하기 위해 제한됩니다 groovy.lang.MissingMethodException: No signature of method: $Proxy15.clearRequestInterceptors() is applicable for argument types:() values: []
여기에 무엇이 누락 되었습니까?