Guilherme Lima Pereira
05/05/2021, 8:42 PMNumberFormat.getCurrencyInstance
).
Learning about some changes from JDK 8 to JDK 11, I found that on JDK 9 they’ve enhanced some things related to Locale. One of the things is the usage of CLDR.
The issue with CLDR
is that is uses NBSP
instead of normal whitespace. The problem with NBSP
is that is not straightforward for the developers to add it during unit tests.
I tried to solve it by adding -Djava.locale.providers=COMPAT
on gradle.properties
(org.gradle.jvmargs
), but it keeps using NBSP
😢
Does anyone has suffered with it or have any idea how to address this issue?Guilherme Lima Pereira
05/05/2021, 9:01 PMnbsp
ephemient
05/05/2021, 9:02 PMtest {
jvmArgs '-Djava.locale.providers=COMPAT'
}
but note that IntelliJ won't use those JVM args if it's running the test classes itself, so... either manually fix the run configuration every time, or fix your testsephemient
05/05/2021, 9:04 PMephemient
05/05/2021, 9:06 PMandroid {
testOptions {
unitTests.all {
jvmArgs '-Djava.locale.providers=COMPAT'
}
}
}
in an Android moduleGuilherme Lima Pereira
05/05/2021, 9:18 PMnbsp
ephemient
05/05/2021, 9:19 PMephemient
05/05/2021, 9:19 PMephemient
05/05/2021, 9:20 PMGuilherme Lima Pereira
05/05/2021, 9:21 PMGuilherme Lima Pereira
05/05/2021, 9:23 PMephemient
05/05/2021, 9:23 PMephemient
05/05/2021, 9:24 PMGuilherme Lima Pereira
05/05/2021, 9:24 PMephemient
05/05/2021, 9:25 PM\u00A0
or regex match with \s
?Guilherme Lima Pereira
05/05/2021, 9:26 PMGuilherme Lima Pereira
05/05/2021, 9:26 PMval result = subject.mapFrom(cardResponse = cardResponse)
val expected = PricingCatalogItemCardModel(
unitPrice = "R$ 4,99",
originalUnitPrice = null
)
assertEquals(expected, result)
Guilherme Lima Pereira
05/05/2021, 9:27 PM"R$ 4,99",
to "R$\u00A04,99",
which not very straightforward for the devsephemient
05/05/2021, 9:27 PMGuilherme Lima Pereira
05/05/2021, 9:27 PMephemient
05/05/2021, 9:29 PMassertThat(result, matchesPattern("""R\$\s4,99"""))
may be an option as wellGuilherme Lima Pereira
05/05/2021, 9:30 PMephemient
05/05/2021, 9:30 PMMahmoud Mabrok
05/05/2021, 10:00 PMephemient
05/05/2021, 10:01 PMephemient
05/05/2021, 10:02 PM