blob: 78f0c83f474b6187d07cffa3462b36433dea56a0 [file] [log] [blame]
J. Duke319a3b92007-12-01 00:00:00 +00001/*
2 * Copyright 2004 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
20 * CA 95054 USA or visit www.sun.com if you need additional information or
21 * have any questions.
22 */
23
24/**
25 * @test
26 * @bug 5030623
27 * @summary Basic test of all append() methods in Writer and inherited classes.
28 */
29
30import java.io.*;
31import java.lang.reflect.*;
32
33public class Append {
34 // append methods throw IOException
35 private static Class [] io = {
36 Writer.class, BufferedWriter.class, FilterWriter.class,
37 OutputStreamWriter.class, FileWriter.class
38 };
39
40 // append methods don't throw IOException
41 private static Class [] nio = {
42 CharArrayWriter.class, StringWriter.class, PrintWriter.class,
43 PrintStream.class
44 };
45
46 public static void main(String [] args) {
47 for (int i = 0; i < io.length; i++)
48 test(io[i], true);
49 for (int i = 0; i < nio.length; i++)
50 test(nio[i], false);
51 }
52
53 private static void test(Class c, boolean io) {
54 try {
55 Class [] cparams = { char.class };
56 test(c.getMethod("append", cparams), io);
57 Class [] csparams = { CharSequence.class };
58 test(c.getMethod("append", csparams), io);
59 } catch (NoSuchMethodException x) {
60 throw new RuntimeException("No append method found");
61 }
62 }
63
64 private static void test(Method m, boolean io) {
65 Class [] ca = m.getExceptionTypes();
66 boolean found = false;
67 for (int i = 0; i < ca.length; i++) {
68 if (ca[i].equals(IOException.class)) {
69 found = true;
70 break;
71 }
72 }
73
74 if (found && !io)
75 throw new RuntimeException("Unexpected IOException");
76 if (!found && io)
77 throw new RuntimeException("Missing IOException");
78 }
79}