+++ /dev/null
-package de.juplo.demo;
-
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.RequestParam;
-import org.springframework.web.bind.annotation.RestController;
-import reactor.core.publisher.Mono;
-
-
-/**
- * Fetches data from remote-webserver and renders them as HTML.
- * @author Kai Moritz
- */
-@RestController
-public class RemoteContentController
-{
- @Autowired
- RemoteContentService service;
-
-
- @GetMapping("/")
- public Mono<String> renderRemoteText(@RequestParam String path)
- {
- return service.getRemoteText(path);
- }
-}
--- /dev/null
+package de.juplo.demo;
+
+
+import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
+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.mockito.junit.jupiter.MockitoExtension;
+import org.springframework.boot.test.mock.mockito.MockBean;
+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 reactor.core.publisher.Mono;
+
+
+/**
+ * Unit-Test for class {@link RemoteContentService}.
+ * @author Kai Moritz
+ */
+@ExtendWith(MockitoExtension.class)
+public class RemoteContentServiceTest
+{
+ RemoteContentService service;
+
+ @MockBean
+ WebClient webClient;
+ @MockBean
+ RequestHeadersUriSpec uriSpec;
+ @MockBean
+ RequestHeadersSpec headersSpec;
+ @MockBean
+ ResponseSpec responseSpec;
+
+
+ @Test
+ void test()
+ {
+ when(webClient.get()).thenReturn(uriSpec);
+ when(uriSpec.uri(eq("/foo"))).thenReturn(headersSpec);
+ when(headersSpec.retrieve()).thenReturn(responseSpec);
+ when(responseSpec.bodyToMono(String.class)).thenReturn(Mono.just("bar"));
+
+ Mono<String> result = service.getRemoteText("/foo");
+
+ assertThat(result).isNotNull();
+ assertThat(result.block()).isEqualTo("bar");
+ }
+}