Path: blob/master/test/jdk/java/util/PluggableLocale/BreakIteratorProviderTest.java
41149 views
/*1* Copyright (c) 2007, 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*/2223/*24* @test25* @bug 4052440 8062588 8165804 821040626* @summary BreakIteratorProvider tests27* @library providersrc/foobarutils28* providersrc/fooprovider29* @modules java.base/sun.util.locale.provider30* java.base/sun.util.resources31* @build com.foobar.Utils32* com.foo.*33* @run main/othervm -Djava.locale.providers=JRE,SPI BreakIteratorProviderTest34*/3536import java.text.BreakIterator;37import java.util.Arrays;38import java.util.HashSet;39import java.util.List;40import java.util.Locale;41import java.util.ResourceBundle;42import java.util.Set;4344import com.foo.BreakIteratorProviderImpl;4546import sun.util.locale.provider.LocaleProviderAdapter;47import sun.util.locale.provider.ResourceBundleBasedAdapter;4849public class BreakIteratorProviderTest extends ProviderTest {5051BreakIteratorProviderImpl bip = new BreakIteratorProviderImpl();52List<Locale> availloc = Arrays.asList(BreakIterator.getAvailableLocales());53List<Locale> providerloc = Arrays.asList(bip.getAvailableLocales());54List<Locale> jreloc = Arrays.asList(LocaleProviderAdapter.forJRE().getAvailableLocales());55List<Locale> jreimplloc = Arrays.asList(LocaleProviderAdapter.forJRE().getBreakIteratorProvider().getAvailableLocales());5657public static void main(String[] s) {58new BreakIteratorProviderTest();59}6061BreakIteratorProviderTest() {62availableLocalesTest();63objectValidityTest();64}6566void availableLocalesTest() {67Set<Locale> localesFromAPI = new HashSet<>(availloc);68Set<Locale> localesExpected = new HashSet<>(jreloc);69localesExpected.addAll(providerloc);70if (localesFromAPI.equals(localesExpected)) {71System.out.println("availableLocalesTest passed.");72} else {73throw new RuntimeException("availableLocalesTest failed");74}75}7677void objectValidityTest() {7879for (Locale target: availloc) {80// pure JRE implementation81ResourceBundle rb = ((ResourceBundleBasedAdapter)LocaleProviderAdapter.forJRE()).getLocaleData().getBreakIteratorInfo(target);82String[] classNames = rb.getStringArray("BreakIteratorClasses");83boolean jreSupportsLocale = jreimplloc.contains(target);8485// result object86String[] result = new String[4];87result[0] = BreakIterator.getCharacterInstance(target).getClass().getName();88result[1] = BreakIterator.getWordInstance(target).getClass().getName();89result[2] = BreakIterator.getLineInstance(target).getClass().getName();90result[3] = BreakIterator.getSentenceInstance(target).getClass().getName();9192// provider's object (if any)93String[] providersResult = new String[4];94if (providerloc.contains(target)) {95providersResult[0] = bip.getCharacterInstance(target).getClass().getName();96providersResult[1] = bip.getWordInstance(target).getClass().getName();97providersResult[2] = bip.getLineInstance(target).getClass().getName();98providersResult[3] = bip.getSentenceInstance(target).getClass().getName();99}100101// JRE102String[] jresResult = new String[4];103if (jreSupportsLocale) {104for (int i = 0; i < 4; i++) {105jresResult[i] = "sun.text." + classNames[i];106}107}108109for (int i = 0; i < 4; i++) {110checkValidity(target, jresResult[i], providersResult[i], result[i], jreSupportsLocale);111}112}113}114}115116