Browse Source

Fix Jackson custom locale with Joda Time test on Java 9

The translations for the timezone names vary between Java 8 and Java
9. For example, with Java 9, UTC's name is no longer localized while
others have different localizations. This commit updates the test
to verify that the correct locale is being used while also tolerating
the different localization's of Java 8 and 9.

See gh-7226
pull/10447/head
Andy Wilkinson 8 years ago
parent
commit
2c2b9be4be
  1. 24
      spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jackson/JacksonAutoConfigurationTests.java

24
spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jackson/JacksonAutoConfigurationTests.java

@ -412,17 +412,19 @@ public class JacksonAutoConfigurationTests { @@ -412,17 +412,19 @@ public class JacksonAutoConfigurationTests {
}
@Test
public void customLocale() throws JsonProcessingException {
this.context.register(JacksonAutoConfiguration.class);
TestPropertyValues.of("spring.jackson.locale:de").applyTo(this.context);
TestPropertyValues.of("spring.jackson.date-format:zzzz").applyTo(this.context);
this.context.refresh();
ObjectMapper objectMapper = this.context
.getBean(Jackson2ObjectMapperBuilder.class).build();
DateTime dateTime = new DateTime(1436966242231L, DateTimeZone.UTC);
assertThat(objectMapper.writeValueAsString(dateTime))
.isEqualTo("\"Koordinierte Universalzeit\"");
public void customLocaleWithJodaTime() throws JsonProcessingException {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
context.register(JacksonAutoConfiguration.class);
TestPropertyValues
.of("spring.jackson.locale:de_DE", "spring.jackson.date-format:zzzz",
"spring.jackson.serialization.write-dates-with-zone-id:true")
.applyTo(context);
context.refresh();
ObjectMapper objectMapper = context.getBean(ObjectMapper.class);
DateTime jodaTime = new DateTime(1478424650000L,
DateTimeZone.forID("Europe/Rome"));
assertThat(objectMapper.writeValueAsString(jodaTime))
.startsWith("\"Mitteleuropäische ");
}
@Test

Loading…
Cancel
Save