WebServiceClient { public void intercept(WebServiceClientInterceptor interceptor) { if (this.interceptor != null) throw new Error("found duplicate interceptor, previous=" + this.interceptor.getClass().getCanonicalName()); this.interceptor = interceptor; } WebServiceClient(String serviceURL, HTTPClient httpClient, RequestBeanWriter writer, ResponseBeanReader reader); Object execute(HTTPMethod method, String path, Class<T> requestBeanClass, T requestBean, Type responseType); void intercept(WebServiceClientInterceptor interceptor); void logCallWebService(String method); static final String USER_AGENT; }
@Test void intercept() { WebServiceClientInterceptor interceptor = mock(WebServiceClientInterceptor.class); webServiceClient.intercept(interceptor); var response = new HTTPResponse(200, Map.of(), new byte[0]); when(httpClient.execute(any())).thenReturn(response); webServiceClient.execute(HTTPMethod.GET, "/api", null, null, void.class); verify(interceptor).onRequest(argThat(request -> request.method == HTTPMethod.GET && "http: verify(interceptor).onResponse(response); }