[JAVA-2625] ServerDescriptionTest failed due to character used for decimal separator Created: 05/Oct/17  Updated: 29/Oct/23  Resolved: 08/Nov/17

Status: Closed
Project: Java Driver
Component/s: Test Coverage
Affects Version/s: 3.0.0
Fix Version/s: 3.6.0

Type: Improvement Priority: Trivial - P5
Reporter: Farès Hassak Assignee: Jeffrey Yemin
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: PNG File failedTest.png     PNG File passedTest.png    

 Description   

Hello,

ServerDescriptionTest.testShortDescription() failed due to character used for decimal separator :

expected = roundTripTime=5000.0 ms
actual = 5000,0 ms

In my region, locale decimal separator is ',' and not '.'.

org.junit.ComparisonFailure: expected:<..., roundTripTime=5000[.]0 ms, state=CONNECTE...> but was:<..., roundTripTime=5000[,]0 ms, state=CONNECTE...>
	at org.junit.Assert.assertEquals(Assert.java:115)
	at org.junit.Assert.assertEquals(Assert.java:144)
	at com.mongodb.connection.ServerDescriptionTest.testShortDescription(ServerDescriptionTest.java:316)

More details :
https://docs.oracle.com/javase/tutorial/i18n/format/decimalFormat.html
https://docs.oracle.com/javase/8/docs/api/java/text/DecimalFormatSymbols.html

I have fixed this issue by using a locale decimal separator instead of '.'
I will do a pull request.

 public void testShortDescription() throws UnknownHostException {
        final char decimalSeparator = new DecimalFormatSymbols().getDecimalSeparator();
        assertEquals("{address=127.0.0.1:27017, type=UNKNOWN, TagSet{[Tag{name='dc', value='ny'}, Tag{name='rack', value='1'}]}, "
                     + "roundTripTime=5000" + decimalSeparator + "0 ms, "
 
}

Farès



 Comments   
Comment by Githook User [ 08/Nov/17 ]

Author:

{'name': 'Farès Hassak', 'username': 'fhassak', 'email': 'fares.hassak@gmail.com'}

Message: JAVA-2625: Set the character used for decimal separator so that it is no longer locale-sensitive.

Branch: master
https://github.com/mongodb/mongo-java-driver/commit/cfc43dfaa7038a65ebb3ff88225b9d5ef50c30fe

Comment by Farès Hassak [ 16/Oct/17 ]
  • PR 419 is closed.
  • PR 420 is updated with static initialization of DecimalFormatSymbols
Comment by Jeffrey Yemin [ 16/Oct/17 ]

I prefer the alternative solution. Log messages don't need to be localized

Comment by Farès Hassak [ 08/Oct/17 ]

An alternative solution is to set the character used for decimal separator.
In this case, the separator will always be '.' regardless of the default locale

https://github.com/mongodb/mongo-java-driver/pull/420.

Comment by Farès Hassak [ 06/Oct/17 ]

https://github.com/mongodb/mongo-java-driver/pull/419

Comment by Ross Lawley [ 06/Oct/17 ]

Hi Farès Hassak,

Many thanks for the ticket. We'll look to fix this in the next release.

Ross

Generated at Thu Feb 08 08:57:41 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.