From 25586a2e23789e3c1160d7c597960417ece2b06e Mon Sep 17 00:00:00 2001 From: dreis2211 Date: Fri, 5 Jul 2019 19:53:03 +0200 Subject: [PATCH] Use Assertions.contentOf() where possible See gh-17444 --- ...LogFileWebEndpointAutoConfigurationTests.java | 8 ++------ .../actuate/logging/LogFileWebEndpointTests.java | 16 ++++------------ 2 files changed, 6 insertions(+), 18 deletions(-) diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/logging/LogFileWebEndpointAutoConfigurationTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/logging/LogFileWebEndpointAutoConfigurationTests.java index 2c5a22f44e..acda4f0055 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/logging/LogFileWebEndpointAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/logging/LogFileWebEndpointAutoConfigurationTests.java @@ -18,8 +18,6 @@ package org.springframework.boot.actuate.autoconfigure.logging; import java.io.File; import java.io.IOException; -import java.io.InputStream; -import java.nio.charset.StandardCharsets; import java.nio.file.Path; import org.junit.jupiter.api.Test; @@ -30,9 +28,9 @@ import org.springframework.boot.autoconfigure.AutoConfigurations; import org.springframework.boot.test.context.runner.WebApplicationContextRunner; import org.springframework.core.io.Resource; import org.springframework.util.FileCopyUtils; -import org.springframework.util.StreamUtils; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.contentOf; /** * Tests for {@link LogFileWebEndpointAutoConfiguration}. @@ -119,9 +117,7 @@ class LogFileWebEndpointAutoConfigurationTests { LogFileWebEndpoint endpoint = context.getBean(LogFileWebEndpoint.class); Resource resource = endpoint.logFile(); assertThat(resource).isNotNull(); - try (InputStream input = resource.getInputStream()) { - assertThat(StreamUtils.copyToString(input, StandardCharsets.UTF_8)).isEqualTo("--TEST--"); - } + assertThat(contentOf(resource.getFile())).isEqualTo("--TEST--"); }); } diff --git a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/logging/LogFileWebEndpointTests.java b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/logging/LogFileWebEndpointTests.java index 2e3ae7e5f2..0eb1be1cb2 100644 --- a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/logging/LogFileWebEndpointTests.java +++ b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/logging/LogFileWebEndpointTests.java @@ -18,8 +18,6 @@ package org.springframework.boot.actuate.logging; import java.io.File; import java.io.IOException; -import java.io.InputStream; -import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; @@ -30,9 +28,9 @@ import org.junit.jupiter.api.io.TempDir; import org.springframework.core.io.Resource; import org.springframework.mock.env.MockEnvironment; import org.springframework.util.FileCopyUtils; -import org.springframework.util.StreamUtils; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.contentOf; /** * Tests for {@link LogFileWebEndpoint}. @@ -71,7 +69,7 @@ class LogFileWebEndpointTests { this.environment.setProperty("logging.file.name", this.logFile.getAbsolutePath()); Resource resource = this.endpoint.logFile(); assertThat(resource).isNotNull(); - assertThat(contentOf(resource)).isEqualTo("--TEST--"); + assertThat(contentOf(resource.getFile())).isEqualTo("--TEST--"); } @Test @@ -80,7 +78,7 @@ class LogFileWebEndpointTests { this.environment.setProperty("logging.file", this.logFile.getAbsolutePath()); Resource resource = this.endpoint.logFile(); assertThat(resource).isNotNull(); - assertThat(contentOf(resource)).isEqualTo("--TEST--"); + assertThat(contentOf(resource.getFile())).isEqualTo("--TEST--"); } @Test @@ -88,13 +86,7 @@ class LogFileWebEndpointTests { LogFileWebEndpoint endpoint = new LogFileWebEndpoint(this.environment, this.logFile); Resource resource = endpoint.logFile(); assertThat(resource).isNotNull(); - assertThat(contentOf(resource)).isEqualTo("--TEST--"); - } - - private String contentOf(Resource resource) throws IOException { - try (InputStream input = resource.getInputStream()) { - return StreamUtils.copyToString(input, StandardCharsets.UTF_8); - } + assertThat(contentOf(resource.getFile())).isEqualTo("--TEST--"); } }