Commit 01ddee22 authored by Stephane Nicoll's avatar Stephane Nicoll

Polish

parent 0f9e8315
/* /*
* 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -21,10 +21,10 @@ import java.time.Duration; ...@@ -21,10 +21,10 @@ import java.time.Duration;
import java.util.Collections; import java.util.Collections;
import com.samskivert.mustache.Mustache; import com.samskivert.mustache.Mustache;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test; 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.http.MediaType;
import org.springframework.mock.http.server.reactive.MockServerHttpRequest; import org.springframework.mock.http.server.reactive.MockServerHttpRequest;
import org.springframework.mock.web.server.MockServerWebExchange; import org.springframework.mock.web.server.MockServerWebExchange;
...@@ -41,27 +41,20 @@ class MustacheViewTests { ...@@ -41,27 +41,20 @@ class MustacheViewTests {
private final String templateUrl = "classpath:/" + getClass().getPackage().getName().replace(".", "/") private final String templateUrl = "classpath:/" + getClass().getPackage().getName().replace(".", "/")
+ "/template.html"; + "/template.html";
private GenericApplicationContext context = new GenericApplicationContext(); private final StaticApplicationContext context = new StaticApplicationContext();
private MockServerWebExchange exchange;
@BeforeEach
void init() {
this.context.refresh();
}
@Test @Test
void viewResolvesHandlebars() { void viewResolvesHandlebars() {
this.exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/test").build()); MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/test").build());
MustacheView view = new MustacheView(); MustacheView view = new MustacheView();
view.setCompiler(Mustache.compiler()); view.setCompiler(Mustache.compiler());
view.setUrl(this.templateUrl); view.setUrl(this.templateUrl);
view.setCharset(StandardCharsets.UTF_8.displayName()); view.setCharset(StandardCharsets.UTF_8.displayName());
view.setApplicationContext(this.context); 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)); .block(Duration.ofSeconds(30));
assertThat(this.exchange.getResponse().getBodyAsString().block(Duration.ofSeconds(30)).trim()) StepVerifier.create(exchange.getResponse().getBodyAsString())
.isEqualTo("Hello Spring"); .assertNext((body) -> assertThat(body).isEqualToIgnoringWhitespace("Hello Spring")).verifyComplete();
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment