--- old/test/java/io/PrintWriter/FailingConstructors.java 2016-11-24 12:48:41.814083236 +0000 +++ new/test/java/io/PrintWriter/FailingConstructors.java 2016-11-24 12:48:41.702085884 +0000 @@ -28,13 +28,16 @@ * exception thrown */ +import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileInputStream; -import java.io.FileOutputStream; import java.io.FileNotFoundException; +import java.io.FileOutputStream; import java.io.IOException; +import java.io.OutputStream; import java.io.PrintWriter; import java.io.UnsupportedEncodingException; +import java.nio.charset.Charset; public class FailingConstructors { static final String fileName = "FailingConstructorsTest"; @@ -42,6 +45,8 @@ static final String FILE_CONTENTS = "This is a small file!"; private static void realMain(String[] args) throws Throwable { + testOutputStream(); + test(false, new File(fileName)); /* create the file and write its contents */ @@ -55,6 +60,42 @@ file.delete(); } + private static void testWithAutoFlush() throws Throwable { + ByteArrayOutputStream out = new ByteArrayOutputStream(); + + PrintWriter writer = new PrintWriter(out); + + PrintWriter writer_noAutoFlush = writer.withAutoFlush(false); + if (writer == writer_noAutoFlush) { + pass(); + } else { + fail();; + } + + PrintWriter writer_withAutoFlush = writer.withAutoFlush(true); + if (writer == writer_withAutoFlush) { + pass(); + } else { + fail();; + } + + PrintWriter writer_withAutoFlush2 = writer_withAutoFlush.withAutoFlush(true); + if (writer_withAutoFlush == writer_withAutoFlush2) { + pass(); + } else { + fail();; + } + } + + private static void testOutputStream() throws Throwable { + try { + new PrintWriter((OutputStream)null, (Charset)null); + fail(); + } catch(NullPointerException e) { + pass(); + } + } + private static void test(boolean exists, File file) throws Throwable { /* PrintWriter(File file, String csn) */ try { @@ -67,7 +108,16 @@ check(exists, file); try { - new PrintWriter(file, null); + new PrintWriter(file, (String)null); + fail(); + } catch(FileNotFoundException|NullPointerException e) { + pass(); + } + + check(exists, file); + + try { + new PrintWriter(file, (Charset) null); fail(); } catch(FileNotFoundException|NullPointerException e) { pass();