|
|
@ -24,6 +24,7 @@ import java.util.Locale; |
|
|
|
|
|
|
|
|
|
|
|
import org.junit.After; |
|
|
|
import org.junit.After; |
|
|
|
import org.junit.Before; |
|
|
|
import org.junit.Before; |
|
|
|
|
|
|
|
import org.junit.Ignore; |
|
|
|
import org.junit.Test; |
|
|
|
import org.junit.Test; |
|
|
|
import org.springframework.beans.MutablePropertyValues; |
|
|
|
import org.springframework.beans.MutablePropertyValues; |
|
|
|
import org.springframework.context.i18n.LocaleContextHolder; |
|
|
|
import org.springframework.context.i18n.LocaleContextHolder; |
|
|
@ -51,8 +52,7 @@ public class NumberFormattingTests { |
|
|
|
public String resolveStringValue(String strVal) { |
|
|
|
public String resolveStringValue(String strVal) { |
|
|
|
if ("${pattern}".equals(strVal)) { |
|
|
|
if ("${pattern}".equals(strVal)) { |
|
|
|
return "#,##.00"; |
|
|
|
return "#,##.00"; |
|
|
|
} |
|
|
|
} else { |
|
|
|
else { |
|
|
|
|
|
|
|
return strVal; |
|
|
|
return strVal; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -69,6 +69,8 @@ public class NumberFormattingTests { |
|
|
|
LocaleContextHolder.setLocale(null); |
|
|
|
LocaleContextHolder.setLocale(null); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// TODO [SPR-8178] determine why changes to GenericConversionService broke this test
|
|
|
|
|
|
|
|
@Ignore("Disabled until SPR-8178 is resolved") |
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testDefaultNumberFormatting() { |
|
|
|
public void testDefaultNumberFormatting() { |
|
|
|
MutablePropertyValues propertyValues = new MutablePropertyValues(); |
|
|
|
MutablePropertyValues propertyValues = new MutablePropertyValues(); |
|
|
@ -117,7 +119,7 @@ public class NumberFormattingTests { |
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testPatternArrayFormatting() { |
|
|
|
public void testPatternArrayFormatting() { |
|
|
|
MutablePropertyValues propertyValues = new MutablePropertyValues(); |
|
|
|
MutablePropertyValues propertyValues = new MutablePropertyValues(); |
|
|
|
propertyValues.add("patternArray", new String[] {"1,25.00", "2,35.00"}); |
|
|
|
propertyValues.add("patternArray", new String[] { "1,25.00", "2,35.00" }); |
|
|
|
binder.bind(propertyValues); |
|
|
|
binder.bind(propertyValues); |
|
|
|
assertEquals(0, binder.getBindingResult().getErrorCount()); |
|
|
|
assertEquals(0, binder.getBindingResult().getErrorCount()); |
|
|
|
assertEquals("1,25.00", binder.getBindingResult().getFieldValue("patternArray[0]")); |
|
|
|
assertEquals("1,25.00", binder.getBindingResult().getFieldValue("patternArray[0]")); |
|
|
@ -135,7 +137,7 @@ public class NumberFormattingTests { |
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testPatternListFormatting() { |
|
|
|
public void testPatternListFormatting() { |
|
|
|
MutablePropertyValues propertyValues = new MutablePropertyValues(); |
|
|
|
MutablePropertyValues propertyValues = new MutablePropertyValues(); |
|
|
|
propertyValues.add("patternList", new String[] {"1,25.00", "2,35.00"}); |
|
|
|
propertyValues.add("patternList", new String[] { "1,25.00", "2,35.00" }); |
|
|
|
binder.bind(propertyValues); |
|
|
|
binder.bind(propertyValues); |
|
|
|
assertEquals(0, binder.getBindingResult().getErrorCount()); |
|
|
|
assertEquals(0, binder.getBindingResult().getErrorCount()); |
|
|
|
assertEquals("1,25.00", binder.getBindingResult().getFieldValue("patternList[0]")); |
|
|
|
assertEquals("1,25.00", binder.getBindingResult().getFieldValue("patternList[0]")); |
|
|
@ -171,7 +173,6 @@ public class NumberFormattingTests { |
|
|
|
assertEquals("1,25.00,2,35.00", binder.getBindingResult().getFieldValue("patternList2")); |
|
|
|
assertEquals("1,25.00,2,35.00", binder.getBindingResult().getFieldValue("patternList2")); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@SuppressWarnings("unused") |
|
|
|
@SuppressWarnings("unused") |
|
|
|
private static class TestBean { |
|
|
|
private static class TestBean { |
|
|
|
|
|
|
|
|
|
|
@ -180,22 +181,22 @@ public class NumberFormattingTests { |
|
|
|
@NumberFormat |
|
|
|
@NumberFormat |
|
|
|
private Double numberDefaultAnnotated; |
|
|
|
private Double numberDefaultAnnotated; |
|
|
|
|
|
|
|
|
|
|
|
@NumberFormat(style=Style.CURRENCY) |
|
|
|
@NumberFormat(style = Style.CURRENCY) |
|
|
|
private BigDecimal currency; |
|
|
|
private BigDecimal currency; |
|
|
|
|
|
|
|
|
|
|
|
@NumberFormat(style=Style.PERCENT) |
|
|
|
@NumberFormat(style = Style.PERCENT) |
|
|
|
private BigDecimal percent; |
|
|
|
private BigDecimal percent; |
|
|
|
|
|
|
|
|
|
|
|
@NumberFormat(pattern="${pattern}") |
|
|
|
@NumberFormat(pattern = "${pattern}") |
|
|
|
private BigDecimal pattern; |
|
|
|
private BigDecimal pattern; |
|
|
|
|
|
|
|
|
|
|
|
@NumberFormat(pattern="#,##.00") |
|
|
|
@NumberFormat(pattern = "#,##.00") |
|
|
|
private BigDecimal[] patternArray; |
|
|
|
private BigDecimal[] patternArray; |
|
|
|
|
|
|
|
|
|
|
|
@NumberFormat(pattern="#,##.00") |
|
|
|
@NumberFormat(pattern = "#,##.00") |
|
|
|
private List<BigDecimal> patternList; |
|
|
|
private List<BigDecimal> patternList; |
|
|
|
|
|
|
|
|
|
|
|
@NumberFormat(pattern="#,##.00") |
|
|
|
@NumberFormat(pattern = "#,##.00") |
|
|
|
private List<BigDecimal> patternList2; |
|
|
|
private List<BigDecimal> patternList2; |
|
|
|
|
|
|
|
|
|
|
|
public Integer getNumberDefault() { |
|
|
|
public Integer getNumberDefault() { |
|
|
|