From f521c43b07485665ac09a671bb4613116c3be5b4 Mon Sep 17 00:00:00 2001 From: Sharang Gupta Date: Tue, 6 Oct 2026 23:07:41 +0100 Subject: [PATCH] test: pin the default locale in SpringDocApp238Test SpringDocApp238Test resolves the @Info title and the tag names through a ResourceBundleMessageSource for en-US, fr-CA and zh-CN and compares the output with fixtures written for the base messages.properties bundle. ResourceBundleMessageSource falls back to the JVM default locale before the base bundle, so on a machine whose default locale is en_GB the en-US request (and the zh-CN one, which the allowed-locales setting maps to en-US) picks up messages_en_GB.properties and the test fails with "This is a test message[EN_GB]". Pin the default locale to en-US for the duration of the class and restore it afterwards, as SpringDocApp14Test already does, so the fixtures are deterministic regardless of the host locale. Fixes #3379 --- .../api/v30/app238/SpringDocApp238Test.java | 15 +++++++++++++++ .../api/v31/app238/SpringDocApp238Test.java | 15 +++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/springdoc-openapi-starter-webmvc-api/src/test/java/test/org/springdoc/api/v30/app238/SpringDocApp238Test.java b/springdoc-openapi-starter-webmvc-api/src/test/java/test/org/springdoc/api/v30/app238/SpringDocApp238Test.java index 1c1cfbc05..256944b53 100644 --- a/springdoc-openapi-starter-webmvc-api/src/test/java/test/org/springdoc/api/v30/app238/SpringDocApp238Test.java +++ b/springdoc-openapi-starter-webmvc-api/src/test/java/test/org/springdoc/api/v30/app238/SpringDocApp238Test.java @@ -26,6 +26,8 @@ import java.util.Locale; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import org.springdoc.core.customizers.OpenApiLocaleCustomizer; import org.springdoc.core.utils.Constants; @@ -48,6 +50,19 @@ @TestPropertySource(properties = "springdoc.allowed-locales=en-US,fr-CA") public class SpringDocApp238Test extends AbstractSpringDocV30Test { + private static Locale DEFAULT_LOCALE; + + @BeforeAll + public static void init() { + DEFAULT_LOCALE = Locale.getDefault(); + Locale.setDefault(Locale.US); + } + + @AfterAll + public static void clean() { + Locale.setDefault(DEFAULT_LOCALE); + } + @Test @Override public void testApp() throws Exception { diff --git a/springdoc-openapi-starter-webmvc-api/src/test/java/test/org/springdoc/api/v31/app238/SpringDocApp238Test.java b/springdoc-openapi-starter-webmvc-api/src/test/java/test/org/springdoc/api/v31/app238/SpringDocApp238Test.java index a681556ae..cd349dd01 100644 --- a/springdoc-openapi-starter-webmvc-api/src/test/java/test/org/springdoc/api/v31/app238/SpringDocApp238Test.java +++ b/springdoc-openapi-starter-webmvc-api/src/test/java/test/org/springdoc/api/v31/app238/SpringDocApp238Test.java @@ -26,6 +26,8 @@ import java.util.Locale; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import org.springdoc.core.customizers.OpenApiLocaleCustomizer; import org.springdoc.core.utils.Constants; @@ -48,6 +50,19 @@ @TestPropertySource(properties = "springdoc.allowed-locales=en-US,fr-CA") public class SpringDocApp238Test extends AbstractSpringDocTest { + private static Locale DEFAULT_LOCALE; + + @BeforeAll + public static void init() { + DEFAULT_LOCALE = Locale.getDefault(); + Locale.setDefault(Locale.US); + } + + @AfterAll + public static void clean() { + Locale.setDefault(DEFAULT_LOCALE); + } + @Test @Override public void testApp() throws Exception {