[
https://jira.codehaus.org/browse/JBEHAVE-739?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=293862#comment-293862
]
Brian Repko commented on JBEHAVE-739:
-------------------------------------
Oh, sorry, just looked at the code and Locale.ENGLISH is the default in
ParameterConverters. You can can change that in the configuration by
using/creating a new ParameterConverters and specifying the locale in the
constructor. It does NOT use the system default locale.
configuration.useParameterConverters(new
ParameterConverters(configuration.stepMonitor(),Locale.GERMANY,",",false);
Let us know if configuring the ParameterConverters based on a "de_DE" locale
works.
I also see that thread safety is sort of addressed there as well - but seems to
be thread-safety around the manipulation of the list of parameter converters,
not the converters themselves.
> NumberFormatException when trying to convert parameters to BigDecimal with
> Locale
> ---------------------------------------------------------------------------------
>
> Key: JBEHAVE-739
> URL: https://jira.codehaus.org/browse/JBEHAVE-739
> Project: JBehave
> Issue Type: Bug
> Components: Core
> Affects Versions: 3.6
> Reporter: Daniel Schneller
>
> When using a German localized number with group separators and decimals, a
> conversion to BigDecimal fails with a {{NumberFormatException}}. For German,
> group separators are dots, decimal separator is a comma (just the other way
> round of the US version).
> In the following test class, the first case is green, the second fails with
> {noformat}
> org.jbehave.core.steps.ParameterConverters$ParameterConvertionFailed:
> 1.000.000,01
> at
> org.jbehave.core.steps.ParameterConverters$NumberConverter.convertValue(ParameterConverters.java:256)
> at
> de.westlb.jets.xce.jbehave.tools.NumberFormatTest.jbehaveConverter(NumberFormatTest.java:39)
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
> at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
> at java.lang.reflect.Method.invoke(Method.java:597)
> at
> org.junit.internal.runners.TestMethodRunner.executeMethodBody(TestMethodRunner.java:99)
> ...
> at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
> Caused by: java.lang.NumberFormatException
> at java.math.BigDecimal.<init>(BigDecimal.java:453)
> at java.math.BigDecimal.<init>(BigDecimal.java:728)
> at
> org.jbehave.core.steps.ParameterConverters$NumberConverter.convertValue(ParameterConverters.java:247)
> ... 21 more
> {noformat}
> Putting a breakpoint in the BigDecimal constructor reveals it is fed a String
> "1.000.000.000.00" which is obviously wrong. I suspect, the
> "canonicalization" of the original String breaks it.
> {code:title=Test.java}
> public class NumberFormatTest {
> private static final BigDecimal EXPECTED = new BigDecimal("1000000.01");
> private final String localizedString = "1.000.000,01";
> private DecimalFormat germanNumbers;
> @Before
> public void setup() {
> germanNumbers = (DecimalFormat) DecimalFormat
> .getNumberInstance(Locale.GERMAN);
> germanNumbers.setParseBigDecimal(true);
> }
> @Test
> public void plainConverter() throws Exception {
> Number parse = germanNumbers.parse(localizedString);
> assertEquals(EXPECTED, parse);
> }
> @Test
> public void jbehaveConverter() throws Exception {
> ParameterConverters.NumberConverter numberConverter = new
> ParameterConverters.NumberConverter(
> germanNumbers);
> Object v = numberConverter.convertValue(localizedString,
> BigDecimal.class);
> assertEquals(EXPECTED, v);
> }
> {code}
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators:
https://jira.codehaus.org/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email