1/* 2 * Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24/** 25 * @test 26 * @bug 6265919 27 */ 28 29import java.util.*; 30 31public class Constructors { 32 33 private static Class NPE = NullPointerException.class; 34 35 private static int fail = 0; 36 private static int pass = 0; 37 38 private static Throwable first; 39 40 private static void pass() { 41 pass++; 42 } 43 44 private static void fail(Throwable t, Class c) { 45 String s = t.getClass().getName() + " constructor did not throw " + c.getName(); 46 if (first == null) 47 first = new RuntimeException(s); 48 System.err.println("FAILED: " + s); 49 fail++; 50 } 51 52 private static void nullTests() { 53 IllegalFormatException ex; 54 try { 55 ex = new DuplicateFormatFlagsException(null); 56 fail(ex, NPE); 57 } catch (NullPointerException x) { 58 pass(); 59 } 60 61 try { 62 ex = new FormatFlagsConversionMismatchException(null, 'a'); 63 fail(ex, NPE); 64 } catch (NullPointerException x) { 65 pass(); 66 } 67 68 try { 69 ex = new IllegalFormatConversionException('b', null); 70 fail(ex, NPE); 71 } catch (NullPointerException x) { 72 pass(); 73 } 74 75 try { 76 ex = new IllegalFormatFlagsException(null); 77 fail(ex, NPE); 78 } catch (NullPointerException x) { 79 pass(); 80 } 81 82 try { 83 ex = new MissingFormatArgumentException(null); 84 fail(ex, NPE); 85 } catch (NullPointerException x) { 86 pass(); 87 } 88 89 try { 90 ex = new MissingFormatWidthException(null); 91 fail(ex, NPE); 92 } catch (NullPointerException x) { 93 pass(); 94 } 95 96 try { 97 ex = new UnknownFormatConversionException(null); 98 fail(ex, NPE); 99 } catch (NullPointerException x) { 100 pass(); 101 } 102 103 try { 104 ex = new UnknownFormatFlagsException(null); 105 fail(ex, NPE); 106 } catch (NullPointerException x) { 107 pass(); 108 } 109 } 110 111 public static void main(String [] args) { 112 nullTests(); 113 114 if (fail != 0) 115 throw new RuntimeException((fail + pass) + " tests: " 116 + fail + " failure(s), first", first); 117 else 118 System.out.println("all " + (fail + pass) + " tests passed"); 119 } 120} 121