WIP spec-stub-holzweg
authorKai Moritz <kai@juplo.de>
Sat, 11 Jan 2020 16:44:51 +0000 (17:44 +0100)
committerKai Moritz <kai@juplo.de>
Sat, 11 Jan 2020 16:44:51 +0000 (17:44 +0100)
src/test/java/de/juplo/demo/RemoteContentServiceTest.java

index a8cecab..e5942d6 100644 (file)
@@ -4,9 +4,13 @@ package de.juplo.demo;
 import java.net.URI;
 import java.nio.charset.Charset;
 import java.time.ZonedDateTime;
 import java.net.URI;
 import java.nio.charset.Charset;
 import java.time.ZonedDateTime;
+import java.util.List;
 import java.util.Map;
 import java.util.function.Consumer;
 import java.util.function.Function;
 import java.util.Map;
 import java.util.function.Consumer;
 import java.util.function.Function;
+import java.util.function.IntPredicate;
+import java.util.function.Predicate;
+import java.util.function.Supplier;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 import org.junit.jupiter.api.extension.ExtendWith;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 import org.junit.jupiter.api.extension.ExtendWith;
@@ -17,7 +21,9 @@ 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.core.ParameterizedTypeReference;
 import org.springframework.http.HttpHeaders;
 import org.springframework.http.HttpMethod;
+import org.springframework.http.HttpStatus;
 import org.springframework.http.MediaType;
 import org.springframework.http.MediaType;
+import org.springframework.http.ResponseEntity;
 import org.springframework.http.client.reactive.ClientHttpRequest;
 import org.springframework.test.context.junit.jupiter.SpringExtension;
 import org.springframework.util.MultiValueMap;
 import org.springframework.http.client.reactive.ClientHttpRequest;
 import org.springframework.test.context.junit.jupiter.SpringExtension;
 import org.springframework.util.MultiValueMap;
@@ -28,6 +34,7 @@ import org.springframework.web.reactive.function.client.WebClient.RequestHeaders
 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 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.Flux;
 import reactor.core.publisher.Mono;
 import reactor.test.StepVerifier;
 
 import reactor.core.publisher.Mono;
 import reactor.test.StepVerifier;
 
@@ -78,8 +85,12 @@ public class RemoteContentServiceTest
   static class WebClientStub implements WebClient
   {
     final static WebClientStub WEB_CLIENT = new WebClientStub();
   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();
+    final static RequestHeadersUriSpecStub HEADERS_SPEC = new RequestHeadersUriSpecStub();
+    final static RequestBodySpecStub REQUEST_BODY_SPEC = new RequestBodySpecStub();
+    final static ResponseSpecStub RESPONSE_SPEC = new ResponseSpecStub();
+
+    static Supplier<Mono<?>> toMono;
+    static Supplier<Flux<?>> toFlux;
 
 
     private WebClientStub() {}
 
 
     private WebClientStub() {}
@@ -88,49 +99,49 @@ public class RemoteContentServiceTest
     @Override
     public RequestHeadersUriSpec<?> get()
     {
     @Override
     public RequestHeadersUriSpec<?> get()
     {
-      return URI_SPEC;
+      return HEADERS_SPEC;
     }
 
     @Override
     public RequestHeadersUriSpec<?> head()
     {
     }
 
     @Override
     public RequestHeadersUriSpec<?> head()
     {
-      return URI_SPEC;
+      return HEADERS_SPEC;
     }
 
     @Override
     public RequestBodyUriSpec post()
     {
     }
 
     @Override
     public RequestBodyUriSpec post()
     {
-      return BODY_SPEC;
+      return REQUEST_BODY_SPEC;
     }
 
     @Override
     public RequestBodyUriSpec put()
     {
     }
 
     @Override
     public RequestBodyUriSpec put()
     {
-      return BODY_SPEC;
+      return REQUEST_BODY_SPEC;
     }
 
     @Override
     public RequestBodyUriSpec patch()
     {
     }
 
     @Override
     public RequestBodyUriSpec patch()
     {
-      return BODY_SPEC;
+      return REQUEST_BODY_SPEC;
     }
 
     @Override
     public RequestHeadersUriSpec<?> delete()
     {
     }
 
     @Override
     public RequestHeadersUriSpec<?> delete()
     {
-      return URI_SPEC;
+      return HEADERS_SPEC;
     }
 
     @Override
     public RequestHeadersUriSpec<?> options()
     {
     }
 
     @Override
     public RequestHeadersUriSpec<?> options()
     {
-      return URI_SPEC;
+      return HEADERS_SPEC;
     }
 
     @Override
     public RequestBodyUriSpec method(HttpMethod hm)
     {
     }
 
     @Override
     public RequestBodyUriSpec method(HttpMethod hm)
     {
-      return BODY_SPEC;
+      return REQUEST_BODY_SPEC;
     }
 
     @Override
     }
 
     @Override
@@ -238,11 +249,13 @@ public class RemoteContentServiceTest
       @Override
       public ResponseSpec retrieve()
       {
       @Override
       public ResponseSpec retrieve()
       {
+        return RESPONSE_SPEC;
       }
 
       @Override
       public Mono exchange()
       {
       }
 
       @Override
       public Mono exchange()
       {
+        return WebClientStub.toMono.get();
       }
     }
 
       }
     }
 
