Skip to content

Commit ef781b6

Browse files
committed
Fixed default formatters test to reliably work with any system locale
Issue: SPR-13232
1 parent 2934256 commit ef781b6

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

spring-context/src/test/java/org/springframework/format/support/FormattingConversionServiceFactoryBeanTests.java

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
import org.junit.Test;
2828

29+
import org.springframework.context.i18n.LocaleContextHolder;
2930
import org.springframework.core.convert.ConversionFailedException;
3031
import org.springframework.core.convert.TypeDescriptor;
3132
import org.springframework.format.AnnotationFormatterFactory;
@@ -50,10 +51,17 @@ public void testDefaultFormattersOn() throws Exception {
5051
factory.afterPropertiesSet();
5152
FormattingConversionService fcs = factory.getObject();
5253
TypeDescriptor descriptor = new TypeDescriptor(TestBean.class.getDeclaredField("pattern"));
53-
Object value = fcs.convert("15,00", TypeDescriptor.valueOf(String.class), descriptor);
54-
assertEquals(15.0, value);
55-
value = fcs.convert(15.0, descriptor, TypeDescriptor.valueOf(String.class));
56-
assertEquals("15", value);
54+
55+
LocaleContextHolder.setLocale(Locale.GERMAN);
56+
try {
57+
Object value = fcs.convert("15,00", TypeDescriptor.valueOf(String.class), descriptor);
58+
assertEquals(15.0, value);
59+
value = fcs.convert(15.0, descriptor, TypeDescriptor.valueOf(String.class));
60+
assertEquals("15", value);
61+
}
62+
finally {
63+
LocaleContextHolder.resetLocaleContext();
64+
}
5765
}
5866

5967
@Test
@@ -63,6 +71,7 @@ public void testDefaultFormattersOff() throws Exception {
6371
factory.afterPropertiesSet();
6472
FormattingConversionService fcs = factory.getObject();
6573
TypeDescriptor descriptor = new TypeDescriptor(TestBean.class.getDeclaredField("pattern"));
74+
6675
try {
6776
fcs.convert("15,00", TypeDescriptor.valueOf(String.class), descriptor);
6877
fail("This format should not be parseable");

0 commit comments

Comments
 (0)