Revision: 1376
http://stripes.svn.sourceforge.net/stripes/?rev=1376&view=rev
Author: bengunter
Date: 2010-12-29 19:55:43 +0000 (Wed, 29 Dec 2010)
Log Message:
-----------
Fixed STS-783: Improve euro currency handling on NumberTypeConverterSupport.
NumberFormat inserts a space after or before currency symbol for some
currencies. I fixed NumberTypeConverterSupport.preprocess(..) to trim
whitespace again after removing the currency symbol.
Modified Paths:
--------------
branches/1.5.x/stripes/src/net/sourceforge/stripes/validation/NumberTypeConverterSupport.java
branches/1.5.x/tests/src/net/sourceforge/stripes/validation/NumberTypeConverterSupportTest.java
Modified:
branches/1.5.x/stripes/src/net/sourceforge/stripes/validation/NumberTypeConverterSupport.java
===================================================================
---
branches/1.5.x/stripes/src/net/sourceforge/stripes/validation/NumberTypeConverterSupport.java
2010-12-29 17:45:16 UTC (rev 1375)
+++
branches/1.5.x/stripes/src/net/sourceforge/stripes/validation/NumberTypeConverterSupport.java
2010-12-29 19:55:43 UTC (rev 1376)
@@ -97,7 +97,10 @@
// The casts are to make sure we don't call replace(String regex,
String replacement)
output = output.replace((CharSequence) currencySymbol, (CharSequence)
"");
- // Step 3: replace parentheses with negation
+ // Step 3: trim whitespace that might precede or follow currency symbol
+ output = output.trim();
+
+ // Step 4: replace parentheses with negation
if (output.startsWith("(") && output.endsWith(")")) {
output = "-" + output.substring(1, output.length() - 1);
}
Modified:
branches/1.5.x/tests/src/net/sourceforge/stripes/validation/NumberTypeConverterSupportTest.java
===================================================================
---
branches/1.5.x/tests/src/net/sourceforge/stripes/validation/NumberTypeConverterSupportTest.java
2010-12-29 17:45:16 UTC (rev 1375)
+++
branches/1.5.x/tests/src/net/sourceforge/stripes/validation/NumberTypeConverterSupportTest.java
2010-12-29 19:55:43 UTC (rev 1376)
@@ -57,7 +57,18 @@
Assert.assertEquals(number.doubleValue(), 1999.95);
}
- @Test(groups="fast")
+ @Test(groups = "fast")
+ public void testCurrencyWithSpace() {
+ Number number = getConverter().parse("$ 57", new
ArrayList<ValidationError>());
+ Assert.assertNotNull(number);
+ Assert.assertEquals(number.intValue(), 57);
+
+ number = getConverter().parse("1,999.95 $", new
ArrayList<ValidationError>());
+ Assert.assertNotNull(number);
+ Assert.assertEquals(number.doubleValue(), 1999.95);
+ }
+
+ @Test(groups = "fast")
public void testNegativeCurrency() {
Number number = getConverter().parse("-$57", new
ArrayList<ValidationError>());
Assert.assertEquals(number.intValue(), -57);
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
Learn how Oracle Real Application Clusters (RAC) One Node allows customers
to consolidate database storage, standardize their database environment, and,
should the need arise, upgrade to a full multi-node Oracle RAC database
without downtime or disruption
http://p.sf.net/sfu/oracle-sfdevnl
_______________________________________________
Stripes-development mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/stripes-development