@@ -407,5 +420,77 @@ public class RemoteContentServiceTest
         return this;
       }
     }
         return this;
       }
     }
+
+    static class ResponseSpecStub implements ResponseSpec
+    {
+      private ResponseSpecStub() {}
+
+
+      @Override
+      public ResponseSpec onStatus(Predicate<HttpStatus> statusPredicate, Function<ClientResponse, Mono<? extends Throwable>> exceptionFunction)
+      {
+        return this;
+      }
+
+      @Override
+      public ResponseSpec onRawStatus(IntPredicate statusCodePredicate, Function<ClientResponse, Mono<? extends Throwable>> exceptionFunction)
+      {
+        return this;
+      }
+
+      @Override
+      public <T> Mono<T> bodyToMono(Class<T> elementClass)
+      {
+        return (Mono<T>)toMono.get();
+      }
+
+      @Override
+      public <T> Mono<T> bodyToMono(ParameterizedTypeReference<T> elementTypeRef)
+      {
+        return (Mono<T>)toMono.get();
+      }
+
+      @Override
+      public <T> Flux<T> bodyToFlux(Class<T> elementClass)
+      {
+        return (Flux<T>)toFlux;
+      }
+
+      @Override
+      public <T> Flux<T> bodyToFlux(ParameterizedTypeReference<T> elementTypeRef)
+      {
+        return (Flux<T>)toFlux;
+      }
+
+      @Override
+      public <T> Mono<ResponseEntity<T>> toEntity(Class<T> bodyClass)
+      {
+        return (Mono<ResponseEntity<T>>)toMono.get();
+      }
+
+      @Override
+      public <T> Mono<ResponseEntity<T>> toEntity(ParameterizedTypeReference<T> bodyTypeReference)
+      {
+        return (Mono<ResponseEntity<T>>)toMono.get();
+      }
+
+      @Override
+      public <T> Mono<ResponseEntity<List<T>>> toEntityList(Class<T> elementClass)
+      {
+        return (Mono<ResponseEntity<List<T>>>)toMono.get();
+      }
+
+      @Override
+      public <T> Mono<ResponseEntity<List<T>>> toEntityList(ParameterizedTypeReference<T> elementTypeRef)
+      {
+        return (Mono<ResponseEntity<List<T>>>)toMono.get();
+      }
+
+      @Override
+      public Mono<ResponseEntity<Void>> toBodilessEntity()
+      {
+        return (Mono<ResponseEntity<Void>>)toMono.get();
+      }
+    }
   }
 }
   }
 }