Browse Source

Fixed default formatters test to reliably work with any system locale

Issue: SPR-13232
pull/838/head
Juergen Hoeller 9 years ago
parent
commit
ef781b6353
  1. 9
      spring-context/src/test/java/org/springframework/format/support/FormattingConversionServiceFactoryBeanTests.java

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

@ -26,6 +26,7 @@ import java.util.Set; @@ -26,6 +26,7 @@ import java.util.Set;
import org.junit.Test;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.core.convert.ConversionFailedException;
import org.springframework.core.convert.TypeDescriptor;
import org.springframework.format.AnnotationFormatterFactory;
@ -50,11 +51,18 @@ public class FormattingConversionServiceFactoryBeanTests { @@ -50,11 +51,18 @@ public class FormattingConversionServiceFactoryBeanTests {
factory.afterPropertiesSet();
FormattingConversionService fcs = factory.getObject();
TypeDescriptor descriptor = new TypeDescriptor(TestBean.class.getDeclaredField("pattern"));
LocaleContextHolder.setLocale(Locale.GERMAN);
try {
Object value = fcs.convert("15,00", TypeDescriptor.valueOf(String.class), descriptor);
assertEquals(15.0, value);
value = fcs.convert(15.0, descriptor, TypeDescriptor.valueOf(String.class));
assertEquals("15", value);
}
finally {
LocaleContextHolder.resetLocaleContext();
}
}
@Test
public void testDefaultFormattersOff() throws Exception {
@ -63,6 +71,7 @@ public class FormattingConversionServiceFactoryBeanTests { @@ -63,6 +71,7 @@ public class FormattingConversionServiceFactoryBeanTests {
factory.afterPropertiesSet();
FormattingConversionService fcs = factory.getObject();
TypeDescriptor descriptor = new TypeDescriptor(TestBean.class.getDeclaredField("pattern"));
try {
fcs.convert("15,00", TypeDescriptor.valueOf(String.class), descriptor);
fail("This format should not be parseable");

Loading…
Cancel
Save