jdk/test/java/util/Formatter/Constructors.java
author ohair
Tue, 22 Jun 2010 17:26:32 -0700
changeset 5967 26b773bf22ea
parent 5506 202f599c92aa
child 6489 9e7015635425
permissions -rw-r--r--
6933622: Duplicate class files in rt.jar and charsets.jar 6895003: JarReorder is not excluding a requested file. Reviewed-by: jjg
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 2004, 2006, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
/* @test
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
 * @bug 4981811 4984465 5064492 6240171
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
 * @summary Unit test for all constructors introduced by the formatter feature
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.io.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.nio.charset.Charset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
public class Constructors {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
    private static int fail = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
    private static int pass = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
    private static Throwable first;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
    static void pass() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
        pass++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    static void fail(String fs) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
        String s = "'" + fs + "': exception not thrown";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
        if (first == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
            first = new RuntimeException(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
        System.err.println("FAILED: " + s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
        fail++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    static void fail(String fs, Throwable ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
        String s = "'" + fs + "': " + ex.getClass().getName() + " thrown";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
        if (first == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
            first = ex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
        System.err.println("FAILED: " + s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
        fail++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    static void locale(Formatter f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        locale(f, Locale.getDefault());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    static void locale(Formatter f, Locale l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
            if ((l != null && !l.equals(f.locale()))
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
                || (l == null && f.locale() != null))
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
                    throw new RuntimeException(f.locale() + " != " + l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
            pass();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        } catch (RuntimeException x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
            fail(x.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    static void out(Formatter f, Class c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
            Appendable a = f.out();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
            if (!c.isInstance(a))
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
                throw new RuntimeException(a.getClass().getName()
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
                                           + " != " + c.getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
            pass();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        } catch (RuntimeException x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
            fail(x.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    public static void main(String [] args) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        // Formatter()
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
            Formatter f = new Formatter();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
            pass();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
            out(f, StringBuilder.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
            locale(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        } catch (Exception x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
            fail("new Formatter()", x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        // Formatter(Appendable a)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
            Formatter f = new Formatter((Appendable) null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
            pass();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
            out(f, StringBuilder.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
            locale(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        } catch (Exception x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
            fail("new Formatter((Appendable)null)", x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        // Formatter(Locale l)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
            Formatter f = new Formatter((Locale) null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
            pass();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
            out(f, StringBuilder.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
            locale(f, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        } catch (Exception x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
            fail("new Formatter((Locale)null)", x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        // Formatter(Appendable a, Locale l)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
            Formatter f = new Formatter((Appendable) null, (Locale) null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
            pass();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
            out(f, StringBuilder.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
            locale(f, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        } catch (Exception x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
            fail("new Formatter((Appendable) null, (Locale) null)", x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        // Formatter(String fileName)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
            Formatter f = new Formatter("foo");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
            pass();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
            out(f, BufferedWriter.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
            locale(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        } catch (Exception x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
            fail("new Formatter(\"foo\")", x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
            Formatter f = new Formatter((String)null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
            fail("new Formatter((String)null)");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        } catch (NullPointerException x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
            pass();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        } catch (Exception x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
            fail("new Formatter((String)null)", x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        // Formatter(String fileName, String csn)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
            Formatter f = new Formatter("foo", "UTF-8");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
            pass();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
            out(f, BufferedWriter.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
            locale(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        } catch (Exception x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
            fail("new Formatter(\"foo\", \"UTF-8\")", x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
            new Formatter("foo", "bar");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
            fail("new Formatter(\"foo\", \"bar\")");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        } catch (UnsupportedEncodingException x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
            pass();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        } catch (Exception x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
            fail("new Formatter(\"foo\", \"bar\")", x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
            new Formatter(".", "bar");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
            fail("new Formatter(\".\", \"bar\")");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        } catch (FileNotFoundException x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
            pass();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        } catch (Exception x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
            fail("new Formatter(\".\", \"bar\")", x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        // Formatter(String fileName, String csn, Locale l)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
            Formatter f = new Formatter("foo", "ISO-8859-1", Locale.GERMANY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
            pass();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
            out(f, BufferedWriter.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
            locale(f, Locale.GERMANY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        } catch (Exception x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
            fail("new Formatter(\"foo\", \"ISO-8859-1\", Locale.GERMANY)", x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
            Formatter f = new Formatter("foo", "ISO-8859-1", null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
            pass();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
            locale(f, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
            out(f, BufferedWriter.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        } catch (Exception x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
            fail("new Formatter(\"foo\", \"ISO-8859-1\", null)", x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        // Formatter(File)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
            Formatter f = new Formatter(new File("foo"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
            pass();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
            locale(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
            out(f, BufferedWriter.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        } catch (Exception x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
            fail("new Formatter(new File(\"foo\")", x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
            Formatter f = new Formatter((File)null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
            fail("new Formatter((File)null)");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        } catch (NullPointerException x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
            pass();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        } catch (Exception x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
            fail("new Formatter((File)null)", x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        // Formatter(PrintStream ps)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
            // ambiguity detected at compile-time
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
            Formatter f = new Formatter(System.out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
            pass();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
            out(f, PrintStream.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
            locale(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        } catch (Exception x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
            fail("new Formatter(System.out)", x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
            new Formatter((PrintStream) null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
            fail("new Formatter((PrintStream) null)");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        } catch (NullPointerException x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
            pass();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        } catch (Exception x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
            fail("new Formatter((PrintStream) null)", x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
            Formatter f = new Formatter(new PrintStream("foo"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
            pass();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
            locale(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
            out(f, PrintStream.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        } catch (FileNotFoundException x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
            fail("new Formatter(new PrintStream(\"foo\")", x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        } catch (Exception x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
            fail("new Formatter(new PrintStream(\"foo\")", x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
            Formatter f = new Formatter(new PrintStream("foo"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
                                        Locale.JAPANESE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
            pass();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
            locale(f, Locale.JAPANESE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
            out(f, PrintStream.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        } catch (FileNotFoundException x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
            fail("new Formatter(new PrintStream(\"foo\")", x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        } catch (Exception x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
            fail("new Formatter(new PrintStream(\"foo\")", x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
            // The cast here is necessary to avoid an ambiguity error
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
            // between Formatter(Appendable a, Locale l)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
            // and     Formatter(OutputStream os, String csn)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
            Formatter f = new Formatter(new PrintStream("foo"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
                                        (String)null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
            fail("new Formatter(new PrintStream(\"foo\"), (String)null)");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        } catch (FileNotFoundException x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
            fail("new Formatter(new PrintStream(\"foo\"), (String)null)", x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        } catch (NullPointerException x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
            pass();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        } catch (UnsupportedEncodingException x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
            fail("new Formatter(new PrintStream(\"foo\"), (String)null)", x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        } catch (Exception x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
            fail("new Formatter(new PrintStream(\"foo\"), (String)null)", x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
            // The cast here is necessary to avoid an ambiguity error
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
            // between Formatter(Appendable a, Locale l)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
            // and     Formatter(OutputStream os, String csn)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
            Formatter f = new Formatter(new PrintStream("foo"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
                                        (Locale)null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
            pass();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
            locale(f, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
            out(f, PrintStream.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
        } catch (FileNotFoundException x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
            fail("new Formatter(new PrintStream(\"foo\"), (Locale)null)", x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        } catch (Exception x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
            fail("new Formatter(new PrintStream(\"foo\"), (Locale)null)", x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
            Formatter f = new Formatter(new PrintStream("foo"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
                                        Locale.KOREAN);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
            pass();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
            locale(f, Locale.KOREAN);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
            out(f, PrintStream.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
        } catch (FileNotFoundException x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
            fail("new Formatter(new PrintStream(\"foo\"), Locale.KOREAN)", x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
        } catch (Exception x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
            fail("new Formatter(new PrintStream(\"foo\"), Locale.KOREAN)", x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
            Formatter f = new Formatter(new PrintStream("foo"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
                                        "UTF-16BE", null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
            pass();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
            locale(f, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
            out(f, BufferedWriter.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
        } catch (FileNotFoundException x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
            fail("new Formatter(new PrintStream(\"foo\"), \"UTF-16BE\", null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
        } catch (UnsupportedEncodingException x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
            fail("new Formatter(new PrintStream(\"foo\"), \"UTF-16BE\", null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
        } catch (Exception x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
            fail("new Formatter(new PrintStream(\"foo\"), \"UTF-16BE\", null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
            Formatter f = new Formatter(new PrintStream("foo"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
                                        "UTF-16BE", Locale.ITALIAN);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
            pass();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
            locale(f, Locale.ITALIAN);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
            out(f, BufferedWriter.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
        } catch (FileNotFoundException x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
            fail("new Formatter(new PrintStream(\"foo\"), \"UTF-16BE\", Locale.ITALIAN");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
        } catch (UnsupportedEncodingException x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
            fail("new Formatter(new PrintStream(\"foo\"), \"UTF-16BE\", Locale.ITALIAN");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
        } catch (Exception x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
            fail("new Formatter(new PrintStream(\"foo\"), \"UTF-16BE\", Locale.ITALIAN");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
        String csn = Charset.defaultCharset().newEncoder().canEncode('\u00a3') ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
            "ASCII" : "ISO-8859-1";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
            ByteArrayOutputStream bs[] = { new ByteArrayOutputStream(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
                                           new ByteArrayOutputStream(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
                                           new ByteArrayOutputStream()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
            };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
            new Formatter((Appendable)  new PrintStream(bs[0], true, csn)).format("\u00a3");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
            new Formatter((OutputStream)new PrintStream(bs[1], true, csn)).format("\u00a3");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
            new Formatter(              new PrintStream(bs[2], true, csn)).format("\u00a3");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
            if (Arrays.equals(bs[0].toByteArray(), bs[1].toByteArray())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
                fail("arrays shouldn't match: " + bs[0].toByteArray());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
                pass();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
            if (! Arrays.equals(bs[0].toByteArray(), bs[2].toByteArray())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
                fail("arrays should match: " + bs[0].toByteArray() + " != "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
                     + bs[2].toByteArray());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
                pass();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
        } catch (UnsupportedEncodingException x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
            fail("new PrintStream(newByteArrayOutputStream, true, " + csn + ")", x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
        // Formatter(OutputStream os)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
            new Formatter((OutputStream) null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
            fail("new Formatter((OutputStream) null)");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
        } catch (NullPointerException x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
            pass();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
        } catch (Exception x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
            fail("new Formatter((OutputStream) null)", x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
            Formatter f = new Formatter((OutputStream) new PrintStream("foo"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
            pass();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
            locale(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
            out(f, BufferedWriter.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
        } catch (Exception x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
            fail("new Formatter((OutputStream) new PrintStream(\"foo\")", x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
        // Formatter(OutputStream os, String csn)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
            new Formatter((OutputStream) null, "ISO-8859-1");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
            fail("new Formatter((OutputStream) null, \"ISO-8859-1\")");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
        } catch (NullPointerException x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
            pass();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
        } catch (Exception x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
            fail("new Formatter((OutputStream) null, \"ISO-8859-1\")", x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
            new Formatter((OutputStream) new PrintStream("foo"), null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
            fail("new Formatter((OutputStream) new PrintStream(\"foo\"), null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
        } catch (NullPointerException x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
            pass();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
        } catch (Exception x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
            fail("new Formatter((OutputStream) new PrintStream(\"foo\"), null",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
                 x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
            new Formatter(new PrintStream("foo"), "bar");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
            fail("new Formatter(new PrintStream(\"foo\"), \"bar\")");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
        } catch (UnsupportedEncodingException x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
            pass();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
        } catch (Exception x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
            fail("new Formatter(new PrintStream(\"foo\"), \"bar\")", x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
            Formatter f = new Formatter(new PrintStream("foo"), "UTF-8");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
            pass();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
            locale(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
            out(f, BufferedWriter.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
        } catch (Exception x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
            fail("new Formatter(new PrintStream(\"foo\"), \"UTF-8\")", x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
        // Formatter(OutputStream os, String csn, Locale l)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
            new Formatter((OutputStream) null, "ISO-8859-1", Locale.UK);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
            fail("new Formatter((OutputStream) null, \"ISO-8859-1\", Locale.UK)");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
        } catch (NullPointerException x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
            pass();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
        } catch (Exception x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
            fail("new Formatter((OutputStream) null, \"ISO-8859-1\", Locale.UK)",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
                 x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
            new Formatter(new PrintStream("foo"), null, Locale.UK);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
            fail("new Formatter(new PrintStream(\"foo\"), null, Locale.UK)");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
        } catch (NullPointerException x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
            pass();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
        } catch (Exception x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
            fail("new Formatter(new PrintStream(\"foo\"), null, Locale.UK)",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
                 x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
            new Formatter(new PrintStream("foo"), "bar", Locale.UK);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
            fail("new Formatter(new PrintStream(\"foo\"), \"bar\", Locale.UK)");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
        } catch (UnsupportedEncodingException x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
            pass();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
        } catch (Exception x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
            fail("new Formatter(new PrintStream(\"foo\"), \"bar\", Locale.UK)",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
                 x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
            Formatter f
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
                = new Formatter(new PrintStream("foo"), "UTF-8", Locale.UK);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
            pass();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
            out(f, BufferedWriter.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
            locale(f, Locale.UK);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
        } catch (Exception x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
            fail("new Formatter(new PrintStream(\"foo\"), \"UTF-8\"), Locale.UK",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
                 x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
        // PrintStream(String fileName)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
            new PrintStream("foo");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
            pass();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
        } catch (Exception x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
            fail("new PrintStream(\"foo\")", x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
        // PrintStream(String fileName, String csn)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
            new PrintStream("foo", null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
            fail("new PrintStream(\"foo\", null)");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
        } catch (NullPointerException x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
            pass();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
        } catch (Exception x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
            fail("new PrintStream(\"foo\", null)", x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
        // PrintStream(File file)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
            new PrintStream(new File("foo"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
            pass();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
        } catch (Exception x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
            fail("new PrintStream(new File(\"foo\"))", x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
        // PrintStream(File file, String csn)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
            new PrintStream(new File("foo"), null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
            fail("new PrintStream(new File(\"foo\"), null)");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
        } catch (NullPointerException x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
            pass();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
        } catch (Exception x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
            fail("new PrintStream(new File(\"foo\"), null)", x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
        // PrintWriter(String fileName)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
            new PrintWriter("foo");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
            pass();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
        } catch (Exception x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
            fail("new PrintWriter(\"foo\")", x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
        // PrintWriter(String fileName, String csn)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
            new PrintWriter("foo", null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
            fail("new PrintWriter(\"foo\"), null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
        } catch (NullPointerException x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
            pass();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
        } catch (Exception x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
            fail("new PrintWriter(\"foo\"), null", x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
        // PrintWriter(File file)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
            new PrintWriter(new File("foo"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
            pass();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
        } catch (Exception x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
            fail("new PrintWriter(new File(\"foo\"))", x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
        // PrintWriter(File file, String csn)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
            new PrintWriter(new File("foo"), null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
            fail("new PrintWriter(new File(\"foo\")), null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
        } catch (NullPointerException x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
            pass();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
        } catch (Exception x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
            fail("new PrintWriter(new File(\"foo\")), null", x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
        if (fail != 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
            throw new RuntimeException((fail + pass) + " tests: "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
                                       + fail + " failure(s), first", first);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
            System.out.println("all " + (fail + pass) + " tests passed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
}