From 66e6b35e9ff990c871d873137d1cb6e37d760378 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Mon, 12 Dec 2016 09:57:57 +0100 Subject: [PATCH] Reliable content length check in ResourceHandlerFunctionTests --- .../ResourceHandlerFunctionTests.java | 20 ++++++------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/spring-web-reactive/src/test/java/org/springframework/web/reactive/function/ResourceHandlerFunctionTests.java b/spring-web-reactive/src/test/java/org/springframework/web/reactive/function/ResourceHandlerFunctionTests.java index 53d0e33f73..76b2f23287 100644 --- a/spring-web-reactive/src/test/java/org/springframework/web/reactive/function/ResourceHandlerFunctionTests.java +++ b/spring-web-reactive/src/test/java/org/springframework/web/reactive/function/ResourceHandlerFunctionTests.java @@ -20,7 +20,6 @@ import java.io.IOException; import java.nio.file.Files; import java.util.EnumSet; -import org.junit.Before; import org.junit.Test; import reactor.core.publisher.Mono; import reactor.test.StepVerifier; @@ -36,24 +35,17 @@ import org.springframework.web.server.ServerWebExchange; import org.springframework.web.server.adapter.DefaultServerWebExchange; import org.springframework.web.server.session.MockWebSessionManager; -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; +import static org.junit.Assert.*; /** * @author Arjen Poutsma */ public class ResourceHandlerFunctionTests { - private Resource resource; + private final Resource resource = new ClassPathResource("response.txt", getClass()); - private ResourceHandlerFunction handlerFunction; + private final ResourceHandlerFunction handlerFunction = new ResourceHandlerFunction(this.resource); - @Before - public void createResource() { - this.resource = new ClassPathResource("response.txt", getClass()); - this.handlerFunction = new ResourceHandlerFunction(this.resource); - } @Test public void get() throws IOException { @@ -88,7 +80,7 @@ public class ResourceHandlerFunctionTests { .expectComplete() .verify(); assertEquals(MediaType.TEXT_PLAIN, mockResponse.getHeaders().getContentType()); - assertEquals(49, mockResponse.getHeaders().getContentLength()); + assertEquals(this.resource.contentLength(), mockResponse.getHeaders().getContentLength()); } @Test @@ -116,7 +108,7 @@ public class ResourceHandlerFunctionTests { .expectComplete() .verify(); assertEquals(MediaType.TEXT_PLAIN, mockResponse.getHeaders().getContentType()); - assertEquals(49, mockResponse.getHeaders().getContentLength()); + assertEquals(this.resource.contentLength(), mockResponse.getHeaders().getContentLength()); } @Test @@ -148,4 +140,4 @@ public class ResourceHandlerFunctionTests { assertNull(mockResponse.getBody()); } -} \ No newline at end of file +}