Path: blob/master/test/jdk/java/text/Format/common/Bug6215962.java
41152 views
/*1* Copyright (c) 2005, 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*/2223/*24* @test25* @bug 621596226* @summary Confirm that replacing Utility.arayEquals methods have with27* Arrays.equals introduces no problem.28*/29import java.text.*;30import java.util.*;3132public class Bug6215962 {3334public static void main(String[] args) {35testMessageFormat();36testChoiceFormat();37testDateFormatSymbols();38}3940/**41* Test cases for MessageFormat42*/43static void testMessageFormat() {44MessageFormat mf1 = new MessageFormat("{0}", null);45MessageFormat mf2 = new MessageFormat("{0}", null);46check(mf1, mf2, true);4748mf1.setLocale(null);49check(mf1, mf2, true);5051mf1 = new MessageFormat("{0}", Locale.US);52check(mf1, mf2, false);5354mf2 = new MessageFormat("{0}", Locale.JAPAN);55check(mf1, mf2, false);5657mf1 = new MessageFormat("{0}", new Locale("ja", "JP"));58check(mf1, mf2, true);5960mf1.setLocale(null);61check(mf1, mf2, false);6263mf1 = new MessageFormat("{0}", new Locale("ja", "JP", "FOO"));64check(mf1, mf2, false);6566mf2 = new MessageFormat("{1}", new Locale("ja", "JP", "FOO"));67check(mf1, mf2, false);6869mf1 = new MessageFormat("{1}", new Locale("ja", "JP", "FOO"));70check(mf1, mf2, true);7172mf1 = new MessageFormat("{1, date}", new Locale("ja", "JP", "FOO"));73check(mf1, mf2, false);7475mf2 = new MessageFormat("{1, date}", new Locale("ja", "JP", "FOO"));76check(mf1, mf2, true);77}7879static void check(MessageFormat f1, MessageFormat f2, boolean expected) {80boolean got = f1.equals(f2);81if (got != expected) {82throw new RuntimeException("Test failed for MessageFormat.equals(). Got: " + got + ", Expected: " + expected);83}84}8586/**87* Test cases for MessageFormat88*/89static void testChoiceFormat() {90double[] limits0 = {0,1,2,3,4,5,6};91double[] limits1 = {1,2,3,4,5,6,7};92String[] monthNames0 = {"Sun","Mon","Tue","Wed","Thu","Fri","Sat"};93String[] monthNames1 = {"Sun","Mon","Tue","Wed","Thur","Fri","Sat"};9495ChoiceFormat cf1 = new ChoiceFormat(limits1, monthNames0);96ChoiceFormat cf2 = new ChoiceFormat(limits1, monthNames0);97check(cf1, cf2, true);9899cf2 = new ChoiceFormat(limits0, monthNames0);100check(cf1, cf2, false);101102cf2 = new ChoiceFormat(limits1, monthNames1);103check(cf1, cf2, false);104}105106static void check(ChoiceFormat f1, ChoiceFormat f2, boolean expected) {107boolean got = f1.equals(f2);108if (got != expected) {109throw new RuntimeException("Test failed for ChoiceFormat.equals(). Got: " + got + ", Expected: " + expected);110}111}112113/**114* Test cases for DateFormatSymbols115*/116static void testDateFormatSymbols() {117DateFormatSymbols dfs1 = new DateFormatSymbols();118DateFormatSymbols dfs2 = new DateFormatSymbols();119check(dfs1, dfs2, true);120121// Becase eras, months, shortmonths, weekdays, shortweekdays, ampms are122// the same data type (String[]) and are treated in the same way, here123// I test only Months.124String[] tmp = dfs1.getMonths();125String saved = tmp[0];126tmp[0] = "Foo";127dfs1.setMonths(tmp);128check(dfs1, dfs2, false);129130tmp[0] = saved;131dfs1.setMonths(tmp);132check(dfs1, dfs2, true);133134// Test LocalizedpatternChars (String)135String pattern = dfs2.getLocalPatternChars();136dfs2.setLocalPatternChars("Bar");137check(dfs1, dfs2, false);138139dfs2.setLocalPatternChars(pattern);140check(dfs1, dfs2, true);141142// Test TimeZone strings (String[][])143String[][] zones = dfs1.getZoneStrings();144saved = zones[0][1];145zones[0][1] = "Yokohama Summer Time";146dfs1.setZoneStrings(zones);147check(dfs1, dfs2, false);148149zones[0][1] = saved;150dfs1.setZoneStrings(zones);151check(dfs1, dfs2, true);152}153154static void check(DateFormatSymbols dfs1, DateFormatSymbols dfs2, boolean expected) {155boolean got = dfs1.equals(dfs2);156if (got != expected) {157throw new RuntimeException("Test failed for DateFormatSymbols.equals(). Got: " + got + ", Expected: " + expected);158}159}160}161162163