Fixed default formatters test to reliably work with any system locale
Issue: SPR-13232
This commit is contained in:
parent
2934256257
commit
ef781b6353
|
|
@ -26,6 +26,7 @@ import java.util.Set;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import org.springframework.context.i18n.LocaleContextHolder;
|
||||||
import org.springframework.core.convert.ConversionFailedException;
|
import org.springframework.core.convert.ConversionFailedException;
|
||||||
import org.springframework.core.convert.TypeDescriptor;
|
import org.springframework.core.convert.TypeDescriptor;
|
||||||
import org.springframework.format.AnnotationFormatterFactory;
|
import org.springframework.format.AnnotationFormatterFactory;
|
||||||
|
|
@ -50,11 +51,18 @@ public class FormattingConversionServiceFactoryBeanTests {
|
||||||
factory.afterPropertiesSet();
|
factory.afterPropertiesSet();
|
||||||
FormattingConversionService fcs = factory.getObject();
|
FormattingConversionService fcs = factory.getObject();
|
||||||
TypeDescriptor descriptor = new TypeDescriptor(TestBean.class.getDeclaredField("pattern"));
|
TypeDescriptor descriptor = new TypeDescriptor(TestBean.class.getDeclaredField("pattern"));
|
||||||
|
|
||||||
|
LocaleContextHolder.setLocale(Locale.GERMAN);
|
||||||
|
try {
|
||||||
Object value = fcs.convert("15,00", TypeDescriptor.valueOf(String.class), descriptor);
|
Object value = fcs.convert("15,00", TypeDescriptor.valueOf(String.class), descriptor);
|
||||||
assertEquals(15.0, value);
|
assertEquals(15.0, value);
|
||||||
value = fcs.convert(15.0, descriptor, TypeDescriptor.valueOf(String.class));
|
value = fcs.convert(15.0, descriptor, TypeDescriptor.valueOf(String.class));
|
||||||
assertEquals("15", value);
|
assertEquals("15", value);
|
||||||
}
|
}
|
||||||
|
finally {
|
||||||
|
LocaleContextHolder.resetLocaleContext();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDefaultFormattersOff() throws Exception {
|
public void testDefaultFormattersOff() throws Exception {
|
||||||
|
|
@ -63,6 +71,7 @@ public class FormattingConversionServiceFactoryBeanTests {
|
||||||
factory.afterPropertiesSet();
|
factory.afterPropertiesSet();
|
||||||
FormattingConversionService fcs = factory.getObject();
|
FormattingConversionService fcs = factory.getObject();
|
||||||
TypeDescriptor descriptor = new TypeDescriptor(TestBean.class.getDeclaredField("pattern"));
|
TypeDescriptor descriptor = new TypeDescriptor(TestBean.class.getDeclaredField("pattern"));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
fcs.convert("15,00", TypeDescriptor.valueOf(String.class), descriptor);
|
fcs.convert("15,00", TypeDescriptor.valueOf(String.class), descriptor);
|
||||||
fail("This format should not be parseable");
|
fail("This format should not be parseable");
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue