From 2c2b9be4be72b2dde931e910c95074a786fcfcf7 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Thu, 28 Sep 2017 11:01:14 +0100 Subject: [PATCH] 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 --- .../JacksonAutoConfigurationTests.java | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jackson/JacksonAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jackson/JacksonAutoConfigurationTests.java index 9dc7dfbac27..a573aaf5c9a 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jackson/JacksonAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jackson/JacksonAutoConfigurationTests.java @@ -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