Path: blob/master/test/jdk/java/io/Writer/Append.java
41149 views
/*1* Copyright (c) 2004, 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 503062326* @summary Basic test of all append() methods in Writer and inherited classes.27*/2829import java.io.*;30import java.lang.reflect.*;3132public class Append {33// append methods throw IOException34private static Class [] io = {35Writer.class, BufferedWriter.class, FilterWriter.class,36OutputStreamWriter.class, FileWriter.class37};3839// append methods don't throw IOException40private static Class [] nio = {41CharArrayWriter.class, StringWriter.class, PrintWriter.class,42PrintStream.class43};4445public static void main(String [] args) {46for (int i = 0; i < io.length; i++)47test(io[i], true);48for (int i = 0; i < nio.length; i++)49test(nio[i], false);50}5152private static void test(Class c, boolean io) {53try {54Class [] cparams = { char.class };55test(c.getMethod("append", cparams), io);56Class [] csparams = { CharSequence.class };57test(c.getMethod("append", csparams), io);58} catch (NoSuchMethodException x) {59throw new RuntimeException("No append method found");60}61}6263private static void test(Method m, boolean io) {64Class [] ca = m.getExceptionTypes();65boolean found = false;66for (int i = 0; i < ca.length; i++) {67if (ca[i].equals(IOException.class)) {68found = true;69break;70}71}7273if (found && !io)74throw new RuntimeException("Unexpected IOException");75if (!found && io)76throw new RuntimeException("Missing IOException");77}78}798081