--- /dev/null
+package de.juplo.demo;
+
+
+import org.springframework.stereotype.Controller;
+import org.springframework.ui.Model;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+
+
+/**
+ * Fetches data from a remote-webserver and renders it as HTML.
+ * @author Kai Moritz
+ */
+@Controller
+public class HtmlController
+{
+ RemoteContentService service;
+
+
+ public HtmlController(RemoteContentService service)
+ {
+ this.service = service;
+ }
+
+
+ @GetMapping("/")
+ public String fetch(Model model, @RequestParam String path)
+ {
+ model.addAttribute("text", service.getRemoteText(path));
+ return "layout";
+ }
+}
--- /dev/null
+<!doctype html>
+<html xmlns:th="http://www.thymeleaf.org" lang="en">
+ <head>
+ <meta charset="utf-8">
+ <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
+ <title>Shows Remote-Content</title>
+ <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
+ </head>
+ <body>
+ <nav class="navbar navbar-dark bg-primary navbar-expand navbar-dark flex-column">
+ <h2 class="navbar-brand">Demo: Unit-Test or Integration-Test — A Practical Guide</h2>
+ </nav>
+ <main class="container mt-5">
+ <div class="card">
+ <div class="card-header" id="content"><h1>Information About Fetched Data</h1></div>
+ <div class="card-body">
+ <p class="card-text"><pre th:text="${text}">TEXT</pre></p>
+ </div>
+ </div>
+ </main>
+ </body>
+</html>
--- /dev/null
+package de.juplo.demo;
+
+
+import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.DisplayName;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.ArgumentCaptor;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+import org.springframework.boot.test.mock.mockito.MockBean;
+import org.springframework.test.context.junit.jupiter.SpringExtension;
+import org.springframework.ui.Model;
+import reactor.core.publisher.Mono;
+import reactor.test.StepVerifier;
+
+
+/**
+ * Unit-Test for class {@link RemoteContentHtmlController}.
+ * @author Kai Moritz
+ */
+@ExtendWith(SpringExtension.class)
+public class HtmlControllerTest
+{
+ HtmlController controller;
+
+ @MockBean
+ RemoteContentService service;
+ @MockBean
+ Model model;
+
+
+ @BeforeEach
+ void setUp()
+ {
+ controller = new HtmlController(service);
+ }
+
+
+ @Test
+ @DisplayName("Data successfully fetched from remote-server")
+ void testOK()
+ {
+ when(service.getRemoteText("foo")).thenReturn(Mono.just("bar"));
+
+ String result = controller.fetch(model, "foo");
+
+ assertThat(result).isEqualTo("layout");
+ ArgumentCaptor<Mono<String>> captor = ArgumentCaptor.forClass(Mono.class);
+ verify(model).addAttribute(eq("text"), captor.capture());
+ StepVerifier
+ .create(captor.getValue())
+ .expectNext("bar")
+ .expectComplete()
+ .verify();
+ }
+}