diff --git a/core/spring-boot/src/test/java/org/springframework/boot/logging/log4j2/ElasticCommonSchemaStructuredLogFormatterTests.java b/core/spring-boot/src/test/java/org/springframework/boot/logging/log4j2/ElasticCommonSchemaStructuredLogFormatterTests.java index 9a63f224913..2db7f407a45 100644 --- a/core/spring-boot/src/test/java/org/springframework/boot/logging/log4j2/ElasticCommonSchemaStructuredLogFormatterTests.java +++ b/core/spring-boot/src/test/java/org/springframework/boot/logging/log4j2/ElasticCommonSchemaStructuredLogFormatterTests.java @@ -101,13 +101,14 @@ class ElasticCommonSchemaStructuredLogFormatterTests extends AbstractStructuredL expectedError.put("message", "Boom"); assertThat(error).containsAllEntriesOf(expectedError); String stackTrace = (String) error.get("stack_trace"); - assertThat(stackTrace).startsWith( - """ - java.lang.RuntimeException: Boom - \tat org.springframework.boot.logging.log4j2.ElasticCommonSchemaStructuredLogFormatterTests.shouldFormatException"""); - assertThat(json).contains( - """ - java.lang.RuntimeException: Boom\\n\\tat org.springframework.boot.logging.log4j2.ElasticCommonSchemaStructuredLogFormatterTests.shouldFormatException"""); + assertThat(stackTrace) + .startsWith(String.format("java.lang.RuntimeException: Boom%n\tat org.springframework.boot.logging.log4j2." + + "ElasticCommonSchemaStructuredLogFormatterTests.shouldFormatException")); + assertThat(json).contains(String + .format("java.lang.RuntimeException: Boom%n\\tat org.springframework.boot.logging.log4j2." + + "ElasticCommonSchemaStructuredLogFormatterTests.shouldFormatException") + .replace("\n", "\\n") + .replace("\r", "\\r")); } @Test diff --git a/core/spring-boot/src/test/java/org/springframework/boot/logging/log4j2/GraylogExtendedLogFormatStructuredLogFormatterTests.java b/core/spring-boot/src/test/java/org/springframework/boot/logging/log4j2/GraylogExtendedLogFormatStructuredLogFormatterTests.java index 82708bc596e..9c52bca10cf 100644 --- a/core/spring-boot/src/test/java/org/springframework/boot/logging/log4j2/GraylogExtendedLogFormatStructuredLogFormatterTests.java +++ b/core/spring-boot/src/test/java/org/springframework/boot/logging/log4j2/GraylogExtendedLogFormatStructuredLogFormatterTests.java @@ -136,21 +136,18 @@ class GraylogExtendedLogFormatStructuredLogFormatterTests extends AbstractStruct String fullMessage = (String) deserialized.get("full_message"); String stackTrace = (String) deserialized.get("_error_stack_trace"); assertThat(fullMessage).startsWith( - """ - message - - java.lang.RuntimeException: Boom - \tat org.springframework.boot.logging.log4j2.GraylogExtendedLogFormatStructuredLogFormatterTests.shouldFormatException"""); - assertThat(stackTrace).startsWith( - """ - java.lang.RuntimeException: Boom - \tat org.springframework.boot.logging.log4j2.GraylogExtendedLogFormatStructuredLogFormatterTests.shouldFormatException"""); - + "message\n\njava.lang.RuntimeException: Boom%n\tat org.springframework.boot.logging.log4j2.GraylogExtendedLogFormatStructuredLogFormatterTests.shouldFormatException" + .formatted()); assertThat(deserialized) .containsAllEntriesOf(map("_error_type", "java.lang.RuntimeException", "_error_message", "Boom")); + assertThat(stackTrace).startsWith( + "java.lang.RuntimeException: Boom%n\tat org.springframework.boot.logging.log4j2.GraylogExtendedLogFormatStructuredLogFormatterTests.shouldFormatException" + .formatted()); assertThat(json).contains( - """ - message\\n\\njava.lang.RuntimeException: Boom\\n\\tat org.springframework.boot.logging.log4j2.GraylogExtendedLogFormatStructuredLogFormatterTests.shouldFormatException"""); + "java.lang.RuntimeException: Boom%n\\tat org.springframework.boot.logging.log4j2.GraylogExtendedLogFormatStructuredLogFormatterTests.shouldFormatException" + .formatted() + .replace("\n", "\\n") + .replace("\r", "\\r")); } @Test diff --git a/core/spring-boot/src/test/java/org/springframework/boot/logging/log4j2/LogstashStructuredLogFormatterTests.java b/core/spring-boot/src/test/java/org/springframework/boot/logging/log4j2/LogstashStructuredLogFormatterTests.java index 938b16dc07b..7014f7fbb58 100644 --- a/core/spring-boot/src/test/java/org/springframework/boot/logging/log4j2/LogstashStructuredLogFormatterTests.java +++ b/core/spring-boot/src/test/java/org/springframework/boot/logging/log4j2/LogstashStructuredLogFormatterTests.java @@ -80,12 +80,13 @@ class LogstashStructuredLogFormatterTests extends AbstractStructuredLoggingTests Map deserialized = deserialize(json); String stackTrace = (String) deserialized.get("stack_trace"); assertThat(stackTrace).startsWith( - """ - java.lang.RuntimeException: Boom - \tat org.springframework.boot.logging.log4j2.LogstashStructuredLogFormatterTests.shouldFormatException"""); + "java.lang.RuntimeException: Boom%n\tat org.springframework.boot.logging.log4j2.LogstashStructuredLogFormatterTests.shouldFormatException" + .formatted()); assertThat(json).contains( - """ - java.lang.RuntimeException: Boom\\n\\tat org.springframework.boot.logging.log4j2.LogstashStructuredLogFormatterTests.shouldFormatException"""); + "java.lang.RuntimeException: Boom%n\\tat org.springframework.boot.logging.log4j2.LogstashStructuredLogFormatterTests.shouldFormatException" + .formatted() + .replace("\n", "\\n") + .replace("\r", "\\r")); } @Test