Path: blob/master/test/jdk/java/text/Format/MessageFormat/MessageTest.java
41152 views
/*1* Copyright (c) 1997, 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* @library /java/text/testlib26* @summary test MessageFormat27*/28/*29(C) Copyright Taligent, Inc. 1996 - All Rights Reserved30(C) Copyright IBM Corp. 1996 - All Rights Reserved3132The original version of this source code and documentation is copyrighted and33owned by Taligent, Inc., a wholly-owned subsidiary of IBM. These materials are34provided under terms of a License Agreement between Taligent and Sun. This35technology is protected by multiple US and International patents. This notice and36attribution to Taligent may not be removed.37Taligent is a registered trademark of Taligent, Inc.38*/394041import java.util.*;42import java.io.*;43import java.text.*;4445public class MessageTest extends IntlTest {4647public static void main(String[] args) throws Exception {48new MessageTest().run(args);49}505152public void TestMSGPatternTest() {53Object[] testArgs = {541D, 3456D,55"Disk", new Date(10000000000L)};5657String[] testCases = {58"Quotes '', '{', 'a' {0} '{0}'",59"Quotes '', '{', 'a' {0,number} '{0}'",60"'{'1,number,'#',##} {1,number,'#',##}",61"There are {1} files on {2} at {3}",62"On {2}, there are {1} files, with {0,number,currency}.",63"'{1,number,percent}', {1,number,percent}, ",64"'{1,date,full}', {1,date,full}, ",65"'{3,date,full}', {3,date,full}, ",66"'{1,number,#,##}' {1,number,#,##}",67};6869for (int i = 0; i < testCases.length; ++i) {70Locale save = Locale.getDefault();71try {72Locale.setDefault(Locale.US);73logln("");74logln( i + " Pat in: " + testCases[i]);75MessageFormat form = new MessageFormat(testCases[i]);76logln( i + " Pat out: " + form.toPattern());77String result = form.format(testArgs);78logln( i + " Result: " + result);79Object[] values = form.parse(result);80for (int j = 0; j < testArgs.length; ++j) {81Object testArg = testArgs[j];82Object value = null;83if (j < values.length) {84value = values[j];85}86if ((testArg == null && value != null)87|| (testArg != null && !testArg.equals(value))) {88logln( i + " " + j + " old: " + testArg);89logln( i + " " + j + " new: " + value);90}91}92}93catch(java.text.ParseException pe ) {94throw new RuntimeException("Error: MessageFormat.parse throws ParseException");95}96finally{97Locale.setDefault(save);98}99}100}101}102103104