Skip to content

Commit 88ce487

Browse files
committed
修改错误方法名,为工具类提供测试方法。
1 parent ffe6777 commit 88ce487

File tree

4 files changed

+157
-2
lines changed

4 files changed

+157
-2
lines changed

framework/fit/java/fit-builtin/plugins/fit-validation-hibernate-jakarta/src/test/java/modelengine/fitframework/validation/LocaleValidationControllerTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ void teardown() throws IOException {
4949

5050
@Test
5151
@DisplayName("测试法文地区的验证消息")
52-
void shouldReturnChineseValidationMessage() {
52+
void shouldReturnFrenchValidationMessage() {
5353
Company invalidCompany = new Company(null);
5454

5555
MockRequestBuilder requestBuilder = MockMvcRequestBuilders.post("/validation/locale/simple")

framework/fit/java/fit-builtin/plugins/fit-validation-hibernate-javax/src/test/java/modelengine/fitframework/validation/LocaleValidationControllerTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ void teardown() throws IOException {
4949

5050
@Test
5151
@DisplayName("测试法文地区的验证消息")
52-
void shouldReturnChineseValidationMessage() {
52+
void shouldReturnFrenchValidationMessage() {
5353
Company invalidCompany = new Company(null);
5454

5555
MockRequestBuilder requestBuilder = MockMvcRequestBuilders.post("/validation/locale/simple")
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) 2025 Huawei Technologies Co., Ltd. All rights reserved.
3+
* This file is a part of the ModelEngine Project.
4+
* Licensed under the MIT License. See License.txt in the project root for license information.
5+
*--------------------------------------------------------------------------------------------*/
6+
7+
package modelengine.fitframework.util.i18n;
8+
9+
import static org.assertj.core.api.Assertions.assertThat;
10+
11+
import java.util.Locale;
12+
13+
import org.junit.jupiter.api.AfterEach;
14+
import org.junit.jupiter.api.DisplayName;
15+
import org.junit.jupiter.api.Nested;
16+
import org.junit.jupiter.api.Test;
17+
18+
/**
19+
* {@link LocaleContextHolder} 的单元测试。
20+
*
21+
* @author 阮睿
22+
* @since 2025-09-09
23+
*/
24+
@DisplayName("测试 LocaleContextHolder")
25+
public class LocaleContextHolderTest {
26+
@AfterEach
27+
void tearDown() {
28+
LocaleContextHolder.clear();
29+
}
30+
31+
@Nested
32+
@DisplayName("Test method: setLocaleContext and getLocaleContext")
33+
class TestSetAndGetLocaleContext {
34+
35+
@Test
36+
@DisplayName("Given locale context with zh_CN then return the same locale context")
37+
void givenLocaleContextWithZhCNThenReturnSameLocaleContext() {
38+
LocaleContext localeContext = new LocaleContext(Locale.SIMPLIFIED_CHINESE);
39+
LocaleContextHolder.setLocaleContext(localeContext);
40+
assertThat(LocaleContextHolder.getLocaleContext()).isEqualTo(localeContext);
41+
}
42+
43+
@Test
44+
@DisplayName("Given locale context with en_US then return the same locale context")
45+
void givenLocaleContextWithEnUSThenReturnSameLocaleContext() {
46+
LocaleContext localeContext = new LocaleContext(Locale.US);
47+
LocaleContextHolder.setLocaleContext(localeContext);
48+
assertThat(LocaleContextHolder.getLocaleContext()).isEqualTo(localeContext);
49+
}
50+
51+
@Test
52+
@DisplayName("Given null locale context then not set and return null")
53+
void givenNullLocaleContextThenReturnNull() {
54+
LocaleContextHolder.setLocaleContext(null);
55+
assertThat(LocaleContextHolder.getLocaleContext()).isNull();
56+
}
57+
}
58+
59+
@Nested
60+
@DisplayName("Test method: getLocale")
61+
class TestGetLocale {
62+
63+
@Test
64+
@DisplayName("Given locale context with zh_CN then return zh_CN locale")
65+
void givenLocaleContextWithZhCNThenReturnZhCNLocale() {
66+
LocaleContext localeContext = new LocaleContext(Locale.SIMPLIFIED_CHINESE);
67+
LocaleContextHolder.setLocaleContext(localeContext);
68+
assertThat(LocaleContextHolder.getLocale()).isEqualTo(Locale.SIMPLIFIED_CHINESE);
69+
}
70+
71+
@Test
72+
@DisplayName("Given locale context with en_US then return en_US locale")
73+
void givenLocaleContextWithEnUSThenReturnEnUSLocale() {
74+
LocaleContext localeContext = new LocaleContext(Locale.US);
75+
LocaleContextHolder.setLocaleContext(localeContext);
76+
assertThat(LocaleContextHolder.getLocale()).isEqualTo(Locale.US);
77+
}
78+
79+
@Test
80+
@DisplayName("Given no locale context then return null")
81+
void givenNoLocaleContextThenReturnNull() {
82+
LocaleContextHolder.clear();
83+
assertThat(LocaleContextHolder.getLocale()).isNull();
84+
}
85+
}
86+
87+
@Nested
88+
@DisplayName("Test method: clear")
89+
class TestClear {
90+
91+
@Test
92+
@DisplayName("Given existing locale context then clear it")
93+
void givenExistingLocaleContextThenClearIt() {
94+
LocaleContext localeContext = new LocaleContext(Locale.SIMPLIFIED_CHINESE);
95+
LocaleContextHolder.setLocaleContext(localeContext);
96+
assertThat(LocaleContextHolder.getLocaleContext()).isNotNull();
97+
98+
LocaleContextHolder.clear();
99+
assertThat(LocaleContextHolder.getLocaleContext()).isNull();
100+
}
101+
}
102+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) 2025 Huawei Technologies Co., Ltd. All rights reserved.
3+
* This file is a part of the ModelEngine Project.
4+
* Licensed under the MIT License. See License.txt in the project root for license information.
5+
*--------------------------------------------------------------------------------------------*/
6+
7+
package modelengine.fitframework.util.i18n;
8+
9+
import static org.assertj.core.api.Assertions.assertThat;
10+
11+
import java.util.Locale;
12+
13+
import org.junit.jupiter.api.DisplayName;
14+
import org.junit.jupiter.api.Nested;
15+
import org.junit.jupiter.api.Test;
16+
17+
/**
18+
* {@link LocaleContext} 的单元测试。
19+
*
20+
* @author 阮睿
21+
* @since 2025-09-09
22+
*/
23+
@DisplayName("测试 LocaleContext")
24+
public class LocaleContextTest {
25+
@Nested
26+
@DisplayName("Test method: constructor and getLocale()")
27+
class TestConstructorAndGetLocale {
28+
29+
@Test
30+
@DisplayName("Given locale is zh_CN then return the same locale")
31+
void givenZhCNThenReturnSameLocale() {
32+
Locale locale = Locale.SIMPLIFIED_CHINESE;
33+
LocaleContext localeContext = new LocaleContext(locale);
34+
assertThat(localeContext.getLocale()).isEqualTo(locale);
35+
}
36+
37+
@Test
38+
@DisplayName("Given locale is en_US then return the same locale")
39+
void givenEnUSThenReturnSameLocale() {
40+
Locale locale = Locale.US;
41+
LocaleContext localeContext = new LocaleContext(locale);
42+
assertThat(localeContext.getLocale()).isEqualTo(locale);
43+
}
44+
45+
@Test
46+
@DisplayName("Given locale is null then return null")
47+
void givenNullThenReturnNull() {
48+
LocaleContext localeContext = new LocaleContext(null);
49+
assertThat(localeContext.getLocale()).isNull();
50+
}
51+
}
52+
}
53+

0 commit comments

Comments
 (0)