From ce80ed428376f09e67511d0056d3c16fbdbd9130 Mon Sep 17 00:00:00 2001 From: guqing <38999863+guqing@users.noreply.github.com> Date: Fri, 24 Feb 2023 16:40:13 +0800 Subject: [PATCH] fix: i18n unit test (#3388) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #### What type of PR is this? /kind improvement /area core #### What this PR does / why we need it: 修复 i18n 的单元测试,在中文或其他除了英语之外的系统语言的环境下断言无法通过 image 可以将系统语言设置为其他来测试此 PR 不会出现上述问题即可 #### Does this PR introduce a user-facing change? ```release-note None ``` --- .../exception/handlers/I18nExceptionTest.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/test/java/run/halo/app/infra/exception/handlers/I18nExceptionTest.java b/src/test/java/run/halo/app/infra/exception/handlers/I18nExceptionTest.java index a6ef11b9c..161a3be78 100644 --- a/src/test/java/run/halo/app/infra/exception/handlers/I18nExceptionTest.java +++ b/src/test/java/run/halo/app/infra/exception/handlers/I18nExceptionTest.java @@ -2,6 +2,9 @@ package run.halo.app.infra.exception.handlers; import static org.junit.jupiter.api.Assertions.assertEquals; +import java.util.Locale; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.reactive.AutoConfigureWebTestClient; @@ -25,6 +28,18 @@ class I18nExceptionTest { @Autowired WebTestClient webClient; + Locale currentLocale; + + @BeforeEach + void setUp() { + currentLocale = Locale.getDefault(); + Locale.setDefault(Locale.ENGLISH); + } + + @AfterEach + void tearDown() { + Locale.setDefault(currentLocale); + } @Test void shouldBeOkForGreetingEndpoint() {