jdk/test/java/util/Formatter/Constructors.java
changeset 7966 a23e3f47c5a8
parent 7668 d4a77089c587
equal deleted inserted replaced
7817:0b2c3a61f004 7966:a23e3f47c5a8
     1 /*
     1 /*
     2  * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     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
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     7  * published by the Free Software Foundation.
    20  * or visit www.oracle.com if you need additional information or have any
    20  * or visit www.oracle.com if you need additional information or have any
    21  * questions.
    21  * questions.
    22  */
    22  */
    23 
    23 
    24 /* @test
    24 /* @test
    25  * @bug 4981811 4984465 5064492 6240171
    25  * @bug 4981811 4984465 5064492 6240171 7000511
    26  * @summary Unit test for all constructors introduced by the formatter feature
    26  * @summary Unit test for all constructors introduced by the formatter feature
    27  */
    27  */
    28 
    28 
    29 import java.io.*;
    29 import java.io.*;
    30 import java.util.*;
    30 import java.util.*;
    83             fail(x.getMessage());
    83             fail(x.getMessage());
    84         }
    84         }
    85     }
    85     }
    86 
    86 
    87     public static void main(String [] args) {
    87     public static void main(String [] args) {
    88 
       
    89         // Formatter()
    88         // Formatter()
    90         try {
    89         try (Formatter f = new Formatter()) {
    91             Formatter f = new Formatter();
       
    92             pass();
    90             pass();
    93             out(f, StringBuilder.class);
    91             out(f, StringBuilder.class);
    94             locale(f);
    92             locale(f);
    95         } catch (Exception x) {
    93         } catch (Exception x) {
    96             fail("new Formatter()", x);
    94             fail("new Formatter()", x);
    97         }
    95         }
    98 
    96 
    99         // Formatter(Appendable a)
    97         // Formatter(Appendable a)
   100         try {
    98         try (Formatter f = new Formatter((Appendable) null)) {
   101             Formatter f = new Formatter((Appendable) null);
       
   102             pass();
    99             pass();
   103             out(f, StringBuilder.class);
   100             out(f, StringBuilder.class);
   104             locale(f);
   101             locale(f);
   105         } catch (Exception x) {
   102         } catch (Exception x) {
   106             fail("new Formatter((Appendable)null)", x);
   103             fail("new Formatter((Appendable)null)", x);
   107         }
   104         }
   108 
   105 
   109         // Formatter(Locale l)
   106         // Formatter(Locale l)
   110         try {
   107         try (Formatter f = new Formatter((Locale) null)) {
   111             Formatter f = new Formatter((Locale) null);
       
   112             pass();
   108             pass();
   113             out(f, StringBuilder.class);
   109             out(f, StringBuilder.class);
   114             locale(f, null);
   110             locale(f, null);
   115         } catch (Exception x) {
   111         } catch (Exception x) {
   116             fail("new Formatter((Locale)null)", x);
   112             fail("new Formatter((Locale)null)", x);
   117         }
   113         }
   118 
   114 
   119         // Formatter(Appendable a, Locale l)
   115         // Formatter(Appendable a, Locale l)
   120         try {
   116         try (Formatter f = new Formatter((Appendable) null, (Locale) null)) {
   121             Formatter f = new Formatter((Appendable) null, (Locale) null);
       
   122             pass();
   117             pass();
   123             out(f, StringBuilder.class);
   118             out(f, StringBuilder.class);
   124             locale(f, null);
   119             locale(f, null);
   125         } catch (Exception x) {
   120         } catch (Exception x) {
   126             fail("new Formatter((Appendable) null, (Locale) null)", x);
   121             fail("new Formatter((Appendable) null, (Locale) null)", x);
   127         }
   122         }
   128 
   123 
   129         // Formatter(String fileName)
   124         // Formatter(String fileName)
   130         try {
   125         try (Formatter f = new Formatter("foo")) {
   131             Formatter f = new Formatter("foo");
       
   132             pass();
   126             pass();
   133             out(f, BufferedWriter.class);
   127             out(f, BufferedWriter.class);
   134             locale(f);
   128             locale(f);
   135         } catch (Exception x) {
   129         } catch (Exception x) {
   136             fail("new Formatter(\"foo\")", x);
   130             fail("new Formatter(\"foo\")", x);
   137         }
   131         }
   138 
   132 
   139         try {
   133         try {
   140             Formatter f = new Formatter((String)null);
   134             new Formatter((String)null);
   141             fail("new Formatter((String)null)");
   135             fail("new Formatter((String)null)");
   142         } catch (NullPointerException x) {
   136         } catch (NullPointerException x) {
   143             pass();
   137             pass();
   144         } catch (Exception x) {
   138         } catch (Exception x) {
   145             fail("new Formatter((String)null)", x);
   139             fail("new Formatter((String)null)", x);
   146         }
   140         }
   147 
   141 
   148         // Formatter(String fileName, String csn)
   142         // Formatter(String fileName, String csn)
   149         try {
   143         try (Formatter f = new Formatter("foo", "UTF-8")) {
   150             Formatter f = new Formatter("foo", "UTF-8");
       
   151             pass();
   144             pass();
   152             out(f, BufferedWriter.class);
   145             out(f, BufferedWriter.class);
   153             locale(f);
   146             locale(f);
   154         } catch (Exception x) {
   147         } catch (Exception x) {
   155             fail("new Formatter(\"foo\", \"UTF-8\")", x);
   148             fail("new Formatter(\"foo\", \"UTF-8\")", x);
   165         }
   158         }
   166 
   159 
   167         try {
   160         try {
   168             new Formatter(".", "bar");
   161             new Formatter(".", "bar");
   169             fail("new Formatter(\".\", \"bar\")");
   162             fail("new Formatter(\".\", \"bar\")");
   170         } catch (FileNotFoundException x) {
   163         } catch (FileNotFoundException|UnsupportedEncodingException x) {
   171             pass();
   164             pass();
   172         } catch (Exception x) {
   165         } catch (Exception x) {
   173             fail("new Formatter(\".\", \"bar\")", x);
   166             fail("new Formatter(\".\", \"bar\")", x);
   174         }
   167         }
   175 
   168 
   176         // Formatter(String fileName, String csn, Locale l)
   169         // Formatter(String fileName, String csn, Locale l)
   177         try {
   170         try (Formatter f = new Formatter("foo", "ISO-8859-1", Locale.GERMANY)) {
   178             Formatter f = new Formatter("foo", "ISO-8859-1", Locale.GERMANY);
       
   179             pass();
   171             pass();
   180             out(f, BufferedWriter.class);
   172             out(f, BufferedWriter.class);
   181             locale(f, Locale.GERMANY);
   173             locale(f, Locale.GERMANY);
   182         } catch (Exception x) {
   174         } catch (Exception x) {
   183             fail("new Formatter(\"foo\", \"ISO-8859-1\", Locale.GERMANY)", x);
   175             fail("new Formatter(\"foo\", \"ISO-8859-1\", Locale.GERMANY)", x);
   184         }
   176         }
   185 
   177 
   186         try {
   178         try (Formatter f = new Formatter("foo", "ISO-8859-1", null)) {
   187             Formatter f = new Formatter("foo", "ISO-8859-1", null);
       
   188             pass();
   179             pass();
   189             locale(f, null);
   180             locale(f, null);
   190             out(f, BufferedWriter.class);
   181             out(f, BufferedWriter.class);
   191         } catch (Exception x) {
   182         } catch (Exception x) {
   192             fail("new Formatter(\"foo\", \"ISO-8859-1\", null)", x);
   183             fail("new Formatter(\"foo\", \"ISO-8859-1\", null)", x);
   193         }
   184         }
   194 
   185 
   195         // Formatter(File)
   186         // Formatter(File)
   196         try {
   187         try (Formatter f = new Formatter(new File("foo"))) {
   197             Formatter f = new Formatter(new File("foo"));
       
   198             pass();
   188             pass();
   199             locale(f);
   189             locale(f);
   200             out(f, BufferedWriter.class);
   190             out(f, BufferedWriter.class);
   201         } catch (Exception x) {
   191         } catch (Exception x) {
   202             fail("new Formatter(new File(\"foo\")", x);
   192             fail("new Formatter(new File(\"foo\")", x);
   203         }
   193         }
   204 
   194 
   205         try {
   195         try {
   206             Formatter f = new Formatter((File)null);
   196             new Formatter((File)null);
   207             fail("new Formatter((File)null)");
   197             fail("new Formatter((File)null)");
   208         } catch (NullPointerException x) {
   198         } catch (NullPointerException x) {
   209             pass();
   199             pass();
   210         } catch (Exception x) {
   200         } catch (Exception x) {
   211             fail("new Formatter((File)null)", x);
   201             fail("new Formatter((File)null)", x);
   229             pass();
   219             pass();
   230         } catch (Exception x) {
   220         } catch (Exception x) {
   231             fail("new Formatter((PrintStream) null)", x);
   221             fail("new Formatter((PrintStream) null)", x);
   232         }
   222         }
   233 
   223 
   234         try {
   224         try (Formatter f = new Formatter(new PrintStream("foo"))) {
   235             Formatter f = new Formatter(new PrintStream("foo"));
       
   236             pass();
   225             pass();
   237             locale(f);
   226             locale(f);
   238             out(f, PrintStream.class);
   227             out(f, PrintStream.class);
   239         } catch (FileNotFoundException x) {
   228         } catch (FileNotFoundException x) {
   240             fail("new Formatter(new PrintStream(\"foo\")", x);
   229             fail("new Formatter(new PrintStream(\"foo\")", x);
   241         } catch (Exception x) {
   230         } catch (Exception x) {
   242             fail("new Formatter(new PrintStream(\"foo\")", x);
   231             fail("new Formatter(new PrintStream(\"foo\")", x);
   243         }
   232         }
   244 
   233 
   245         try {
   234         try (Formatter f = new Formatter(new PrintStream("foo"),
   246             Formatter f = new Formatter(new PrintStream("foo"),
   235                                          Locale.JAPANESE)) {
   247                                         Locale.JAPANESE);
       
   248             pass();
   236             pass();
   249             locale(f, Locale.JAPANESE);
   237             locale(f, Locale.JAPANESE);
   250             out(f, PrintStream.class);
   238             out(f, PrintStream.class);
   251         } catch (FileNotFoundException x) {
   239         } catch (FileNotFoundException x) {
   252             fail("new Formatter(new PrintStream(\"foo\")", x);
   240             fail("new Formatter(new PrintStream(\"foo\")", x);
   253         } catch (Exception x) {
   241         } catch (Exception x) {
   254             fail("new Formatter(new PrintStream(\"foo\")", x);
   242             fail("new Formatter(new PrintStream(\"foo\")", x);
   255         }
   243         }
   256 
   244 
   257         try {
   245         try (PrintStream ps = new PrintStream("foo")) {
   258             // The cast here is necessary to avoid an ambiguity error
   246             // The cast here is necessary to avoid an ambiguity error
   259             // between Formatter(Appendable a, Locale l)
   247             // between Formatter(Appendable a, Locale l)
   260             // and     Formatter(OutputStream os, String csn)
   248             // and Formatter(OutputStream os, String csn)
   261             Formatter f = new Formatter(new PrintStream("foo"),
   249             new Formatter(ps, (String)null);
   262                                         (String)null);
       
   263             fail("new Formatter(new PrintStream(\"foo\"), (String)null)");
   250             fail("new Formatter(new PrintStream(\"foo\"), (String)null)");
   264         } catch (FileNotFoundException x) {
   251         } catch (FileNotFoundException x) {
   265             fail("new Formatter(new PrintStream(\"foo\"), (String)null)", x);
   252             fail("new Formatter(new PrintStream(\"foo\"), (String)null)", x);
   266         } catch (NullPointerException x) {
   253         } catch (NullPointerException x) {
   267             pass();
   254             pass();
   269             fail("new Formatter(new PrintStream(\"foo\"), (String)null)", x);
   256             fail("new Formatter(new PrintStream(\"foo\"), (String)null)", x);
   270         } catch (Exception x) {
   257         } catch (Exception x) {
   271             fail("new Formatter(new PrintStream(\"foo\"), (String)null)", x);
   258             fail("new Formatter(new PrintStream(\"foo\"), (String)null)", x);
   272         }
   259         }
   273 
   260 
   274         try {
   261         // The cast here is necessary to avoid an ambiguity error
   275             // The cast here is necessary to avoid an ambiguity error
   262         // between Formatter(Appendable a, Locale l)
   276             // between Formatter(Appendable a, Locale l)
   263         // and  Formatter(OutputStream os, String csn)
   277             // and     Formatter(OutputStream os, String csn)
   264         try (Formatter f = new Formatter(new PrintStream("foo"),
   278             Formatter f = new Formatter(new PrintStream("foo"),
   265                                          (Locale)null)) {
   279                                         (Locale)null);
       
   280             pass();
   266             pass();
   281             locale(f, null);
   267             locale(f, null);
   282             out(f, PrintStream.class);
   268             out(f, PrintStream.class);
   283         } catch (FileNotFoundException x) {
   269         } catch (FileNotFoundException x) {
   284             fail("new Formatter(new PrintStream(\"foo\"), (Locale)null)", x);
   270             fail("new Formatter(new PrintStream(\"foo\"), (Locale)null)", x);
   285         } catch (Exception x) {
   271         } catch (Exception x) {
   286             fail("new Formatter(new PrintStream(\"foo\"), (Locale)null)", x);
   272             fail("new Formatter(new PrintStream(\"foo\"), (Locale)null)", x);
   287         }
   273         }
   288 
   274 
   289         try {
   275         try (Formatter f = new Formatter(new PrintStream("foo"),
   290             Formatter f = new Formatter(new PrintStream("foo"),
   276                                          Locale.KOREAN)) {
   291                                         Locale.KOREAN);
       
   292             pass();
   277             pass();
   293             locale(f, Locale.KOREAN);
   278             locale(f, Locale.KOREAN);
   294             out(f, PrintStream.class);
   279             out(f, PrintStream.class);
   295         } catch (FileNotFoundException x) {
   280         } catch (FileNotFoundException x) {
   296             fail("new Formatter(new PrintStream(\"foo\"), Locale.KOREAN)", x);
   281             fail("new Formatter(new PrintStream(\"foo\"), Locale.KOREAN)", x);
   297         } catch (Exception x) {
   282         } catch (Exception x) {
   298             fail("new Formatter(new PrintStream(\"foo\"), Locale.KOREAN)", x);
   283             fail("new Formatter(new PrintStream(\"foo\"), Locale.KOREAN)", x);
   299         }
   284         }
   300 
   285 
   301         try {
   286         try (Formatter f = new Formatter(new PrintStream("foo"),
   302             Formatter f = new Formatter(new PrintStream("foo"),
   287                                          "UTF-16BE", null)) {
   303                                         "UTF-16BE", null);
       
   304             pass();
   288             pass();
   305             locale(f, null);
   289             locale(f, null);
   306             out(f, BufferedWriter.class);
   290             out(f, BufferedWriter.class);
   307         } catch (FileNotFoundException x) {
   291         } catch (FileNotFoundException x) {
   308             fail("new Formatter(new PrintStream(\"foo\"), \"UTF-16BE\", null");
   292             fail("new Formatter(new PrintStream(\"foo\"), \"UTF-16BE\", null");
   310             fail("new Formatter(new PrintStream(\"foo\"), \"UTF-16BE\", null");
   294             fail("new Formatter(new PrintStream(\"foo\"), \"UTF-16BE\", null");
   311         } catch (Exception x) {
   295         } catch (Exception x) {
   312             fail("new Formatter(new PrintStream(\"foo\"), \"UTF-16BE\", null");
   296             fail("new Formatter(new PrintStream(\"foo\"), \"UTF-16BE\", null");
   313         }
   297         }
   314 
   298 
   315         try {
   299         try (Formatter f = new Formatter(new PrintStream("foo"),
   316             Formatter f = new Formatter(new PrintStream("foo"),
   300                                          "UTF-16BE", Locale.ITALIAN)) {
   317                                         "UTF-16BE", Locale.ITALIAN);
       
   318             pass();
   301             pass();
   319             locale(f, Locale.ITALIAN);
   302             locale(f, Locale.ITALIAN);
   320             out(f, BufferedWriter.class);
   303             out(f, BufferedWriter.class);
   321         } catch (FileNotFoundException x) {
   304         } catch (FileNotFoundException x) {
   322             fail("new Formatter(new PrintStream(\"foo\"), \"UTF-16BE\", Locale.ITALIAN");
   305             fail("new Formatter(new PrintStream(\"foo\"), \"UTF-16BE\", Locale.ITALIAN");
   359             pass();
   342             pass();
   360         } catch (Exception x) {
   343         } catch (Exception x) {
   361             fail("new Formatter((OutputStream) null)", x);
   344             fail("new Formatter((OutputStream) null)", x);
   362         }
   345         }
   363 
   346 
   364         try {
   347         try (Formatter f = new Formatter((OutputStream) new PrintStream("foo"))) {
   365             Formatter f = new Formatter((OutputStream) new PrintStream("foo"));
       
   366             pass();
   348             pass();
   367             locale(f);
   349             locale(f);
   368             out(f, BufferedWriter.class);
   350             out(f, BufferedWriter.class);
   369         } catch (Exception x) {
   351         } catch (Exception x) {
   370             fail("new Formatter((OutputStream) new PrintStream(\"foo\")", x);
   352             fail("new Formatter((OutputStream) new PrintStream(\"foo\")", x);
   378             pass();
   360             pass();
   379         } catch (Exception x) {
   361         } catch (Exception x) {
   380             fail("new Formatter((OutputStream) null, \"ISO-8859-1\")", x);
   362             fail("new Formatter((OutputStream) null, \"ISO-8859-1\")", x);
   381         }
   363         }
   382 
   364 
   383         try {
   365         try (PrintStream ps = new PrintStream("foo")) {
   384             new Formatter((OutputStream) new PrintStream("foo"), null);
   366             new Formatter((OutputStream) ps, null);
   385             fail("new Formatter((OutputStream) new PrintStream(\"foo\"), null");
   367             fail("new Formatter((OutputStream) new PrintStream(\"foo\"), null");
   386         } catch (NullPointerException x) {
   368         } catch (NullPointerException x) {
   387             pass();
   369             pass();
   388         } catch (Exception x) {
   370         } catch (Exception x) {
   389             fail("new Formatter((OutputStream) new PrintStream(\"foo\"), null",
   371             fail("new Formatter((OutputStream) new PrintStream(\"foo\"), null",
   390                  x);
   372                  x);
   391         }
   373         }
   392 
   374 
   393         try {
   375         try (PrintStream ps = new PrintStream("foo")) {
   394             new Formatter(new PrintStream("foo"), "bar");
   376             new Formatter(ps, "bar");
   395             fail("new Formatter(new PrintStream(\"foo\"), \"bar\")");
   377             fail("new Formatter(new PrintStream(\"foo\"), \"bar\")");
   396         } catch (UnsupportedEncodingException x) {
   378         } catch (UnsupportedEncodingException x) {
   397             pass();
   379             pass();
   398         } catch (Exception x) {
   380         } catch (Exception x) {
   399             fail("new Formatter(new PrintStream(\"foo\"), \"bar\")", x);
   381             fail("new Formatter(new PrintStream(\"foo\"), \"bar\")", x);
   400         }
   382         }
   401 
   383 
   402         try {
   384         try (Formatter f = new Formatter(new PrintStream("foo"), "UTF-8")) {
   403             Formatter f = new Formatter(new PrintStream("foo"), "UTF-8");
       
   404             pass();
   385             pass();
   405             locale(f);
   386             locale(f);
   406             out(f, BufferedWriter.class);
   387             out(f, BufferedWriter.class);
   407         } catch (Exception x) {
   388         } catch (Exception x) {
   408             fail("new Formatter(new PrintStream(\"foo\"), \"UTF-8\")", x);
   389             fail("new Formatter(new PrintStream(\"foo\"), \"UTF-8\")", x);
   417         } catch (Exception x) {
   398         } catch (Exception x) {
   418             fail("new Formatter((OutputStream) null, \"ISO-8859-1\", Locale.UK)",
   399             fail("new Formatter((OutputStream) null, \"ISO-8859-1\", Locale.UK)",
   419                  x);
   400                  x);
   420         }
   401         }
   421 
   402 
   422         try {
   403         try (PrintStream ps = new PrintStream("foo")) {
   423             new Formatter(new PrintStream("foo"), null, Locale.UK);
   404             new Formatter(ps, null, Locale.UK);
   424             fail("new Formatter(new PrintStream(\"foo\"), null, Locale.UK)");
   405             fail("new Formatter(new PrintStream(\"foo\"), null, Locale.UK)");
   425         } catch (NullPointerException x) {
   406         } catch (NullPointerException x) {
   426             pass();
   407             pass();
   427         } catch (Exception x) {
   408         } catch (Exception x) {
   428             fail("new Formatter(new PrintStream(\"foo\"), null, Locale.UK)",
   409             fail("new Formatter(new PrintStream(\"foo\"), null, Locale.UK)",
   429                  x);
   410                  x);
   430         }
   411         }
   431 
   412 
   432         try {
   413         try (PrintStream ps = new PrintStream("foo")) {
   433             new Formatter(new PrintStream("foo"), "bar", Locale.UK);
   414             new Formatter(ps, "bar", Locale.UK);
   434             fail("new Formatter(new PrintStream(\"foo\"), \"bar\", Locale.UK)");
   415             fail("new Formatter(new PrintStream(\"foo\"), \"bar\", Locale.UK)");
   435         } catch (UnsupportedEncodingException x) {
   416         } catch (UnsupportedEncodingException x) {
   436             pass();
   417             pass();
   437         } catch (Exception x) {
   418         } catch (Exception x) {
   438             fail("new Formatter(new PrintStream(\"foo\"), \"bar\", Locale.UK)",
   419             fail("new Formatter(new PrintStream(\"foo\"), \"bar\", Locale.UK)",
   439                  x);
   420                  x);
   440         }
   421         }
   441 
   422 
   442         try {
   423         try (Formatter f = new Formatter(new PrintStream("foo"), "UTF-8", Locale.UK)) {
   443             Formatter f
       
   444                 = new Formatter(new PrintStream("foo"), "UTF-8", Locale.UK);
       
   445             pass();
   424             pass();
   446             out(f, BufferedWriter.class);
   425             out(f, BufferedWriter.class);
   447             locale(f, Locale.UK);
   426             locale(f, Locale.UK);
   448         } catch (Exception x) {
   427         } catch (Exception x) {
   449             fail("new Formatter(new PrintStream(\"foo\"), \"UTF-8\"), Locale.UK",
   428             fail("new Formatter(new PrintStream(\"foo\"), \"UTF-8\"), Locale.UK",
   450                  x);
   429                  x);
   451         }
   430         }
   452 
   431 
   453         // PrintStream(String fileName)
   432         // PrintStream(String fileName)
   454         try {
   433         try (PrintStream ps = new PrintStream("foo")) {
   455             new PrintStream("foo");
       
   456             pass();
   434             pass();
   457         } catch (Exception x) {
   435         } catch (Exception x) {
   458             fail("new PrintStream(\"foo\")", x);
   436             fail("new PrintStream(\"foo\")", x);
   459         }
   437         }
   460 
   438 
   467         } catch (Exception x) {
   445         } catch (Exception x) {
   468             fail("new PrintStream(\"foo\", null)", x);
   446             fail("new PrintStream(\"foo\", null)", x);
   469         }
   447         }
   470 
   448 
   471         // PrintStream(File file)
   449         // PrintStream(File file)
   472         try {
   450         try (PrintStream ps = new PrintStream(new File("foo"))) {
   473             new PrintStream(new File("foo"));
       
   474             pass();
   451             pass();
   475         } catch (Exception x) {
   452         } catch (Exception x) {
   476             fail("new PrintStream(new File(\"foo\"))", x);
   453             fail("new PrintStream(new File(\"foo\"))", x);
   477         }
   454         }
   478 
   455 
   485         } catch (Exception x) {
   462         } catch (Exception x) {
   486             fail("new PrintStream(new File(\"foo\"), null)", x);
   463             fail("new PrintStream(new File(\"foo\"), null)", x);
   487         }
   464         }
   488 
   465 
   489         // PrintWriter(String fileName)
   466         // PrintWriter(String fileName)
   490         try {
   467         try (PrintWriter pw = new PrintWriter("foo")) {
   491             new PrintWriter("foo");
       
   492             pass();
   468             pass();
   493         } catch (Exception x) {
   469         } catch (Exception x) {
   494             fail("new PrintWriter(\"foo\")", x);
   470             fail("new PrintWriter(\"foo\")", x);
   495         }
   471         }
   496 
   472 
   503         } catch (Exception x) {
   479         } catch (Exception x) {
   504             fail("new PrintWriter(\"foo\"), null", x);
   480             fail("new PrintWriter(\"foo\"), null", x);
   505         }
   481         }
   506 
   482 
   507         // PrintWriter(File file)
   483         // PrintWriter(File file)
   508         try {
   484         try (PrintWriter pw = new PrintWriter(new File("foo"))) {
   509             new PrintWriter(new File("foo"));
       
   510             pass();
   485             pass();
   511         } catch (Exception x) {
   486         } catch (Exception x) {
   512             fail("new PrintWriter(new File(\"foo\"))", x);
   487             fail("new PrintWriter(new File(\"foo\"))", x);
   513         }
   488         }
   514 
   489