Path: blob/master/test/jdk/java/text/Format/CompactNumberFormat/TestWithCompatProvider.java
41153 views
/*1* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/22/*23* @test24* @bug 817755225* @summary Checks the compact number format with COMPAT provider. Since the26* compact number resources are only provided by CLDR, using COMPAT27* as a provider should always use the default patterns added in the28* FormatData.java resource bundle29* @modules jdk.localedata30* @run testng/othervm -Djava.locale.providers=COMPAT TestWithCompatProvider31*/32import java.math.BigDecimal;33import java.math.BigInteger;34import java.text.NumberFormat;35import java.text.ParseException;36import java.util.Locale;37import org.testng.annotations.DataProvider;38import org.testng.annotations.Test;3940public class TestWithCompatProvider {4142private static final NumberFormat FORMAT_DZ_SHORT = NumberFormat43.getCompactNumberInstance(new Locale("dz"), NumberFormat.Style.SHORT);4445private static final NumberFormat FORMAT_EN_US_SHORT = NumberFormat46.getCompactNumberInstance(Locale.US, NumberFormat.Style.SHORT);4748@DataProvider(name = "format")49Object[][] compactFormatData() {50return new Object[][]{51{FORMAT_DZ_SHORT, 1000.09, "1K"},52{FORMAT_DZ_SHORT, -999.99, "-1K"},53{FORMAT_DZ_SHORT, -0.0, "-0"},54{FORMAT_DZ_SHORT, new BigInteger("12345678901234567890"), "12345679T"},55{FORMAT_DZ_SHORT, new BigDecimal("12345678901234567890.89"), "12345679T"},56{FORMAT_EN_US_SHORT, -999.99, "-1K"},57{FORMAT_EN_US_SHORT, 9999, "10K"},58{FORMAT_EN_US_SHORT, 3000.90, "3K"},59{FORMAT_EN_US_SHORT, new BigInteger("12345678901234567890"), "12345679T"},60{FORMAT_EN_US_SHORT, new BigDecimal("12345678901234567890.89"), "12345679T"},};61}6263@DataProvider(name = "parse")64Object[][] compactParseData() {65return new Object[][]{66{FORMAT_DZ_SHORT, "1K", 1000L},67{FORMAT_DZ_SHORT, "-3K", -3000L},68{FORMAT_DZ_SHORT, "12345700T", 1.23457E19},69{FORMAT_EN_US_SHORT, "-99", -99L},70{FORMAT_EN_US_SHORT, "10K", 10000L},71{FORMAT_EN_US_SHORT, "12345679T", 1.2345679E19},};72}7374@Test(dataProvider = "format")75public void testFormat(NumberFormat cnf, Object number,76String expected) {77CompactFormatAndParseHelper.testFormat(cnf, number, expected);78}7980@Test(dataProvider = "parse")81public void testParse(NumberFormat cnf, String parseString,82Number expected) throws ParseException {83CompactFormatAndParseHelper.testParse(cnf, parseString, expected, null, null);84}8586}878889