Path: blob/master/test/jdk/java/util/IllegalFormatException/Constructors.java
41149 views
/*1* Copyright (c) 2005, 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 626591926*/2728import java.util.*;2930public class Constructors {3132private static Class NPE = NullPointerException.class;3334private static int fail = 0;35private static int pass = 0;3637private static Throwable first;3839private static void pass() {40pass++;41}4243private static void fail(Throwable t, Class c) {44String s = t.getClass().getName() + " constructor did not throw " + c.getName();45if (first == null)46first = new RuntimeException(s);47System.err.println("FAILED: " + s);48fail++;49}5051private static void nullTests() {52IllegalFormatException ex;53try {54ex = new DuplicateFormatFlagsException(null);55fail(ex, NPE);56} catch (NullPointerException x) {57pass();58}5960try {61ex = new FormatFlagsConversionMismatchException(null, 'a');62fail(ex, NPE);63} catch (NullPointerException x) {64pass();65}6667try {68ex = new IllegalFormatConversionException('b', null);69fail(ex, NPE);70} catch (NullPointerException x) {71pass();72}7374try {75ex = new IllegalFormatFlagsException(null);76fail(ex, NPE);77} catch (NullPointerException x) {78pass();79}8081try {82ex = new MissingFormatArgumentException(null);83fail(ex, NPE);84} catch (NullPointerException x) {85pass();86}8788try {89ex = new MissingFormatWidthException(null);90fail(ex, NPE);91} catch (NullPointerException x) {92pass();93}9495try {96ex = new UnknownFormatConversionException(null);97fail(ex, NPE);98} catch (NullPointerException x) {99pass();100}101102try {103ex = new UnknownFormatFlagsException(null);104fail(ex, NPE);105} catch (NullPointerException x) {106pass();107}108}109110public static void main(String [] args) {111nullTests();112113if (fail != 0)114throw new RuntimeException((fail + pass) + " tests: "115+ fail + " failure(s), first", first);116else117System.out.println("all " + (fail + pass) + " tests passed");118}119}120121122