From 01ddee2201aa44d82ed3836ff5e12e304ad2abd0 Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Sat, 10 Oct 2020 08:23:28 +0200 Subject: [PATCH] Polish --- .../result/view/MustacheViewTests.java | 23 +++++++------------ 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/reactive/result/view/MustacheViewTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/reactive/result/view/MustacheViewTests.java index a43727f5d66..cecfd57d9a5 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/reactive/result/view/MustacheViewTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/reactive/result/view/MustacheViewTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,10 +21,10 @@ import java.time.Duration; import java.util.Collections; import com.samskivert.mustache.Mustache; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import reactor.test.StepVerifier; -import org.springframework.context.support.GenericApplicationContext; +import org.springframework.context.support.StaticApplicationContext; import org.springframework.http.MediaType; import org.springframework.mock.http.server.reactive.MockServerHttpRequest; import org.springframework.mock.web.server.MockServerWebExchange; @@ -41,27 +41,20 @@ class MustacheViewTests { private final String templateUrl = "classpath:/" + getClass().getPackage().getName().replace(".", "/") + "/template.html"; - private GenericApplicationContext context = new GenericApplicationContext(); - - private MockServerWebExchange exchange; - - @BeforeEach - void init() { - this.context.refresh(); - } + private final StaticApplicationContext context = new StaticApplicationContext(); @Test void viewResolvesHandlebars() { - this.exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/test").build()); + MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/test").build()); MustacheView view = new MustacheView(); view.setCompiler(Mustache.compiler()); view.setUrl(this.templateUrl); view.setCharset(StandardCharsets.UTF_8.displayName()); view.setApplicationContext(this.context); - view.render(Collections.singletonMap("World", "Spring"), MediaType.TEXT_HTML, this.exchange) + view.render(Collections.singletonMap("World", "Spring"), MediaType.TEXT_HTML, exchange) .block(Duration.ofSeconds(30)); - assertThat(this.exchange.getResponse().getBodyAsString().block(Duration.ofSeconds(30)).trim()) - .isEqualTo("Hello Spring"); + StepVerifier.create(exchange.getResponse().getBodyAsString()) + .assertNext((body) -> assertThat(body).isEqualToIgnoringWhitespace("Hello Spring")).verifyComplete(); } }