1 /* 2 * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 /* 24 * @test 25 * @bug 8177552 26 * @summary Checks the compact number format with COMPAT provider. Since the 27 * compact number resources are only provided by CLDR, using COMPAT 28 * as a provider should always use the default patterns added in the 29 * FormatData.java resource bundle 30 * @modules jdk.localedata 31 * @run testng/othervm -Djava.locale.providers=COMPAT WithCompatProvider 32 */ 33 import java.math.BigDecimal; 34 import java.math.BigInteger; 35 import java.text.NumberFormat; 36 import java.text.ParseException; 37 import java.util.Locale; 38 import org.testng.annotations.DataProvider; 39 import org.testng.annotations.Test; 40 41 public class WithCompatProvider { 42 43 private static final NumberFormat FORMAT_DZ_SHORT = NumberFormat 44 .getCompactNumberInstance(new Locale("dz"), 45 NumberFormat.Style.SHORT); 46 47 private static final NumberFormat FORMAT_EN_US_SHORT = NumberFormat 48 .getCompactNumberInstance(Locale.US, 49 NumberFormat.Style.SHORT); 50 51 @DataProvider(name = "format") 52 Object[][] compactFormatData() { 53 return new Object[][]{ 54 {FORMAT_DZ_SHORT, 1000.09, "1K"}, 55 {FORMAT_DZ_SHORT, -999.99, "-1K"}, 56 {FORMAT_DZ_SHORT, -0.0, "-0"}, 57 {FORMAT_DZ_SHORT, new BigInteger("12345678901234567890"), 58 "12345679T"}, 59 {FORMAT_DZ_SHORT, new BigDecimal("12345678901234567890.89"), 60 "12345679T"}, 61 {FORMAT_EN_US_SHORT, -999.99, "-1K"}, 62 {FORMAT_EN_US_SHORT, 9999, "10K"}, 63 {FORMAT_EN_US_SHORT, 3000.90, "3K"}, 64 {FORMAT_EN_US_SHORT, new BigInteger("12345678901234567890"), 65 "12345679T"}, 66 {FORMAT_EN_US_SHORT, new BigDecimal("12345678901234567890.89"), 67 "12345679T"},}; 68 } 69 70 @DataProvider(name = "parse") 71 Object[][] compactParseData() { 72 return new Object[][]{ 73 {FORMAT_DZ_SHORT, "1K", 1000L}, 74 {FORMAT_DZ_SHORT, "-3K", -3000L}, 75 {FORMAT_DZ_SHORT, "12345700T", 1.23457E19}, 76 {FORMAT_EN_US_SHORT, "-99", -99L}, 77 {FORMAT_EN_US_SHORT, "10K", 10000L}, 78 {FORMAT_EN_US_SHORT, "12345679T", 1.2345679E19},}; 79 } 80 81 @Test(dataProvider = "format") 82 public void testFormat(NumberFormat cnf, Object number, 83 String expected) { 84 CompactFormatAndParse.testFormat(cnf, number, expected); 85 } 86 87 @Test(dataProvider = "parse") 88 public void testParse(NumberFormat cnf, String parseString, 89 Number expected) throws ParseException { 90 CompactFormatAndParse.testParse(cnf, parseString, expected, null, null); 91 } 92 93 }