Avoid issues with system line separator in tests

See f10caf6aa6
This commit is contained in:
Sam Brannen
2024-06-05 12:16:12 +02:00
parent f4f89aa2a4
commit 9e1ef83669
5 changed files with 18 additions and 22 deletions

View File

@@ -262,9 +262,11 @@ class Jackson2JsonEncoderTests extends AbstractEncoderTests<Jackson2JsonEncoder>
ObjectMapper mapper = new ObjectMapper().configure(SerializationFeature.INDENT_OUTPUT, true);
this.encoder.registerObjectMappersForType(JacksonViewBean.class, map -> map.put(halMediaType, mapper));
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("""
{
\s "withView1" : "with"
}"""))
.verifyComplete()
);
}

View File

@@ -63,8 +63,6 @@ import static org.assertj.core.api.Assertions.within;
*/
class MappingJackson2HttpMessageConverterTests {
protected static final String NEWLINE_SYSTEM_PROPERTY = System.lineSeparator();
private final MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter();
@@ -369,8 +367,10 @@ class MappingJackson2HttpMessageConverterTests {
this.converter.writeInternal(bean, null, outputMessage);
String result = outputMessage.getBodyAsString(StandardCharsets.UTF_8);
assertThat(result).isEqualTo(("{" + NEWLINE_SYSTEM_PROPERTY +
" \"name\" : \"Jason\"" + NEWLINE_SYSTEM_PROPERTY + "}"));
assertThat(result).isEqualToNormalizingNewlines("""
{
\s "name" : "Jason"
}""");
}
@Test