Compare text with system line separator (for Windows compatibility)

See gh-32756
This commit is contained in:
Juergen Hoeller 2024-06-04 22:50:14 +02:00
parent cf3171dae0
commit f10caf6aa6
2 changed files with 8 additions and 8 deletions

View File

@ -16,7 +16,6 @@
package org.springframework.test.http; package org.springframework.test.http;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
@ -63,11 +62,12 @@ class MediaTypeAssertTests {
@Test @Test
void isEqualInvalidStringShouldFail() { void isEqualInvalidStringShouldFail() {
String ls = System.lineSeparator(); // output below is different between Unix and Windows
assertThatExceptionOfType(AssertionError.class) assertThatExceptionOfType(AssertionError.class)
.isThrownBy(() -> assertThat(mediaType("application/json")).isEqualTo("example of a bad value")) .isThrownBy(() -> assertThat(mediaType("application/json")).isEqualTo("example of a bad value"))
.withMessageContaining("[Media type]") .withMessageContaining("[Media type]")
.withMessageEndingWith("To be a valid media type but got:\n" + .withMessageEndingWith("To be a valid media type but got:" + ls +
" \"Invalid mime type \"example of a bad value\": does not contain '/'\"\n"); " \"Invalid mime type \"example of a bad value\": does not contain '/'\"" + ls);
} }
@Test @Test
@ -108,11 +108,12 @@ class MediaTypeAssertTests {
@Test @Test
void isNotEqualInvalidStringShouldFail() { void isNotEqualInvalidStringShouldFail() {
String ls = System.lineSeparator(); // output below is different between Unix and Windows
assertThatExceptionOfType(AssertionError.class) assertThatExceptionOfType(AssertionError.class)
.isThrownBy(() -> assertThat(mediaType("application/json")).isNotEqualTo("example of a bad value")) .isThrownBy(() -> assertThat(mediaType("application/json")).isNotEqualTo("example of a bad value"))
.withMessageContaining("[Media type]") .withMessageContaining("[Media type]")
.withMessageEndingWith("To be a valid media type but got:\n" + .withMessageEndingWith("To be a valid media type but got:" + ls +
" \"Invalid mime type \"example of a bad value\": does not contain '/'\"\n"); " \"Invalid mime type \"example of a bad value\": does not contain '/'\"" + ls);
} }
@Test @Test

View File

@ -152,7 +152,7 @@ class Jackson2JsonEncoderTests extends AbstractEncoderTests<Jackson2JsonEncoder>
.verifyComplete()); .verifyComplete());
} }
@Test // gh-29038 @Test // gh-29038
void encodeNonStreamWithErrorAsFirstSignal() { void encodeNonStreamWithErrorAsFirstSignal() {
String message = "I'm a teapot"; String message = "I'm a teapot";
Flux<Object> input = Flux.error(new IllegalStateException(message)); Flux<Object> input = Flux.error(new IllegalStateException(message));
@ -264,8 +264,7 @@ class Jackson2JsonEncoderTests extends AbstractEncoderTests<Jackson2JsonEncoder>
String ls = System.lineSeparator(); // output below is different between Unix and Windows String ls = System.lineSeparator(); // output below is different between Unix and Windows
testEncode(Mono.just(jacksonValue), type, halMediaType, Collections.emptyMap(), step -> step testEncode(Mono.just(jacksonValue), type, halMediaType, Collections.emptyMap(), step -> step
.consumeNextWith(expectString("{" + ls + " \"withView1\" : \"with\"" + ls + "}") .consumeNextWith(expectString("{" + ls + " \"withView1\" : \"with\"" + ls + "}"))
)
.verifyComplete() .verifyComplete()
); );
} }