X-Git-Url: https://juplo.de/gitweb/?a=blobdiff_plain;f=src%2Ftest%2Fjava%2Fde%2Fjuplo%2Fdemo%2FRemoteContentServiceTest.java;h=a396d6cca6c794f306ed2a5fb51415c68036a500;hb=914b56733fa8bc671107808b97ee7175a4053dc3;hp=ac1488e546fa116e815f6eaa242222b03a282fed;hpb=261ba91233d309eabe0ee048776ebdcc5ff1152e;p=demos%2Ftesting diff --git a/src/test/java/de/juplo/demo/RemoteContentServiceTest.java b/src/test/java/de/juplo/demo/RemoteContentServiceTest.java index ac1488e..a396d6c 100644 --- a/src/test/java/de/juplo/demo/RemoteContentServiceTest.java +++ b/src/test/java/de/juplo/demo/RemoteContentServiceTest.java @@ -1,27 +1,11 @@ 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 static org.assertj.core.api.AssertionsForClassTypes.assertThat; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.when; -import org.springframework.boot.test.mock.mockito.MockBean; -import org.springframework.http.HttpMethod; -import org.springframework.http.MediaType; import org.springframework.test.context.junit.jupiter.SpringExtension; -import org.springframework.web.reactive.function.client.ClientResponse; -import org.springframework.web.reactive.function.client.WebClient; -import org.springframework.web.reactive.function.client.WebClient.RequestBodyUriSpec; -import org.springframework.web.reactive.function.client.WebClient.RequestHeadersUriSpec; -import org.springframework.web.reactive.function.client.WebClient.ResponseSpec; import reactor.core.publisher.Mono; @@ -34,22 +18,11 @@ public class RemoteContentServiceTest { RemoteContentService service; - @MockBean - WebClient webClient; - @MockBean - RequestHeadersUriSpec headersSpec; - @MockBean - RequestBodyUriSpec bodySpec; - @MockBean - ResponseSpec responseSpec; - @MockBean - ClientResponse clientResponse; - @BeforeEach void setUp() { - service = new RemoteContentService(webClient); + service = new RemoteContentService(WebClientStub.WEB_CLIENT); } @@ -57,47 +30,7 @@ public class RemoteContentServiceTest void test() { Mono mono = Mono.just("bar"); - - when(webClient.options()).thenReturn(headersSpec); - when(webClient.head()).thenReturn(headersSpec); - when(webClient.get()).thenReturn(headersSpec); - when(webClient.method(any(HttpMethod.class))).thenReturn(bodySpec); - when(headersSpec.uri(any(URI.class))).thenReturn(headersSpec); - when(headersSpec.uri(any(String.class), any(Function.class))).thenReturn(headersSpec); - when(headersSpec.uri(any(String.class), any(Map.class))).thenReturn(headersSpec); - when(headersSpec.uri(any(String.class), (Object[])any())).thenReturn(headersSpec); - when(headersSpec.uri(any(Function.class))).thenReturn(headersSpec); - when(headersSpec.accept((MediaType[])any())).thenReturn(headersSpec); - when(headersSpec.acceptCharset((Charset[])any())).thenReturn(headersSpec); - when(headersSpec.attribute(any(String.class), any(Object.class))).thenReturn(headersSpec); - when(headersSpec.cookie(any(String.class), any(String.class))).thenReturn(headersSpec); - when(headersSpec.cookies(any(Consumer.class))).thenReturn(headersSpec); - when(headersSpec.exchange()).thenReturn(mono); - when(headersSpec.header(any(String.class), (String[])any())).thenReturn(headersSpec); - when(headersSpec.headers(any(Consumer.class))).thenReturn(headersSpec); - when(headersSpec.ifModifiedSince(any(ZonedDateTime.class))).thenReturn(headersSpec); - when(headersSpec.ifNoneMatch((String[])any())).thenReturn(headersSpec); - when(headersSpec.retrieve()).thenReturn(responseSpec); - when(bodySpec.uri(any(URI.class))).thenReturn(bodySpec); - when(bodySpec.uri(any(String.class), any(Function.class))).thenReturn(bodySpec); - when(bodySpec.uri(any(String.class), any(Map.class))).thenReturn(bodySpec); - when(bodySpec.uri(any(String.class), (Object[])any())).thenReturn(bodySpec); - when(bodySpec.uri(any(Function.class))).thenReturn(bodySpec); - when(bodySpec.accept((MediaType[])any())).thenReturn(bodySpec); - when(bodySpec.acceptCharset((Charset[])any())).thenReturn(bodySpec); - when(bodySpec.attribute(any(String.class), any(Object.class))).thenReturn(bodySpec); - when(bodySpec.cookie(any(String.class), any(String.class))).thenReturn(bodySpec); - when(bodySpec.cookies(any(Consumer.class))).thenReturn(bodySpec); - when(bodySpec.exchange()).thenReturn(Mono.just(clientResponse)); - when(bodySpec.header(any(String.class), (String[])any())).thenReturn(bodySpec); - when(bodySpec.headers(any(Consumer.class))).thenReturn(bodySpec); - when(bodySpec.ifModifiedSince(any(ZonedDateTime.class))).thenReturn(bodySpec); - when(bodySpec.ifNoneMatch((String[])any())).thenReturn(bodySpec); - when(bodySpec.contentLength(any(Long.class))).thenReturn(bodySpec); - when(bodySpec.contentType(any(MediaType.class))).thenReturn(bodySpec); - when(bodySpec.retrieve()).thenReturn(responseSpec); - when(responseSpec.bodyToMono(String.class)).thenReturn(mono); - when(clientResponse.bodyToMono(String.class)).thenReturn(mono); + WebClientStub.expect(mono); Mono result = service.getRemoteText("/foo");