Index: /src/test/java/org/apache/harmony/tests/java/io/PrintStreamTest.java =================================================================== --- /src/test/java/org/apache/harmony/tests/java/io/PrintStreamTest.java (revision 0) +++ /src/test/java/org/apache/harmony/tests/java/io/PrintStreamTest.java (revision 0) @@ -0,0 +1,86 @@ +/* Copyright 2006 The Apache Software Foundation or its licensors, as applicable + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +package org.apache.harmony.tests.java.io; + +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.PrintStream; + +import junit.framework.TestCase; + +public class PrintStreamTest extends TestCase { + + public void test_construct_null_file() throws FileNotFoundException { + File file = null; + + PrintStream ps = null; + try { + ps = new PrintStream(file); + fail("Should throw NullPointerException"); + } catch (NullPointerException e) { + // expected + } + } + + public void test_construct_null_charset() throws IOException { + File file = File.createTempFile("ttt", null); + try + {PrintStream ps = new PrintStream(file,null); + fail("Should throw NullPointerException");} + catch(NullPointerException e) + { + //expected + } + finally + {file.delete();} + + } + + public void test_append_string() throws IOException { + String testString = "My Test String"; + ByteArrayOutputStream bout = new ByteArrayOutputStream(); + PrintStream ps = new PrintStream(bout); + ps.append(testString); + ps.flush(); + assertEquals(testString, bout.toString()); + ps.close(); + } + + public void test_append_nochar() throws IOException { + ByteArrayOutputStream bout = new ByteArrayOutputStream(); + PrintStream ps = new PrintStream(bout); + ps.append(""); + ps.flush(); + byte[] buffer = bout.toByteArray(); + assertNotNull(buffer); + assertEquals(0, buffer.length); + ps.close(); + } + + public void test_append_null() throws IOException { + String testString = "My Test String"; + ByteArrayOutputStream bout = new ByteArrayOutputStream(); + PrintStream ps = new PrintStream(bout); + ps.print(testString.toCharArray()); + ps.append(null); + ps.flush(); + testString = testString.concat("null"); + assertEquals(testString, bout.toString()); + } +} Index: /src/test/java/org/apache/harmony/tests/java/io/CharArrayWriterTest.java =================================================================== --- /src/test/java/org/apache/harmony/tests/java/io/CharArrayWriterTest.java (revision 0) +++ /src/test/java/org/apache/harmony/tests/java/io/CharArrayWriterTest.java (revision 0) @@ -0,0 +1,48 @@ +/* Copyright 2006 The Apache Software Foundation or its licensors, as applicable + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.harmony.tests.java.io; + +import junit.framework.TestCase; +import java.io.CharArrayWriter; +import java.io.IOException; + +public class CharArrayWriterTest extends TestCase { + + public static void test_append_string() throws IOException { + String testString = "My Test String"; + CharArrayWriter charArrayWriter = new CharArrayWriter(); + charArrayWriter.append(testString, 1, 3); + assertEquals(testString.substring(1, 3), charArrayWriter.toString()); + } + + public static void test_append_nochar() throws IOException { + CharArrayWriter charArrayWriter = new CharArrayWriter(10); + charArrayWriter.append(""); + char[] buffer = charArrayWriter.toCharArray(); + assertNotNull(buffer); + assertEquals("", charArrayWriter.toString()); + } + + public static void test_append_null() throws IOException { + String testString = "My Test String"; + CharArrayWriter charArrayWriter = new CharArrayWriter(); + charArrayWriter.write(testString.toCharArray()); + charArrayWriter.append(null); + testString = testString.concat("null"); + assertEquals(testString, charArrayWriter.toString()); + } + +}