22
22
import java .util .Map ;
23
23
24
24
import jakarta .servlet .jsp .tagext .Tag ;
25
+ import org .junit .jupiter .api .AfterEach ;
25
26
import org .junit .jupiter .api .BeforeEach ;
26
27
import org .junit .jupiter .api .Test ;
27
28
29
+ import org .springframework .context .i18n .LocaleContextHolder ;
28
30
import org .springframework .context .support .GenericApplicationContext ;
29
31
import org .springframework .core .env .MapPropertySource ;
30
32
import org .springframework .format .annotation .NumberFormat ;
31
33
import org .springframework .format .annotation .NumberFormat .Style ;
32
- import org .springframework .format .number .PercentStyleFormatter ;
33
34
import org .springframework .format .support .FormattingConversionServiceFactoryBean ;
34
35
import org .springframework .web .servlet .DispatcherServlet ;
35
36
import org .springframework .web .testfixture .servlet .MockHttpServletResponse ;
@@ -49,6 +50,8 @@ class EvalTagTests extends AbstractTagTests {
49
50
50
51
@ BeforeEach
51
52
void setup () {
53
+ LocaleContextHolder .setDefaultLocale (Locale .UK );
54
+
52
55
context = createPageContext ();
53
56
FormattingConversionServiceFactoryBean factory = new FormattingConversionServiceFactoryBean ();
54
57
factory .afterPropertiesSet ();
@@ -58,6 +61,11 @@ void setup() {
58
61
tag .setPageContext (context );
59
62
}
60
63
64
+ @ AfterEach
65
+ void reset () {
66
+ LocaleContextHolder .setDefaultLocale (null );
67
+ }
68
+
61
69
62
70
@ Test
63
71
void printScopedAttributeResult () throws Exception {
@@ -81,13 +89,12 @@ void printNullAsEmptyString() throws Exception {
81
89
82
90
@ Test
83
91
void printFormattedScopedAttributeResult () throws Exception {
84
- PercentStyleFormatter formatter = new PercentStyleFormatter ();
85
92
tag .setExpression ("bean.formattable" );
86
93
int action = tag .doStartTag ();
87
94
assertThat (action ).isEqualTo (Tag .EVAL_BODY_INCLUDE );
88
95
action = tag .doEndTag ();
89
96
assertThat (action ).isEqualTo (Tag .EVAL_PAGE );
90
- assertThat (((MockHttpServletResponse ) context .getResponse ()).getContentAsString ()).isEqualTo (formatter . print ( new BigDecimal ( ".25" ), Locale . getDefault ()) );
97
+ assertThat (((MockHttpServletResponse ) context .getResponse ()).getContentAsString ()).isEqualTo ("25%" );
91
98
}
92
99
93
100
@ Test
0 commit comments