Path: blob/master/test/jdk/java/util/Formatter/NullArg.java
41149 views
/*1* Copyright (c) 2015, 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 803939026* @summary Basic test for null argument27*/2829import java.util.Formatter;30import java.util.Locale;3132public class NullArg {3334public static void main(String [] args) {35char[] cs = new char[] {36'b', 'B', 'h', 'H', 's', 'S', 'c', 'C', 'd', 'o', 'x', 'X',37'e', 'E', 'f', 'g', 'G', 'a', 'A', 't', 'T',38};39char[] tcs = new char[] {40'H', 'I', 'k', 'l', 'l', 'M', 'S', 'L', 'N', 'p', 'z', 'Z', 's',41'Q', 'B', 'b', 'h', 'A', 'a', 'C', 'Y', 'y', 'j', 'm', 'd', 'e',42'R', 'T', 'r', 'D', 'F', 'c'43};44for (char c : cs) {45String expected = (c == 'b' || c == 'B') ? "false" : "null";46if (Character.isUpperCase(c)) {47expected = expected.toUpperCase(Locale.ROOT);48}49if (c == 't' || c == 'T') {50for (char ct : tcs) {51if (!String.format("%" + c + ct, null).equals(expected)) {52throw new RuntimeException("%t" + ct + "null check failed.");53}54}55} else {56if (!String.format("%" + c , null).equals(expected)) {57throw new RuntimeException("%" + c + "null check failed.");58}59}60}61}62}636465