source: josm/trunk/test/unit/org/openstreetmap/josm/tools/JosmDecimalFormatSymbolsProviderTest.java@ 17280

Last change on this file since 17280 was 17280, checked in by Don-vip, 3 years ago

see #16567 - fix assertEquals parameters order

  • Property svn:eol-style set to native
File size: 2.2 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.tools;
3
4import static org.junit.Assume.assumeTrue;
5import static org.junit.jupiter.api.Assertions.assertEquals;
6import static org.junit.jupiter.api.Assertions.assertTrue;
7
8import java.text.DecimalFormat;
9import java.util.Locale;
10import java.util.stream.Stream;
11
12import org.junit.jupiter.api.Test;
13import org.junit.jupiter.api.extension.RegisterExtension;
14import org.openstreetmap.josm.testutils.JOSMTestRules;
15
16import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
17
18/**
19 * Unit tests of {@link JosmDecimalFormatSymbolsProvider}.
20 */
21class JosmDecimalFormatSymbolsProviderTest {
22
23 /**
24 * Setup rule.
25 */
26 @RegisterExtension
27 @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
28 public JOSMTestRules test = new JOSMTestRules();
29
30 @Test
31 void testGroupingSeparator() {
32 System.out.println(Locale.getDefault());
33 assumeTrue(Utils.getJavaVersion() >= 9);
34
35 assertTrue(I18n.getAvailableTranslations().count() > 10);
36 I18n.getAvailableTranslations().forEach(this::checkGroupingSymbol);
37 Stream.of("", "AU", "IE", "US", "UK").map(country -> new Locale("en", country, "")).forEach(this::checkGroupingSymbol);
38 Stream.of("", "AT", "CH", "DE").map(country -> new Locale("de", country, "")).forEach(this::checkGroupingSymbol);
39 }
40
41 private void checkGroupingSymbol(Locale locale) {
42 assertEquals("123\u202F456", DecimalFormat.getInstance(locale).format(123_456), locale.toString());
43 }
44
45 /**
46 * Test {@link JosmDecimalFormatSymbolsProvider#parseDouble}.
47 */
48 @Test
49 void testParseDouble() {
50 final Locale defLocale = Locale.getDefault();
51 try {
52 Locale.setDefault(Locale.ENGLISH);
53 assertEquals(0.3, JosmDecimalFormatSymbolsProvider.parseDouble("0.3"), 1e-7);
54 assertEquals(0.3, JosmDecimalFormatSymbolsProvider.parseDouble("0,3"), 1e-7);
55 Locale.setDefault(Locale.FRENCH);
56 assertEquals(0.3, JosmDecimalFormatSymbolsProvider.parseDouble("0.3"), 1e-7);
57 assertEquals(0.3, JosmDecimalFormatSymbolsProvider.parseDouble("0,3"), 1e-7);
58 } finally {
59 Locale.setDefault(defLocale);
60 }
61 }
62}
Note: See TracBrowser for help on using the repository browser.