Path: blob/master/test/jdk/java/util/Locale/Bug8166994.java
41149 views
/*1* Copyright (c) 2016, 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 816688425* @summary Checks the subsequent call to parse the same language ranges26* which must generate the same list of language ranges27* i.e. the priority list containing equivalents, as in the28* first call29*/3031import java.util.Arrays;32import java.util.List;33import java.util.Locale;34import java.util.stream.Collectors;3536public class Bug8166994 {3738public static void main(String[] args) {39List<String> list = Arrays.asList("ccq-aa", "ybd-aa", "rki-aa");40String ranges = "ccq-aa";41testParseConsistency(list, ranges);4243// consecutive call to check the language range parse consistency44testParseConsistency(list, ranges);4546// another case with ranges consisting of multiple equivalents and47// single equivalents48list = Arrays.asList("gfx-xz", "oun-xz", "mwj-xz", "vaj-xz",49"taj-xy", "tsf-xy");50ranges = "gfx-xz, taj-xy";51testParseConsistency(list, ranges);52// consecutive call to check the language range parse consistency53testParseConsistency(list, ranges);5455}5657private static void testParseConsistency(List<String> list, String ranges) {58List<String> priorityList = parseRanges(ranges);59if (!list.equals(priorityList)) {60throw new RuntimeException("Failed to parse the language range ["61+ ranges + "], Expected: " + list + " Found: "62+ priorityList);63}64}6566private static List<String> parseRanges(String s) {67return Locale.LanguageRange.parse(s).stream()68.map(Locale.LanguageRange::getRange)69.collect(Collectors.toList());70}7172}73747576