test/jdk/java/util/PluggableLocale/NumberFormatProviderTest.java
author dzhou
Thu, 18 Oct 2018 00:56:38 -0700
changeset 52187 8d140834fbb0
parent 47216 71c04702a3d5
permissions -rw-r--r--
8210406: Refactor java.util.PluggableLocale:i18n shell tests to plain java tests Reviewed-by: naoto
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
52187
8d140834fbb0 8210406: Refactor java.util.PluggableLocale:i18n shell tests to plain java tests
dzhou
parents: 47216
diff changeset
     2
 * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 */
52187
8d140834fbb0 8210406: Refactor java.util.PluggableLocale:i18n shell tests to plain java tests
dzhou
parents: 47216
diff changeset
    23
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
/*
52187
8d140834fbb0 8210406: Refactor java.util.PluggableLocale:i18n shell tests to plain java tests
dzhou
parents: 47216
diff changeset
    25
 * @test
8d140834fbb0 8210406: Refactor java.util.PluggableLocale:i18n shell tests to plain java tests
dzhou
parents: 47216
diff changeset
    26
 * @bug 4052440 7003643 8062588 8210406
8d140834fbb0 8210406: Refactor java.util.PluggableLocale:i18n shell tests to plain java tests
dzhou
parents: 47216
diff changeset
    27
 * @summary NumberFormatProvider tests
8d140834fbb0 8210406: Refactor java.util.PluggableLocale:i18n shell tests to plain java tests
dzhou
parents: 47216
diff changeset
    28
 * @library providersrc/foobarutils
8d140834fbb0 8210406: Refactor java.util.PluggableLocale:i18n shell tests to plain java tests
dzhou
parents: 47216
diff changeset
    29
 *          providersrc/fooprovider
8d140834fbb0 8210406: Refactor java.util.PluggableLocale:i18n shell tests to plain java tests
dzhou
parents: 47216
diff changeset
    30
 * @modules java.base/sun.util.locale.provider
8d140834fbb0 8210406: Refactor java.util.PluggableLocale:i18n shell tests to plain java tests
dzhou
parents: 47216
diff changeset
    31
 * @build com.foobar.Utils
8d140834fbb0 8210406: Refactor java.util.PluggableLocale:i18n shell tests to plain java tests
dzhou
parents: 47216
diff changeset
    32
 *        com.foo.*
8d140834fbb0 8210406: Refactor java.util.PluggableLocale:i18n shell tests to plain java tests
dzhou
parents: 47216
diff changeset
    33
 * @run main/othervm -Djava.locale.providers=JRE,SPI NumberFormatProviderTest
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
52187
8d140834fbb0 8210406: Refactor java.util.PluggableLocale:i18n shell tests to plain java tests
dzhou
parents: 47216
diff changeset
    36
import java.text.DecimalFormat;
8d140834fbb0 8210406: Refactor java.util.PluggableLocale:i18n shell tests to plain java tests
dzhou
parents: 47216
diff changeset
    37
import java.text.DecimalFormatSymbols;
8d140834fbb0 8210406: Refactor java.util.PluggableLocale:i18n shell tests to plain java tests
dzhou
parents: 47216
diff changeset
    38
import java.text.MessageFormat;
8d140834fbb0 8210406: Refactor java.util.PluggableLocale:i18n shell tests to plain java tests
dzhou
parents: 47216
diff changeset
    39
import java.text.NumberFormat;
8d140834fbb0 8210406: Refactor java.util.PluggableLocale:i18n shell tests to plain java tests
dzhou
parents: 47216
diff changeset
    40
import java.util.Arrays;
8d140834fbb0 8210406: Refactor java.util.PluggableLocale:i18n shell tests to plain java tests
dzhou
parents: 47216
diff changeset
    41
import java.util.Currency;
8d140834fbb0 8210406: Refactor java.util.PluggableLocale:i18n shell tests to plain java tests
dzhou
parents: 47216
diff changeset
    42
import java.util.HashSet;
8d140834fbb0 8210406: Refactor java.util.PluggableLocale:i18n shell tests to plain java tests
dzhou
parents: 47216
diff changeset
    43
import java.util.List;
8d140834fbb0 8210406: Refactor java.util.PluggableLocale:i18n shell tests to plain java tests
dzhou
parents: 47216
diff changeset
    44
import java.util.Locale;
8d140834fbb0 8210406: Refactor java.util.PluggableLocale:i18n shell tests to plain java tests
dzhou
parents: 47216
diff changeset
    45
import java.util.Set;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
7787
d2420a14d0a2 7003643: [Fmt-Me] MessageFormat.toPattern produces wrong quoted string and subformat modifiers
okutsu
parents: 5506
diff changeset
    47
import com.foo.FooNumberFormat;
52187
8d140834fbb0 8210406: Refactor java.util.PluggableLocale:i18n shell tests to plain java tests
dzhou
parents: 47216
diff changeset
    48
import com.foo.NumberFormatProviderImpl;
8d140834fbb0 8210406: Refactor java.util.PluggableLocale:i18n shell tests to plain java tests
dzhou
parents: 47216
diff changeset
    49
8d140834fbb0 8210406: Refactor java.util.PluggableLocale:i18n shell tests to plain java tests
dzhou
parents: 47216
diff changeset
    50
import sun.util.locale.provider.LocaleProviderAdapter;
7787
d2420a14d0a2 7003643: [Fmt-Me] MessageFormat.toPattern produces wrong quoted string and subformat modifiers
okutsu
parents: 5506
diff changeset
    51
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
public class NumberFormatProviderTest extends ProviderTest {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
52187
8d140834fbb0 8210406: Refactor java.util.PluggableLocale:i18n shell tests to plain java tests
dzhou
parents: 47216
diff changeset
    54
    NumberFormatProviderImpl nfp = new NumberFormatProviderImpl();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    List<Locale> availloc = Arrays.asList(NumberFormat.getAvailableLocales());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    List<Locale> providerloc = Arrays.asList(nfp.getAvailableLocales());
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 7787
diff changeset
    57
    List<Locale> jreloc = Arrays.asList(LocaleProviderAdapter.forJRE().getAvailableLocales());
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 7787
diff changeset
    58
    List<Locale> jreimplloc = Arrays.asList(LocaleProviderAdapter.forJRE().getNumberFormatProvider().getAvailableLocales());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    public static void main(String[] s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        new NumberFormatProviderTest();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    NumberFormatProviderTest() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        availableLocalesTest();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        objectValidityTest();
7787
d2420a14d0a2 7003643: [Fmt-Me] MessageFormat.toPattern produces wrong quoted string and subformat modifiers
okutsu
parents: 5506
diff changeset
    67
        messageFormatTest();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    void availableLocalesTest() {
14418
967376921f20 8001205: Calendar.getDisplayName(...): Returns null when provider is SPI but there is no SPI implementation
naoto
parents: 13583
diff changeset
    71
        Set<Locale> localesFromAPI = new HashSet<>(availloc);
967376921f20 8001205: Calendar.getDisplayName(...): Returns null when provider is SPI but there is no SPI implementation
naoto
parents: 13583
diff changeset
    72
        Set<Locale> localesExpected = new HashSet<>(jreloc);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        localesExpected.addAll(providerloc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        if (localesFromAPI.equals(localesExpected)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
            System.out.println("availableLocalesTest passed.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
            throw new RuntimeException("availableLocalesTest failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    void objectValidityTest() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        for (Locale target: availloc) {
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 7787
diff changeset
    84
            boolean jreSupportsLocale = jreimplloc.contains(target);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
            // JRE string arrays
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
            String[] jreNumberPatterns = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
            if (jreSupportsLocale) {
15260
7af2d7a87806 7162007: Clean up i18n related caches
naoto
parents: 14418
diff changeset
    89
                jreNumberPatterns = LocaleProviderAdapter.forJRE().getLocaleResources(target).getNumberPatterns();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
            // result object
7787
d2420a14d0a2 7003643: [Fmt-Me] MessageFormat.toPattern produces wrong quoted string and subformat modifiers
okutsu
parents: 5506
diff changeset
    93
            String resultCur = getPattern(NumberFormat.getCurrencyInstance(target));
d2420a14d0a2 7003643: [Fmt-Me] MessageFormat.toPattern produces wrong quoted string and subformat modifiers
okutsu
parents: 5506
diff changeset
    94
            String resultInt = getPattern(NumberFormat.getIntegerInstance(target));
d2420a14d0a2 7003643: [Fmt-Me] MessageFormat.toPattern produces wrong quoted string and subformat modifiers
okutsu
parents: 5506
diff changeset
    95
            String resultNum = getPattern(NumberFormat.getNumberInstance(target));
d2420a14d0a2 7003643: [Fmt-Me] MessageFormat.toPattern produces wrong quoted string and subformat modifiers
okutsu
parents: 5506
diff changeset
    96
            String resultPer = getPattern(NumberFormat.getPercentInstance(target));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
            // provider's object (if any)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
            String providersCur = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
            String providersInt = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
            String providersNum = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
            String providersPer = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
            if (providerloc.contains(target)) {
7787
d2420a14d0a2 7003643: [Fmt-Me] MessageFormat.toPattern produces wrong quoted string and subformat modifiers
okutsu
parents: 5506
diff changeset
   104
                NumberFormat dfCur = nfp.getCurrencyInstance(target);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
                if (dfCur != null) {
7787
d2420a14d0a2 7003643: [Fmt-Me] MessageFormat.toPattern produces wrong quoted string and subformat modifiers
okutsu
parents: 5506
diff changeset
   106
                    providersCur = getPattern(dfCur);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
                }
7787
d2420a14d0a2 7003643: [Fmt-Me] MessageFormat.toPattern produces wrong quoted string and subformat modifiers
okutsu
parents: 5506
diff changeset
   108
                NumberFormat dfInt = nfp.getIntegerInstance(target);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
                if (dfInt != null) {
7787
d2420a14d0a2 7003643: [Fmt-Me] MessageFormat.toPattern produces wrong quoted string and subformat modifiers
okutsu
parents: 5506
diff changeset
   110
                    providersInt = getPattern(dfInt);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
                }
7787
d2420a14d0a2 7003643: [Fmt-Me] MessageFormat.toPattern produces wrong quoted string and subformat modifiers
okutsu
parents: 5506
diff changeset
   112
                NumberFormat dfNum = nfp.getNumberInstance(target);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
                if (dfNum != null) {
7787
d2420a14d0a2 7003643: [Fmt-Me] MessageFormat.toPattern produces wrong quoted string and subformat modifiers
okutsu
parents: 5506
diff changeset
   114
                    providersNum = getPattern(dfNum);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
                }
7787
d2420a14d0a2 7003643: [Fmt-Me] MessageFormat.toPattern produces wrong quoted string and subformat modifiers
okutsu
parents: 5506
diff changeset
   116
                NumberFormat dfPer = nfp.getPercentInstance(target);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
                if (dfPer != null) {
7787
d2420a14d0a2 7003643: [Fmt-Me] MessageFormat.toPattern produces wrong quoted string and subformat modifiers
okutsu
parents: 5506
diff changeset
   118
                    providersPer = getPattern(dfPer);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
            // JRE's object (if any)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
            // note that this totally depends on the current implementation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
            String jresCur = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
            String jresInt = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
            String jresNum = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
            String jresPer = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
            if (jreSupportsLocale) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
                DecimalFormat dfCur = new DecimalFormat(jreNumberPatterns[1],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
                    DecimalFormatSymbols.getInstance(target));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
                if (dfCur != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
                    adjustForCurrencyDefaultFractionDigits(dfCur);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
                    jresCur = dfCur.toPattern();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
                DecimalFormat dfInt = new DecimalFormat(jreNumberPatterns[0],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
                    DecimalFormatSymbols.getInstance(target));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
                if (dfInt != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
                    dfInt.setMaximumFractionDigits(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
                    dfInt.setDecimalSeparatorAlwaysShown(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
                    dfInt.setParseIntegerOnly(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
                    jresInt = dfInt.toPattern();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
                DecimalFormat dfNum = new DecimalFormat(jreNumberPatterns[0],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
                    DecimalFormatSymbols.getInstance(target));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
                if (dfNum != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
                    jresNum = dfNum.toPattern();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
                DecimalFormat dfPer = new DecimalFormat(jreNumberPatterns[2],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
                    DecimalFormatSymbols.getInstance(target));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
                if (dfPer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
                    jresPer = dfPer.toPattern();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
            checkValidity(target, jresCur, providersCur, resultCur, jreSupportsLocale);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
            checkValidity(target, jresInt, providersInt, resultInt, jreSupportsLocale);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
            checkValidity(target, jresNum, providersNum, resultNum, jreSupportsLocale);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
            checkValidity(target, jresPer, providersPer, resultPer, jreSupportsLocale);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     * Adjusts the minimum and maximum fraction digits to values that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     * are reasonable for the currency's default fraction digits.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    void adjustForCurrencyDefaultFractionDigits(DecimalFormat df) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        DecimalFormatSymbols dfs = df.getDecimalFormatSymbols();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        Currency currency = dfs.getCurrency();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        if (currency == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
                currency = Currency.getInstance(dfs.getInternationalCurrencySymbol());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
            } catch (IllegalArgumentException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        if (currency != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
            int digits = currency.getDefaultFractionDigits();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
            if (digits != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
                int oldMinDigits = df.getMinimumFractionDigits();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
                // Common patterns are "#.##", "#.00", "#".
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
                // Try to adjust all of them in a reasonable way.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
                if (oldMinDigits == df.getMaximumFractionDigits()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
                    df.setMinimumFractionDigits(digits);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
                    df.setMaximumFractionDigits(digits);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
                    df.setMinimumFractionDigits(Math.min(digits, oldMinDigits));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
                    df.setMaximumFractionDigits(digits);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    }
7787
d2420a14d0a2 7003643: [Fmt-Me] MessageFormat.toPattern produces wrong quoted string and subformat modifiers
okutsu
parents: 5506
diff changeset
   191
d2420a14d0a2 7003643: [Fmt-Me] MessageFormat.toPattern produces wrong quoted string and subformat modifiers
okutsu
parents: 5506
diff changeset
   192
    private static String getPattern(NumberFormat nf) {
d2420a14d0a2 7003643: [Fmt-Me] MessageFormat.toPattern produces wrong quoted string and subformat modifiers
okutsu
parents: 5506
diff changeset
   193
        if (nf instanceof DecimalFormat) {
d2420a14d0a2 7003643: [Fmt-Me] MessageFormat.toPattern produces wrong quoted string and subformat modifiers
okutsu
parents: 5506
diff changeset
   194
            return ((DecimalFormat)nf).toPattern();
d2420a14d0a2 7003643: [Fmt-Me] MessageFormat.toPattern produces wrong quoted string and subformat modifiers
okutsu
parents: 5506
diff changeset
   195
        }
d2420a14d0a2 7003643: [Fmt-Me] MessageFormat.toPattern produces wrong quoted string and subformat modifiers
okutsu
parents: 5506
diff changeset
   196
        if (nf instanceof FooNumberFormat) {
d2420a14d0a2 7003643: [Fmt-Me] MessageFormat.toPattern produces wrong quoted string and subformat modifiers
okutsu
parents: 5506
diff changeset
   197
            return ((FooNumberFormat)nf).toPattern();
d2420a14d0a2 7003643: [Fmt-Me] MessageFormat.toPattern produces wrong quoted string and subformat modifiers
okutsu
parents: 5506
diff changeset
   198
        }
d2420a14d0a2 7003643: [Fmt-Me] MessageFormat.toPattern produces wrong quoted string and subformat modifiers
okutsu
parents: 5506
diff changeset
   199
        return null;
d2420a14d0a2 7003643: [Fmt-Me] MessageFormat.toPattern produces wrong quoted string and subformat modifiers
okutsu
parents: 5506
diff changeset
   200
    }
d2420a14d0a2 7003643: [Fmt-Me] MessageFormat.toPattern produces wrong quoted string and subformat modifiers
okutsu
parents: 5506
diff changeset
   201
d2420a14d0a2 7003643: [Fmt-Me] MessageFormat.toPattern produces wrong quoted string and subformat modifiers
okutsu
parents: 5506
diff changeset
   202
    private static final String[] NUMBER_PATTERNS = {
d2420a14d0a2 7003643: [Fmt-Me] MessageFormat.toPattern produces wrong quoted string and subformat modifiers
okutsu
parents: 5506
diff changeset
   203
        "num={0,number}",
d2420a14d0a2 7003643: [Fmt-Me] MessageFormat.toPattern produces wrong quoted string and subformat modifiers
okutsu
parents: 5506
diff changeset
   204
        "num={0,number,currency}",
d2420a14d0a2 7003643: [Fmt-Me] MessageFormat.toPattern produces wrong quoted string and subformat modifiers
okutsu
parents: 5506
diff changeset
   205
        "num={0,number,percent}",
d2420a14d0a2 7003643: [Fmt-Me] MessageFormat.toPattern produces wrong quoted string and subformat modifiers
okutsu
parents: 5506
diff changeset
   206
        "num={0,number,integer}"
d2420a14d0a2 7003643: [Fmt-Me] MessageFormat.toPattern produces wrong quoted string and subformat modifiers
okutsu
parents: 5506
diff changeset
   207
    };
d2420a14d0a2 7003643: [Fmt-Me] MessageFormat.toPattern produces wrong quoted string and subformat modifiers
okutsu
parents: 5506
diff changeset
   208
d2420a14d0a2 7003643: [Fmt-Me] MessageFormat.toPattern produces wrong quoted string and subformat modifiers
okutsu
parents: 5506
diff changeset
   209
    void messageFormatTest() {
d2420a14d0a2 7003643: [Fmt-Me] MessageFormat.toPattern produces wrong quoted string and subformat modifiers
okutsu
parents: 5506
diff changeset
   210
        for (Locale target : providerloc) {
d2420a14d0a2 7003643: [Fmt-Me] MessageFormat.toPattern produces wrong quoted string and subformat modifiers
okutsu
parents: 5506
diff changeset
   211
            for (String pattern : NUMBER_PATTERNS) {
d2420a14d0a2 7003643: [Fmt-Me] MessageFormat.toPattern produces wrong quoted string and subformat modifiers
okutsu
parents: 5506
diff changeset
   212
                MessageFormat mf = new MessageFormat(pattern, target);
d2420a14d0a2 7003643: [Fmt-Me] MessageFormat.toPattern produces wrong quoted string and subformat modifiers
okutsu
parents: 5506
diff changeset
   213
                String toPattern = mf.toPattern();
d2420a14d0a2 7003643: [Fmt-Me] MessageFormat.toPattern produces wrong quoted string and subformat modifiers
okutsu
parents: 5506
diff changeset
   214
                if (!pattern.equals(toPattern)) {
d2420a14d0a2 7003643: [Fmt-Me] MessageFormat.toPattern produces wrong quoted string and subformat modifiers
okutsu
parents: 5506
diff changeset
   215
                    throw new RuntimeException("MessageFormat.toPattern: got '"
d2420a14d0a2 7003643: [Fmt-Me] MessageFormat.toPattern produces wrong quoted string and subformat modifiers
okutsu
parents: 5506
diff changeset
   216
                                               + toPattern
d2420a14d0a2 7003643: [Fmt-Me] MessageFormat.toPattern produces wrong quoted string and subformat modifiers
okutsu
parents: 5506
diff changeset
   217
                                               + "', expected '" + pattern + "'");
d2420a14d0a2 7003643: [Fmt-Me] MessageFormat.toPattern produces wrong quoted string and subformat modifiers
okutsu
parents: 5506
diff changeset
   218
                }
d2420a14d0a2 7003643: [Fmt-Me] MessageFormat.toPattern produces wrong quoted string and subformat modifiers
okutsu
parents: 5506
diff changeset
   219
            }
d2420a14d0a2 7003643: [Fmt-Me] MessageFormat.toPattern produces wrong quoted string and subformat modifiers
okutsu
parents: 5506
diff changeset
   220
        }
d2420a14d0a2 7003643: [Fmt-Me] MessageFormat.toPattern produces wrong quoted string and subformat modifiers
okutsu
parents: 5506
diff changeset
   221
    }
52187
8d140834fbb0 8210406: Refactor java.util.PluggableLocale:i18n shell tests to plain java tests
dzhou
parents: 47216
diff changeset
   222
}