package de.juplo.demo;
+import java.net.URI;
+import java.nio.charset.Charset;
+import java.time.ZonedDateTime;
+import java.util.Map;
+import java.util.function.Consumer;
+import java.util.function.Function;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.when;
+import org.reactivestreams.Publisher;
import org.springframework.boot.test.mock.mockito.MockBean;
+import org.springframework.core.ParameterizedTypeReference;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.HttpMethod;
+import org.springframework.http.MediaType;
+import org.springframework.http.client.reactive.ClientHttpRequest;
import org.springframework.test.context.junit.jupiter.SpringExtension;
+import org.springframework.util.MultiValueMap;
+import org.springframework.web.reactive.function.BodyInserter;
+import org.springframework.web.reactive.function.client.ClientResponse;
import org.springframework.web.reactive.function.client.WebClient;
import org.springframework.web.reactive.function.client.WebClient.RequestHeadersSpec;
import org.springframework.web.reactive.function.client.WebClient.RequestHeadersUriSpec;
import org.springframework.web.reactive.function.client.WebClient.ResponseSpec;
+import org.springframework.web.util.UriBuilder;
import reactor.core.publisher.Mono;
import reactor.test.StepVerifier;
.expectNext("bar")
.verifyComplete();
}
+
+
+ static class WebClientStub implements WebClient
+ {
+ final static WebClientStub WEB_CLIENT = new WebClientStub();
+ final static RequestHeadersUriSpecStub URI_SPEC = new RequestHeadersUriSpecStub();
+ final static RequestBodySpecStub BODY_SPEC = new RequestBodySpecStub();
+
+
+ private WebClientStub() {}
+
+
+ @Override
+ public RequestHeadersUriSpec<?> get()
+ {
+ return URI_SPEC;
+ }
+
+ @Override
+ public RequestHeadersUriSpec<?> head()
+ {
+ return URI_SPEC;
+ }
+
+ @Override
+ public RequestBodyUriSpec post()
+ {
+ return BODY_SPEC;
+ }
+
+ @Override
+ public RequestBodyUriSpec put()
+ {
+ return BODY_SPEC;
+ }
+
+ @Override
+ public RequestBodyUriSpec patch()
+ {
+ return BODY_SPEC;
+ }
+
+ @Override
+ public RequestHeadersUriSpec<?> delete()
+ {
+ return URI_SPEC;
+ }
+
+ @Override
+ public RequestHeadersUriSpec<?> options()
+ {
+ return URI_SPEC;
+ }
+
+ @Override
+ public RequestBodyUriSpec method(HttpMethod hm)
+ {
+ return BODY_SPEC;
+ }
+
+ @Override
+ public Builder mutate()
+ {
+ throw new UnsupportedOperationException("Stub is immutable!");
+ }
+
+
+ static class RequestHeadersUriSpecStub implements RequestHeadersUriSpec
+ {
+ private RequestHeadersUriSpecStub() {}
+
+
+ @Override
+ public RequestHeadersSpec uri(URI uri)
+ {
+ return this;
+ }
+
+ @Override
+ public RequestHeadersSpec uri(String string, Object... os)
+ {
+ return this;
+ }
+
+ @Override
+ public RequestHeadersSpec uri(String string, Map map)
+ {
+ return this;
+ }
+
+ @Override
+ public RequestHeadersSpec uri(String string, Function fnctn)
+ {
+ return this;
+ }
+
+ @Override
+ public RequestHeadersSpec uri(Function fnctn)
+ {
+ return this;
+ }
+
+ @Override
+ public RequestHeadersSpec accept(MediaType... mts)
+ {
+ return this;
+ }
+
+ @Override
+ public RequestHeadersSpec acceptCharset(Charset... chrsts)
+ {
+ return this;
+ }
+
+ @Override
+ public RequestHeadersSpec cookie(String string, String string1)
+ {
+ return this;
+ }
+
+ @Override
+ public RequestHeadersSpec cookies(Consumer cnsmr)
+ {
+ return this;
+ }
+
+ @Override
+ public RequestHeadersSpec ifModifiedSince(ZonedDateTime zdt)
+ {
+ return this;
+ }
+
+ @Override
+ public RequestHeadersSpec ifNoneMatch(String... strings)
+ {
+ return this;
+ }
+
+ @Override
+ public RequestHeadersSpec header(String string, String... strings)
+ {
+ return this;
+ }
+
+ @Override
+ public RequestHeadersSpec headers(Consumer cnsmr)
+ {
+ return this;
+ }
+
+ @Override
+ public RequestHeadersSpec attribute(String string, Object o)
+ {
+ return this;
+ }
+
+ @Override
+ public RequestHeadersSpec attributes(Consumer cnsmr)
+ {
+ return this;
+ }
+
+ @Override
+ public ResponseSpec retrieve()
+ {
+ }
+
+ @Override
+ public Mono exchange()
+ {
+ }
+ }
+
+ static class RequestBodySpecStub implements RequestBodyUriSpec
+ {
+ private RequestBodySpecStub() {}
+
+
+ @Override
+ public RequestBodySpec contentLength(long l)
+ {
+ return this;
+ }
+
+ @Override
+ public RequestBodySpec contentType(MediaType mt)
+ {
+ return this;
+ }
+
+ @Override
+ public RequestHeadersSpec<?> bodyValue(Object o)
+ {
+ return this;
+ }
+
+ @Override
+ public <T, P extends Publisher<T>> RequestHeadersSpec<?> body(P p, Class<T> type)
+ {
+ return this;
+ }
+
+ @Override
+ public <T, P extends Publisher<T>> RequestHeadersSpec<?> body(P p, ParameterizedTypeReference<T> ptr)
+ {
+ return this;
+ }
+
+ @Override
+ public RequestHeadersSpec<?> body(Object o, Class<?> type)
+ {
+ return this;
+ }
+
+ @Override
+ public RequestHeadersSpec<?> body(Object o, ParameterizedTypeReference<?> ptr)
+ {
+ return this;
+ }
+
+ @Override
+ public RequestHeadersSpec<?> body( BodyInserter<?, ? super ClientHttpRequest> bi)
+ {
+ return this;
+ }
+
+ @Override
+ public RequestHeadersSpec<?> syncBody(Object o)
+ {
+ return this;
+ }
+
+ @Override
+ public RequestBodySpec accept(MediaType... mts)
+ {
+ return this;
+ }
+
+ @Override
+ public RequestBodySpec acceptCharset(Charset... chrsts)
+ {
+ return this;
+ }
+
+ @Override
+ public RequestBodySpec cookie(String string, String string1)
+ {
+ return this;
+ }
+
+ @Override
+ public RequestBodySpec cookies(Consumer<MultiValueMap<String, String>> cnsmr)
+ {
+ return this;
+ }
+
+ @Override
+ public RequestBodySpec ifModifiedSince(ZonedDateTime zdt)
+ {
+ return this;
+ }
+
+ @Override
+ public RequestBodySpec ifNoneMatch(String... strings)
+ {
+ return this;
+ }
+
+ @Override
+ public RequestBodySpec header(String string, String... strings)
+ {
+ return this;
+ }
+
+ @Override
+ public RequestBodySpec headers(Consumer<HttpHeaders> cnsmr)
+ {
+ return this;
+ }
+
+ @Override
+ public RequestBodySpec attribute(String string, Object o)
+ {
+ return this;
+ }
+
+ @Override
+ public RequestBodySpec attributes(Consumer<Map<String, Object>> cnsmr)
+ {
+ return this;
+ }
+
+ @Override
+ public ResponseSpec retrieve()
+ {
+ throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
+ }
+
+ @Override
+ public Mono<ClientResponse> exchange()
+ {
+ throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
+ }
+
+ @Override
+ public RequestBodySpec uri(URI uri)
+ {
+ return this;
+ }
+
+ @Override
+ public RequestBodySpec uri(String string, Object... os)
+ {
+ return this;
+ }
+
+ @Override
+ public RequestBodySpec uri(String string, Map<String, ?> map)
+ {
+ return this;
+ }
+
+ @Override
+ public RequestBodySpec uri(String string, Function<UriBuilder, URI> fnctn)
+ {
+ return this;
+ }
+
+ @Override
+ public RequestBodySpec uri(Function<UriBuilder, URI> fnctn)
+ {
+ return this;
+ }
+ }
+ }
}