From f10caf6aa6a3ec5bfe229bf403a267d2e022f60e Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Tue, 4 Jun 2024 22:50:14 +0200 Subject: [PATCH] Compare text with system line separator (for Windows compatibility) See gh-32756 --- .../test/http/MediaTypeAssertTests.java | 11 ++++++----- .../http/codec/json/Jackson2JsonEncoderTests.java | 5 ++--- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/spring-test/src/test/java/org/springframework/test/http/MediaTypeAssertTests.java b/spring-test/src/test/java/org/springframework/test/http/MediaTypeAssertTests.java index c8b1d71ee78..c0dc306ff2b 100644 --- a/spring-test/src/test/java/org/springframework/test/http/MediaTypeAssertTests.java +++ b/spring-test/src/test/java/org/springframework/test/http/MediaTypeAssertTests.java @@ -16,7 +16,6 @@ package org.springframework.test.http; - import org.junit.jupiter.api.Test; import org.springframework.http.MediaType; @@ -63,11 +62,12 @@ class MediaTypeAssertTests { @Test void isEqualInvalidStringShouldFail() { + String ls = System.lineSeparator(); // output below is different between Unix and Windows assertThatExceptionOfType(AssertionError.class) .isThrownBy(() -> assertThat(mediaType("application/json")).isEqualTo("example of a bad value")) .withMessageContaining("[Media type]") - .withMessageEndingWith("To be a valid media type but got:\n" + - " \"Invalid mime type \"example of a bad value\": does not contain '/'\"\n"); + .withMessageEndingWith("To be a valid media type but got:" + ls + + " \"Invalid mime type \"example of a bad value\": does not contain '/'\"" + ls); } @Test @@ -108,11 +108,12 @@ class MediaTypeAssertTests { @Test void isNotEqualInvalidStringShouldFail() { + String ls = System.lineSeparator(); // output below is different between Unix and Windows assertThatExceptionOfType(AssertionError.class) .isThrownBy(() -> assertThat(mediaType("application/json")).isNotEqualTo("example of a bad value")) .withMessageContaining("[Media type]") - .withMessageEndingWith("To be a valid media type but got:\n" + - " \"Invalid mime type \"example of a bad value\": does not contain '/'\"\n"); + .withMessageEndingWith("To be a valid media type but got:" + ls + + " \"Invalid mime type \"example of a bad value\": does not contain '/'\"" + ls); } @Test diff --git a/spring-web/src/test/java/org/springframework/http/codec/json/Jackson2JsonEncoderTests.java b/spring-web/src/test/java/org/springframework/http/codec/json/Jackson2JsonEncoderTests.java index cc8400a0a30..a6652a5b97e 100644 --- a/spring-web/src/test/java/org/springframework/http/codec/json/Jackson2JsonEncoderTests.java +++ b/spring-web/src/test/java/org/springframework/http/codec/json/Jackson2JsonEncoderTests.java @@ -152,7 +152,7 @@ class Jackson2JsonEncoderTests extends AbstractEncoderTests .verifyComplete()); } - @Test // gh-29038 + @Test // gh-29038 void encodeNonStreamWithErrorAsFirstSignal() { String message = "I'm a teapot"; Flux input = Flux.error(new IllegalStateException(message)); @@ -264,8 +264,7 @@ class Jackson2JsonEncoderTests extends AbstractEncoderTests String ls = System.lineSeparator(); // output below is different between Unix and Windows testEncode(Mono.just(jacksonValue), type, halMediaType, Collections.emptyMap(), step -> step - .consumeNextWith(expectString("{" + ls + " \"withView1\" : \"with\"" + ls + "}") - ) + .consumeNextWith(expectString("{" + ls + " \"withView1\" : \"with\"" + ls + "}")) .verifyComplete() ); }