harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ton...@apache.org
Subject svn commit: r617085 [8/14] - in /harmony/enhanced/classlib/branches/java6: depends/build/ depends/build/platform/ depends/libs/ depends/oss/ make/ make/linux.x86_64.libstdc++6/ make/windows.x86/ make/windows.x86_64/ modules/archive/META-INF/ modules/ar...
Date Thu, 31 Jan 2008 10:04:22 GMT
Modified: harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/ObjectStreamConstantsTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/ObjectStreamConstantsTest.java?rev=617085&r1=617084&r2=617085&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/ObjectStreamConstantsTest.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/ObjectStreamConstantsTest.java Thu Jan 31 02:04:05 2008
@@ -17,28 +17,29 @@
 package org.apache.harmony.luni.tests.java.io;
 
 import java.io.ObjectStreamConstants;
+
 import junit.framework.TestCase;
 
 public class ObjectStreamConstantsTest extends TestCase {
 
-	/**
-	 * @tests java.io.ObjectStreamConstants#TC_ENUM
-	 */
-	public void test_TC_ENUM() {
-		assertEquals(126, ObjectStreamConstants.TC_ENUM);
-	}
+    /**
+     * @tests java.io.ObjectStreamConstants#TC_ENUM
+     */
+    public void test_TC_ENUM() {
+        assertEquals(126, ObjectStreamConstants.TC_ENUM);
+    }
 
-	/**
-	 * @tests java.io.ObjectStreamConstants#SC_ENUM
-	 */
-	public void test_SC_ENUM() {
-		assertEquals(16, ObjectStreamConstants.SC_ENUM);
-	}
+    /**
+     * @tests java.io.ObjectStreamConstants#SC_ENUM
+     */
+    public void test_SC_ENUM() {
+        assertEquals(16, ObjectStreamConstants.SC_ENUM);
+    }
 
-	/**
-	 * @tests java.io.ObjectStreamConstants#TC_MAX
-	 */
-	public void test_TC_MAX() {
-		assertEquals(126, ObjectStreamConstants.TC_MAX);
-	}
+    /**
+     * @tests java.io.ObjectStreamConstants#TC_MAX
+     */
+    public void test_TC_MAX() {
+        assertEquals(126, ObjectStreamConstants.TC_MAX);
+    }
 }

Modified: harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/ObjectStreamFieldTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/ObjectStreamFieldTest.java?rev=617085&r1=617084&r2=617085&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/ObjectStreamFieldTest.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/ObjectStreamFieldTest.java Thu Jan 31 02:04:05 2008
@@ -32,133 +32,125 @@
 
 public class ObjectStreamFieldTest extends junit.framework.TestCase {
 
-	static class DummyClass implements Serializable {
-		private static final long serialVersionUID = 999999999999998L;
+    static class DummyClass implements Serializable {
+        private static final long serialVersionUID = 999999999999998L;
 
-		long bam = 999L;
+        long bam = 999L;
 
-		int ham = 9999;
+        int ham = 9999;
 
-		int sam = 8888;
+        int sam = 8888;
+
+        Object hola = new Object();
+
+        public static long getUID() {
+            return serialVersionUID;
+        }
+    }
+
+    ObjectStreamClass osc;
+
+    ObjectStreamField hamField;
+
+    ObjectStreamField samField;
+
+    ObjectStreamField bamField;
+
+    ObjectStreamField holaField;
+
+    /**
+     * @tests java.io.ObjectStreamField#ObjectStreamField(java.lang.String,
+     *        java.lang.Class)
+     */
+    public void test_ConstructorLjava_lang_StringLjava_lang_Class() {
+        assertTrue("Used to test", true);
+    }
+
+    public void test_equalsLjava_lang_Object() {
+        // Regression test for HARMONY-4273
+        assertTrue(samField.equals(samField));
+        assertFalse(samField.equals(hamField));
+        assertFalse(samField.equals("fish"));
+        assertFalse(samField.equals(null));
+    }
+
+    /**
+     * @tests java.io.ObjectStreamField#compareTo(java.lang.Object)
+     */
+    public void test_compareToLjava_lang_Object() {
+        assertTrue("Object compared to int did not return > 0", holaField
+                .compareTo(hamField) > 0);
+        assertEquals("Int compared to itself did not return 0", 0, hamField
+                .compareTo(hamField));
+        assertTrue("(Int)ham compared to (Int)sam did not return < 0", hamField
+                .compareTo(samField) < 0);
+    }
+
+    /**
+     * @tests java.io.ObjectStreamField#getName()
+     */
+    public void test_getName() {
+        assertEquals("Field did not return correct name", "hola", holaField
+                .getName());
+    }
+
+    /**
+     * @tests java.io.ObjectStreamField#getOffset()
+     */
+    public void test_getOffset() {
+        ObjectStreamField[] osfArray;
+        osfArray = osc.getFields();
+        assertTrue("getOffset did not return reasonable values", osfArray[0]
+                .getOffset() != osfArray[1].getOffset());
+        assertEquals("getOffset for osfArray[0].getOffset() did not return 0",
+                0, osfArray[0].getOffset());
+        assertEquals("osfArray[1].getOffset() did not return	8", 8, osfArray[1]
+                .getOffset());
+        assertEquals("osfArray[2].getOffset() did not return 12", 12,
+                osfArray[2].getOffset());
+    }
+
+    /**
+     * @tests java.io.ObjectStreamField#getType()
+     */
+    public void test_getType() {
+        assertTrue("getType on an Object field did not answer Object",
+                holaField.getType().equals(Object.class));
+    }
+
+    /**
+     * @tests java.io.ObjectStreamField#getTypeCode()
+     */
+    public void test_getTypeCode() {
+        assertEquals("getTypeCode on an Object field did not answer 'L'", 'L',
+                holaField.getTypeCode());
+        assertEquals("getTypeCode on a long field did not answer 'J'", 'J',
+                bamField.getTypeCode());
+    }
+
+    /**
+     * @tests java.io.ObjectStreamField#getTypeString()
+     */
+    public void test_getTypeString() {
+        assertTrue("getTypeString returned: " + holaField.getTypeString(),
+                holaField.getTypeString().indexOf("Object") >= 0);
+        assertNull("Primitive types' strings should be null", hamField
+                .getTypeString());
 
-		Object hola = new Object();
-
-		public static long getUID() {
-			return serialVersionUID;
-		}
-	}
-
-	ObjectStreamClass osc;
-
-	ObjectStreamField hamField;
-
-	ObjectStreamField samField;
-
-	ObjectStreamField bamField;
-
-	ObjectStreamField holaField;
-
-	/**
-	 * @tests java.io.ObjectStreamField#ObjectStreamField(java.lang.String,
-	 *        java.lang.Class)
-	 */
-	public void test_ConstructorLjava_lang_StringLjava_lang_Class() {
-		// Test for method java.io.ObjectStreamField(java.lang.String,
-		// java.lang.Class)
-		assertTrue("Used to test", true);
-	}
-
-	public void test_equalsLjava_lang_Object() {
-	    // Regression test for HARMONY-4273
-	    assertTrue(samField.equals(samField));
-	    assertFalse(samField.equals(hamField));
-	    assertFalse(samField.equals("fish"));
-	    assertFalse(samField.equals(null));
-    }
-
-	/**
-	 * @tests java.io.ObjectStreamField#compareTo(java.lang.Object)
-	 */
-	public void test_compareToLjava_lang_Object() {
-		// Test for method int
-		// java.io.ObjectStreamField.compareTo(java.lang.Object)
-		assertTrue("Object compared to int did not return > 0", holaField
-				.compareTo(hamField) > 0);
-		assertEquals("Int compared to itself did not return 0", 0, hamField
-				.compareTo(hamField));
-		assertTrue("(Int)ham compared to (Int)sam did not return < 0", hamField
-				.compareTo(samField) < 0);
-	}
-
-	/**
-	 * @tests java.io.ObjectStreamField#getName()
-	 */
-	public void test_getName() {
-		// Test for method java.lang.String java.io.ObjectStreamField.getName()
-		assertEquals("Field did not return correct name", "hola", holaField.getName()
-				);
-	}
-
-	/**
-	 * @tests java.io.ObjectStreamField#getOffset()
-	 */
-	public void test_getOffset() {
-		// Test for method int java.io.ObjectStreamField.getOffset()
-		ObjectStreamField[] osfArray;
-		osfArray = osc.getFields();
-		assertTrue("getOffset did not return reasonable values", osfArray[0]
-				.getOffset() != osfArray[1].getOffset());
-		assertEquals("getOffset for osfArray[0].getOffset() did not return 0",
-				0, osfArray[0].getOffset());
-		assertEquals("osfArray[1].getOffset() did not return	8", 8, osfArray[1]
-				.getOffset());
-		assertEquals("osfArray[2].getOffset() did not return 12", 12, osfArray[2]
-				.getOffset());
-	}
-
-	/**
-	 * @tests java.io.ObjectStreamField#getType()
-	 */
-	public void test_getType() {
-		// Test for method java.lang.Class java.io.ObjectStreamField.getType()
-		assertTrue("getType on an Object field did not answer Object",
-				holaField.getType().equals(Object.class));
-	}
-
-	/**
-	 * @tests java.io.ObjectStreamField#getTypeCode()
-	 */
-	public void test_getTypeCode() {
-		// Test for method char java.io.ObjectStreamField.getTypeCode()
-		assertEquals("getTypeCode on an Object field did not answer 'L'",
-				'L', holaField.getTypeCode());
-		assertEquals("getTypeCode on a long field did not answer 'J'", 'J', bamField
-				.getTypeCode());
-	}
-
-	/**
-	 * @tests java.io.ObjectStreamField#getTypeString()
-	 */
-	public void test_getTypeString() {
-		assertTrue("getTypeString returned: " + holaField.getTypeString(),
-				holaField.getTypeString().indexOf("Object") >= 0);
-		assertNull("Primitive types' strings should be null", hamField.getTypeString());
-        
         ObjectStreamField osf = new ObjectStreamField("s", String.class, true);
         assertTrue(osf.getTypeString() == "Ljava/lang/String;");
-	}
+    }
 
-	/**
-	 * @tests java.io.ObjectStreamField#toString()
-	 */
-	public void test_toString() {
-		// Test for method java.lang.String java.io.ObjectStreamField.toString()
-		assertTrue("toString on a long returned: " + bamField.toString(),
-				bamField.toString().indexOf("bam") >= 0);
-	}
-    
     /**
-     * @tests java.io.ObjectStreamField#getType() 
+     * @tests java.io.ObjectStreamField#toString()
+     */
+    public void test_toString() {
+        assertTrue("toString on a long returned: " + bamField.toString(),
+                bamField.toString().indexOf("bam") >= 0);
+    }
+
+    /**
+     * @tests java.io.ObjectStreamField#getType()
      */
     public void test_getType_Deserialized() throws IOException,
             ClassNotFoundException {
@@ -177,11 +169,12 @@
         ObjectStreamField field = oc.getField("i");
         assertEquals(Object.class, field.getType());
     }
-    
+
     /**
      * @tests java.io.ObjectStreamField#getType()
      */
-    public void test_getType_MockObjectInputStream() throws IOException, ClassNotFoundException {
+    public void test_getType_MockObjectInputStream() throws IOException,
+            ClassNotFoundException {
         ByteArrayOutputStream baos = new ByteArrayOutputStream(1024);
         ObjectOutputStream oos = new ObjectOutputStream(baos);
         oos.writeObject(new SerializableObject());
@@ -197,10 +190,10 @@
         ObjectStreamField field = oc.getField("i");
         assertEquals(Object.class, field.getType());
     }
-    
+
     public void test_isUnshared() throws Exception {
         SerializableObject2 obj = new SerializableObject2();
-        
+
         ByteArrayOutputStream baos = new ByteArrayOutputStream(1024);
         ObjectOutputStream oos = new ObjectOutputStream(baos);
         oos.writeObject(obj);
@@ -210,43 +203,36 @@
         ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
         ObjectInputStream ois = new ObjectInputStream(bais);
         SerializableObject2 newObj = (SerializableObject2) ois.readObject();
-        
+
         ObjectInputStream.GetField getField = newObj.getGetField();
         ObjectStreamClass objectStreamClass = getField.getObjectStreamClass();
-        
+
         assertTrue(objectStreamClass.getField("i").isUnshared());
         assertFalse(objectStreamClass.getField("d").isUnshared());
         assertTrue(objectStreamClass.getField("s").isUnshared());
-        
+
         assertEquals(1000, getField.get("i", null));
         assertEquals(SerializableObject2.today, getField.get("d", null));
         assertEquals("Richard", getField.get("s", null));
-        
+
         assertTrue(objectStreamClass.getField("s").getTypeString() == "Ljava/lang/String;");
-        
+
         assertEquals(0, objectStreamClass.getField("d").getOffset());
         assertEquals(1, objectStreamClass.getField("i").getOffset());
         assertEquals(2, objectStreamClass.getField("s").getOffset());
     }
 
-	/**
-	 * Sets up the fixture, for example, open a network connection. This method
-	 * is called before a test is executed.
-	 */
-	protected void setUp() {
-		osc = ObjectStreamClass.lookup(DummyClass.class);
-		bamField = osc.getField("bam");
-		samField = osc.getField("sam");
-		hamField = osc.getField("ham");
-		holaField = osc.getField("hola");
-	}
-
-	/**
-	 * Tears down the fixture, for example, close a network connection. This
-	 * method is called after a test is executed.
-	 */
-	protected void tearDown() {
-	}
+    /**
+     * Sets up the fixture, for example, open a network connection. This method
+     * is called before a test is executed.
+     */
+    protected void setUp() {
+        osc = ObjectStreamClass.lookup(DummyClass.class);
+        bamField = osc.getField("bam");
+        samField = osc.getField("sam");
+        hamField = osc.getField("ham");
+        holaField = osc.getField("hola");
+    }
 }
 
 class SerializableObject implements Serializable {
@@ -257,9 +243,9 @@
     public Date d;
 
     public Integer i;
-    
+
     public Exception e;
-    
+
     public SerializableObject() {
         d = new Date();
         i = new Integer(1);
@@ -299,7 +285,7 @@
     public ObjectStreamClass readClassDescriptor() throws IOException,
             ClassNotFoundException {
         ObjectStreamClass osc = super.readClassDescriptor();
-        //To get the ObjectStreamClass of SerializableObject
+        // To get the ObjectStreamClass of SerializableObject
         if (osc.getSerialVersionUID() == -2953957835918368056L) {
             temp = osc;
         }
@@ -314,21 +300,20 @@
 class SerializableObject2 implements Serializable {
 
     private static final long serialVersionUID = 1L;
-    
+
     private static final ObjectStreamField[] serialPersistentFields = {
-        new ObjectStreamField("i", Integer.class, true),
-        new ObjectStreamField("d", Date.class, false),
-        new ObjectStreamField("s", String.class, true),
-    };
-    
+            new ObjectStreamField("i", Integer.class, true),
+            new ObjectStreamField("d", Date.class, false),
+            new ObjectStreamField("s", String.class, true), };
+
     private ObjectInputStream.GetField getField;
-    
+
     public static Date today = new Date(1172632429156l);
-    
+
     public ObjectInputStream.GetField getGetField() {
         return getField;
     }
-    
+
     private void writeObject(ObjectOutputStream o) throws IOException {
         ObjectOutputStream.PutField putField = o.putFields();
         putField.put("i", new Integer(1000));

Modified: harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/OpenRandomFileTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/OpenRandomFileTest.java?rev=617085&r1=617084&r2=617085&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/OpenRandomFileTest.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/OpenRandomFileTest.java Thu Jan 31 02:04:05 2008
@@ -23,47 +23,36 @@
 
 import junit.framework.TestCase;
 
-/**
- * TODO Type description
- */
 public class OpenRandomFileTest extends TestCase {
 
-	public static void main(String[] args) {
-		new OpenRandomFileTest().testOpenEmptyFile();
-	}
-
-	public OpenRandomFileTest() {
-		super();
-	}
-
-	public void testOpenNonEmptyFile() {
-		try {
-			File file = File.createTempFile("test", "tmp");
-			assertTrue(file.exists());
-			file.deleteOnExit();
-			FileOutputStream fos = new FileOutputStream(file);
-			fos.write(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 });
-			fos.close();
-
-			String fileName = file.getCanonicalPath();
-			RandomAccessFile raf = new RandomAccessFile(fileName, "rw");
-			raf.close();
-		} catch (IOException ex) {
-			fail(ex.getLocalizedMessage());
-		}
-	}
-
-	public void testOpenEmptyFile() {
-		try {
-			File file = File.createTempFile("test", "tmp");
-			assertTrue(file.exists());
-			file.deleteOnExit();
-
-			String fileName = file.getCanonicalPath();
-			RandomAccessFile raf = new RandomAccessFile(fileName, "rw");
-			raf.close();
-		} catch (IOException ex) {
-			fail(ex.getLocalizedMessage());
-		}
-	}
+    public static void main(String[] args) throws IOException {
+        new OpenRandomFileTest().testOpenEmptyFile();
+    }
+
+    public OpenRandomFileTest() {
+        super();
+    }
+
+    public void testOpenNonEmptyFile() throws IOException {
+        File file = File.createTempFile("test", "tmp");
+        assertTrue(file.exists());
+        file.deleteOnExit();
+        FileOutputStream fos = new FileOutputStream(file);
+        fos.write(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 });
+        fos.close();
+
+        String fileName = file.getCanonicalPath();
+        RandomAccessFile raf = new RandomAccessFile(fileName, "rw");
+        raf.close();
+    }
+
+    public void testOpenEmptyFile() throws IOException {
+        File file = File.createTempFile("test", "tmp");
+        assertTrue(file.exists());
+        file.deleteOnExit();
+
+        String fileName = file.getCanonicalPath();
+        RandomAccessFile raf = new RandomAccessFile(fileName, "rw");
+        raf.close();
+    }
 }

Modified: harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/OutputStreamWriterTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/OutputStreamWriterTest.java?rev=617085&r1=617084&r2=617085&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/OutputStreamWriterTest.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/OutputStreamWriterTest.java Thu Jan 31 02:04:05 2008
@@ -32,639 +32,622 @@
 
 import junit.framework.TestCase;
 
-/**
- * 
- */
 public class OutputStreamWriterTest extends TestCase {
 
-	private static final int UPPER = 0xd800;
+    private static final int UPPER = 0xd800;
 
-	private static final int BUFFER_SIZE = 10000;
+    private static final int BUFFER_SIZE = 10000;
 
-	private ByteArrayOutputStream out;
+    private ByteArrayOutputStream out;
 
-	private OutputStreamWriter writer;
+    private OutputStreamWriter writer;
 
-	static private final String source = "This is a test message with Unicode character. \u4e2d\u56fd is China's name in Chinese";
-
-	static private final String[] MINIMAL_CHARSETS = new String[] { "US-ASCII",
-			"ISO-8859-1", "UTF-16BE", "UTF-16LE", "UTF-16", "UTF-8" };
-
-	OutputStreamWriter osw;
-
-	InputStreamReader isr;
-
-	private ByteArrayOutputStream fos;
-
-	String testString = "Test_All_Tests\nTest_java_io_BufferedInputStream\nTest_java_io_BufferedOutputStream\nTest_java_io_ByteArrayInputStream\nTest_java_io_ByteArrayOutputStream\nTest_java_io_DataInputStream\n";
-
-	/*
-	 * @see TestCase#setUp()
-	 */
-	protected void setUp() throws Exception {
-		super.setUp();
-		out = new ByteArrayOutputStream();
-		writer = new OutputStreamWriter(out, "utf-8");
-
-		fos = new ByteArrayOutputStream();
-		osw = new OutputStreamWriter(fos);
-	}
-
-	/*
-	 * @see TestCase#tearDown()
-	 */
-	protected void tearDown() throws Exception {
-		try {
-			writer.close();
-
-			if (isr != null)
-				isr.close();
-			osw.close();
-		} catch (Exception e) {
-		}
-
-		super.tearDown();
-	}
-
-	public void testClose() throws Exception {
-		writer.flush();
-		writer.close();
-		try {
-			writer.flush();
-			fail();
-		} catch (IOException e) {
-		}
-	}
-
-	public void testFlush() throws Exception {
-		writer.write(source);
-		writer.flush();
-		String result = out.toString("utf-8");
-		assertEquals(source, result);
-	}
-
-	/*
-	 * Class under test for void write(char[], int, int)
-	 */
-	public void testWritecharArrayintint() throws IOException {
-		char[] chars = source.toCharArray();
-		
-		//throws IndexOutOfBoundsException if offset is negative
-		try {
-			writer.write((char[]) null, -1, -1);
-			fail("should throw IndexOutOfBoundsException");
-		} catch (IndexOutOfBoundsException e) {
-			//expected
-		}
-		
-		//throws NullPointerException though count is negative 
-		try {
-			writer.write((char[]) null, 1, -1);
-			fail("should throw NullPointerException");
-		} catch (NullPointerException e) {
-			//expected
-		}
-	
-		try {
-			writer.write((char[]) null, 1, 1);
-			fail();
-		} catch (NullPointerException e) {
-		}
-		try {
-			writer.write(new char[0], 0, 1);
-			fail();
-		} catch (IndexOutOfBoundsException e) {
-		}
-		try {
-			writer.write(chars, -1, 1);
-			fail();
-		} catch (IndexOutOfBoundsException e) {
-		}
-		try {
-			writer.write(chars, 0, -1);
-			fail();
-		} catch (IndexOutOfBoundsException e) {
-		}
-		try {
-			writer.write(chars, 1, chars.length);
-			fail();
-		} catch (IndexOutOfBoundsException e) {
-		}
-		writer.write(chars, 1, 2);
-		writer.flush();
-		assertEquals("hi", out.toString("utf-8"));
-		writer.write(chars, 0, chars.length);
-		writer.flush();
-		assertEquals("hi" + source, out.toString("utf-8"));
-			
-		writer.close();
-        //after the stream is closed ,should throw IOException first
-		try {
-			writer.write((char[]) null, -1, -1);
-			fail("should throw IOException");
-		} catch (IOException e) {
-			//expected
-		}
-
-	}
-
-	/*
-	 * Class under test for void write(int)
-	 */
-	public void testWriteint() throws IOException {
-		writer.write(1);
-		writer.flush();
-		String str = new String(out.toByteArray(), "utf-8");
-		assertEquals("\u0001", str);
-
-		writer.write(2);
-		writer.flush();
-		str = new String(out.toByteArray(), "utf-8");
-		assertEquals("\u0001\u0002", str);
-
-		writer.write(-1);
-		writer.flush();
-		str = new String(out.toByteArray(), "utf-8");
-		assertEquals("\u0001\u0002\uffff", str);
-
-		writer.write(0xfedcb);
-		writer.flush();
-		str = new String(out.toByteArray(), "utf-8");
-		assertEquals("\u0001\u0002\uffff\uedcb", str);
-		
-		writer.close();
-		 //after the stream is closed ,should throw IOException
-		try {
-			writer.write(1);
+    static private final String source = "This is a test message with Unicode character. \u4e2d\u56fd is China's name in Chinese";
+
+    static private final String[] MINIMAL_CHARSETS = new String[] { "US-ASCII",
+            "ISO-8859-1", "UTF-16BE", "UTF-16LE", "UTF-16", "UTF-8" };
+
+    OutputStreamWriter osw;
+
+    InputStreamReader isr;
+
+    private ByteArrayOutputStream fos;
+
+    String testString = "Test_All_Tests\nTest_java_io_BufferedInputStream\nTest_java_io_BufferedOutputStream\nTest_java_io_ByteArrayInputStream\nTest_java_io_ByteArrayOutputStream\nTest_java_io_DataInputStream\n";
+
+    /*
+     * @see TestCase#setUp()
+     */
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+        out = new ByteArrayOutputStream();
+        writer = new OutputStreamWriter(out, "utf-8");
+
+        fos = new ByteArrayOutputStream();
+        osw = new OutputStreamWriter(fos);
+    }
+
+    /*
+     * @see TestCase#tearDown()
+     */
+    @Override
+    protected void tearDown() throws Exception {
+        try {
+            writer.close();
+
+            if (isr != null) {
+                isr.close();
+            }
+            osw.close();
+        } catch (Exception e) {
+            // Ignored
+        }
+
+        super.tearDown();
+    }
+
+    public void testClose() throws Exception {
+        writer.flush();
+        writer.close();
+        try {
+            writer.flush();
+            fail();
+        } catch (IOException e) {
+            // Expected
+        }
+    }
+
+    public void testFlush() throws Exception {
+        writer.write(source);
+        writer.flush();
+        String result = out.toString("utf-8");
+        assertEquals(source, result);
+    }
+
+    /*
+     * Class under test for void write(char[], int, int)
+     */
+    public void testWritecharArrayintint() throws IOException {
+        char[] chars = source.toCharArray();
+
+        // Throws IndexOutOfBoundsException if offset is negative
+        try {
+            writer.write((char[]) null, -1, -1);
+            fail("should throw IndexOutOfBoundsException");
+        } catch (IndexOutOfBoundsException e) {
+            // Expected
+        }
+
+        // throws NullPointerException though count is negative
+        try {
+            writer.write((char[]) null, 1, -1);
+            fail("should throw NullPointerException");
+        } catch (NullPointerException e) {
+            // Expected
+        }
+
+        try {
+            writer.write((char[]) null, 1, 1);
+            fail();
+        } catch (NullPointerException e) {
+            // Expected
+        }
+        try {
+            writer.write(new char[0], 0, 1);
+            fail();
+        } catch (IndexOutOfBoundsException e) {
+            // Expected
+        }
+        try {
+            writer.write(chars, -1, 1);
+            fail();
+        } catch (IndexOutOfBoundsException e) {
+            // Expected
+        }
+        try {
+            writer.write(chars, 0, -1);
+            fail();
+        } catch (IndexOutOfBoundsException e) {
+            // Expected
+        }
+        try {
+            writer.write(chars, 1, chars.length);
+            fail();
+        } catch (IndexOutOfBoundsException e) {
+            // Expected
+        }
+        writer.write(chars, 1, 2);
+        writer.flush();
+        assertEquals("hi", out.toString("utf-8"));
+        writer.write(chars, 0, chars.length);
+        writer.flush();
+        assertEquals("hi" + source, out.toString("utf-8"));
+
+        writer.close();
+        // After the stream is closed, should throw IOException first
+        try {
+            writer.write((char[]) null, -1, -1);
             fail("should throw IOException");
-		} catch (IOException e) {
-			//expected
-		}
-		
-		
-	}
-
-	/*
-	 * Class under test for void write(String, int, int)
-	 */
-	public void testWriteStringintint() throws IOException {
-		try {
-			writer.write((String) null, 1, 1);
-			fail();
-		} catch (NullPointerException e) {
-		}
-		try {
-			writer.write("", 0, 1);
-			fail();
-		} catch (StringIndexOutOfBoundsException e) {
-		}
-		try {
-			writer.write("abc", -1, 1);
-			fail();
-		} catch (StringIndexOutOfBoundsException e) {
-		}
-		try {
-			writer.write("abc", 0, -1);
-			fail();
-		} catch (IndexOutOfBoundsException e) {
-		}
-		try {
-			writer.write("abc", 1, 3);
-			fail();
-		} catch (StringIndexOutOfBoundsException e) {
-		}
-		
-		//throws IndexOutOfBoundsException before NullPointerException if count is negative
-		try {
-			writer.write((String) null, -1, -1);
-			fail("should throw IndexOutOfBoundsException");
-		} catch (IndexOutOfBoundsException e) {
-			//expected
-		}
-		
-		//throws NullPointerException before StringIndexOutOfBoundsException 
-		try {
-			writer.write((String) null, -1, 0);
-			fail("should throw NullPointerException");
-		} catch (NullPointerException e) {
-			//expected
-		}
-		
-		writer.write("abc", 1, 2);
-		writer.flush();
-		assertEquals("bc", out.toString("utf-8"));
-		writer.write(source, 0, source.length());
-		writer.flush();
-		assertEquals("bc" + source, out.toString("utf-8"));
-		
-		writer.close();
-        //throws IndexOutOfBoundsException first if count is negative
-		try {
-			writer.write((String) null, 0, -1);
-			fail("should throw IndexOutOfBoundsException");
-		} catch (IndexOutOfBoundsException e) {
-			//expected
-		}
-		
-		try {
-			writer.write((String) null, -1, 0);
-			fail("should throw NullPointerException");
-		} catch (NullPointerException e) {
-			//expected
-		}
-		
-		try {
-			writer.write("abc", -1, 0);
-			fail("should throw StringIndexOutOfBoundsException");
-		} catch (StringIndexOutOfBoundsException e) {
-			//expected
-		}
-		
-		//throws IOException
-		try {
-			writer.write("abc", 0, 1);
-			fail("should throw IOException");
-		} catch (IOException e) {
-			//expected
-		}
-
-	}
-
-	/*
-	 * Class under test for void OutputStreamWriter(OutputStream)
-	 */
-	public void testOutputStreamWriterOutputStream() throws IOException {
-		try {
-			writer = new OutputStreamWriter(null);
-			fail();
-		} catch (NullPointerException e) {
-		}
-		OutputStreamWriter writer2 = new OutputStreamWriter(out);
-		writer2.close();
-	}
-
-	/*
-	 * Class under test for void OutputStreamWriter(OutputStream, String)
-	 */
-	public void testOutputStreamWriterOutputStreamString() throws IOException {
-		try {
-			writer = new OutputStreamWriter(null, "utf-8");
-			fail();
-		} catch (NullPointerException e) {
-		}
-		try {
-			writer = new OutputStreamWriter(out, "");
-			fail();
-		} catch (UnsupportedEncodingException e) {
-		}
-		try {
-			writer = new OutputStreamWriter(out, "badname");
-			fail();
-		} catch (UnsupportedEncodingException e) {
-		}
-		try {
-			writer = new OutputStreamWriter(out, (String) null);
-			fail();
-		} catch (NullPointerException e) {
-		}
-		OutputStreamWriter writer2 = new OutputStreamWriter(out, "ascii");
-		assertEquals(Charset.forName("ascii"), Charset.forName(writer2
-				.getEncoding()));
-		writer2.close();
-	}
-
-	/*
-	 * Class under test for void OutputStreamWriter(OutputStream)
-	 */
-	public void testOutputStreamWriterOutputStreamCharset() throws IOException {
-		Charset cs = Charset.forName("ascii");
-		try {
-			writer = new OutputStreamWriter(null, cs);
-			fail();
-		} catch (NullPointerException e) {
-		}
-		try {
-			writer = new OutputStreamWriter(out, (Charset) null);
-			fail();
-		} catch (NullPointerException e) {
-		}
-		OutputStreamWriter writer2 = new OutputStreamWriter(out, cs);
-		assertEquals(cs, Charset.forName(writer2.getEncoding()));
-		writer2.close();
-	}
-
-	/*
-	 * Class under test for void OutputStreamWriter(OutputStream, String)
-	 */
-	public void testOutputStreamWriterOutputStreamCharsetEncoder()
-			throws IOException {
-		Charset cs = Charset.forName("ascii");
-		CharsetEncoder enc = cs.newEncoder();
-		try {
-			writer = new OutputStreamWriter(null, enc);
-			fail();
-		} catch (NullPointerException e) {
-		}
-		try {
-			writer = new OutputStreamWriter(out, (CharsetEncoder) null);
-			fail();
-		} catch (NullPointerException e) {
-		}
-		OutputStreamWriter writer2 = new OutputStreamWriter(out, enc);
-		assertEquals(cs, Charset.forName(writer2.getEncoding()));
-		writer2.close();
-	}
-
-	public void testGetEncoding() {
-		Charset cs = Charset.forName("utf-8");
-		assertEquals(cs, Charset.forName(writer.getEncoding()));
-	}
-
-	public void testHandleEarlyEOFChar_1() {
-		String str = "All work and no play makes Jack a dull boy\n"; //$NON-NLS-1$
-		int NUMBER = 2048;
-		int j = 0;
-		int len = str.length() * NUMBER;
-		/* == 88064 *//* NUMBER compulsively written copies of the same string */
-		char[] strChars = new char[len];
-		for (int i = 0; i < NUMBER; ++i) {
-			for (int k = 0; k < str.length(); ++k) {
-				strChars[j++] = str.charAt(k);
-			}
-		}
-		File f = null;
-		FileWriter fw = null;
-		try {
-			f = File.createTempFile("ony", "by_one");
-			fw = new FileWriter(f);
-			fw.write(strChars);
-			fw.close();
-			InputStreamReader in = null;
-			FileInputStream fis = new FileInputStream(f);
-			in = new InputStreamReader(fis);
-			int b;
-			int errors = 0;
-			for (int offset = 0; offset < strChars.length; ++offset) {
-				b = in.read();
-				if (b == -1) {
-					fail("Early EOF at offset " + offset + "\n");
-					return;
-				}
-			}
-			assertEquals(0, errors);
-		} catch (IOException e) {
-			e.printStackTrace();
-		}
-	}
-
-	public void testHandleEarlyEOFChar_2() throws IOException {
-		int capacity = 65536;
-		byte[] bytes = new byte[capacity];
-		byte[] bs = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H' };
-		for (int i = 0; i < bytes.length; i++) {
-			bytes[i] = bs[i / 8192];
-		}
-		String inputStr = new String(bytes);
-		int len = inputStr.length();
-		File f = File.createTempFile("FileWriterBugTest ", null); //$NON-NLS-1$
-		FileWriter writer = new FileWriter(f);
-		writer.write(inputStr);
-		writer.close();
-		long flen = f.length();
-
-		FileReader reader = new FileReader(f);
-		char[] outChars = new char[capacity];
-		int outCount = reader.read(outChars);
-		String outStr = new String(outChars, 0, outCount);
-
-		f.deleteOnExit();
-		assertEquals(len, flen);
-		assertEquals(inputStr, outStr);
-
-	}
-
-	public void testSingleCharIO() throws Exception {
-		InputStreamReader isr = null;
-		for (int i = 0; i < MINIMAL_CHARSETS.length; ++i) {
-			try {
-				out = new ByteArrayOutputStream();
-				writer = new OutputStreamWriter(out, MINIMAL_CHARSETS[i]);
-
-				int upper = UPPER;
-				switch (i) {
-				case 0:
-					upper = 128;
-					break;
-				case 1:
-					upper = 256;
-					break;
-				}
-
-				for (int c = 0; c < upper; ++c) {
-					writer.write(c);
-				}
-				writer.flush();
-				byte[] result = out.toByteArray();
-
-				isr = new InputStreamReader(new ByteArrayInputStream(result),
-						MINIMAL_CHARSETS[i]);
-				for (int expected = 0; expected < upper; ++expected) {
-					assertEquals("Error when reading bytes in "
-							+ MINIMAL_CHARSETS[i], expected, isr.read());
-				}
-			} finally {
-				try {
-					isr.close();
-				} catch (Exception e) {
-				}
-				try {
-					writer.close();
-				} catch (Exception e) {
-				}
-			}
-		}
-	}
-
-	public void testBlockIO() throws Exception {
-		InputStreamReader isr = null;
-		char[] largeBuffer = new char[BUFFER_SIZE];
-		for (int i = 0; i < MINIMAL_CHARSETS.length; ++i) {
-			try {
-				out = new ByteArrayOutputStream();
-				writer = new OutputStreamWriter(out, MINIMAL_CHARSETS[i]);
-
-				int upper = UPPER;
-				switch (i) {
-				case 0:
-					upper = 128;
-					break;
-				case 1:
-					upper = 256;
-					break;
-				}
-
-				int m = 0;
-				for (int c = 0; c < upper; ++c) {
-					largeBuffer[m++] = (char) c;
-					if (m == BUFFER_SIZE) {
-						writer.write(largeBuffer);
-						m = 0;
-					}
-				}
-				writer.write(largeBuffer, 0, m);
-				writer.flush();
-				byte[] result = out.toByteArray();
-
-				isr = new InputStreamReader(new ByteArrayInputStream(result),
-						MINIMAL_CHARSETS[i]);
-				int expected = 0, read = 0, j = 0;
-				while (expected < upper) {
-					if (j == read) {
-						read = isr.read(largeBuffer);
-						j = 0;
-					}
-					assertEquals("Error when reading bytes in "
-							+ MINIMAL_CHARSETS[i], expected++, largeBuffer[j++]);
-				}
-			} finally {
-				try {
-					isr.close();
-				} catch (Exception e) {
-				}
-				try {
-					writer.close();
-				} catch (Exception e) {
-				}
-			}
-		}
-	}
-
-	/**
-	 * @tests java.io.OutputStreamWriter#OutputStreamWriter(java.io.OutputStream)
-	 */
-	public void test_ConstructorLjava_io_OutputStream() {
-		// Test for method java.io.OutputStreamWriter(java.io.OutputStream)
-		assertTrue("Used in tests", true);
-	}
-
-	/**
-	 * @tests java.io.OutputStreamWriter#OutputStreamWriter(java.io.OutputStream,
-	 *        java.lang.String)
-	 */
-	public void test_ConstructorLjava_io_OutputStreamLjava_lang_String() {
-		// Test for method java.io.OutputStreamWriter(java.io.OutputStream,
-		// java.lang.String)
-		try {
-			osw = new OutputStreamWriter(fos, "8859_1");
-		} catch (UnsupportedEncodingException e) {
-			fail("Unable to create output stream : " + e.getMessage());
-		}
-		try {
-			osw = new OutputStreamWriter(fos, "Bogus");
-		} catch (UnsupportedEncodingException e) {
-			return;
-		}
-		fail("Failed to throw Unsupported Encoding exception");
-	}
-
-	/**
-	 * @tests java.io.OutputStreamWriter#close()
-	 */
-	public void test_close() {
-		// Test for method void java.io.OutputStreamWriter.close()
-		boolean exception = false;
-		try {
-			osw.close();
-			osw.write(testString, 0, testString.length());
-		} catch (IOException e) {
-			exception = true;
-		}
-		assertTrue("Chars written after close", exception);
-
-		ByteArrayOutputStream bout = new ByteArrayOutputStream();
-		try {
-			OutputStreamWriter writer = new OutputStreamWriter(bout,
-					"ISO2022JP");
-			writer.write(new char[] { 'a' });
-			writer.close();
-			// the default is ASCII, there should not be any mode changes
-			String converted = new String(bout.toByteArray(), "ISO8859_1");
-			assertTrue("invalid conversion 1: " + converted, converted
-					.equals("a"));
-
-			bout.reset();
-			writer = new OutputStreamWriter(bout, "ISO2022JP");
-			writer.write(new char[] { '\u3048' });
-			writer.flush();
-			// the byte sequence should not switch to ASCII mode until the
-			// stream is closed
-			converted = new String(bout.toByteArray(), "ISO8859_1");
-			assertTrue("invalid conversion 2: " + converted, converted
-					.equals("\u001b$B$("));
-			writer.close();
-			converted = new String(bout.toByteArray(), "ISO8859_1");
-			assertTrue("invalid conversion 3: " + converted, converted
-					.equals("\u001b$B$(\u001b(B"));
-
-			bout.reset();
-			writer = new OutputStreamWriter(bout, "ISO2022JP");
-			writer.write(new char[] { '\u3048' });
-			writer.write(new char[] { '\u3048' });
-			writer.close();
-			// there should not be a mode switch between writes
-			assertEquals("invalid conversion 4", "\u001b$B$($(\u001b(B", new String(bout.toByteArray(),
-					"ISO8859_1"));
-		} catch (UnsupportedEncodingException e) {
-			// Can't test missing converter
-			System.out.println(e);
-		} catch (IOException e) {
-			fail("Unexpected: " + e);
-		}
-	}
-
-	/**
-	 * @tests java.io.OutputStreamWriter#flush()
-	 */
-	public void test_flush() throws Exception {
-		// Test for method void java.io.OutputStreamWriter.flush()
-                char[] buf = new char[testString.length()];
-                osw.write(testString, 0, testString.length());
-                osw.flush();
-                openInputStream();
-                isr.read(buf, 0, buf.length);
-                assertTrue("Chars not flushed", new String(buf, 0, buf.length)
-                                .equals(testString));
-        }
-
-	/**
-	 * @tests java.io.OutputStreamWriter#getEncoding()
-	 */
-	public void test_getEncoding() {
-		// Test for method java.lang.String
-		// java.io.OutputStreamWriter.getEncoding()
-		try {
-			osw = new OutputStreamWriter(fos, "8859_1");
-		} catch (UnsupportedEncodingException e) {
-			assertEquals("Returned incorrect encoding", 
-					"8859_1", osw.getEncoding());
-		}
+        } catch (IOException e) {
+            // Expected
+        }
+    }
 
-        OutputStreamWriter out = null;
+    /*
+     * Class under test for void write(int)
+     */
+    public void testWriteint() throws IOException {
+        writer.write(1);
+        writer.flush();
+        String str = new String(out.toByteArray(), "utf-8");
+        assertEquals("\u0001", str);
+
+        writer.write(2);
+        writer.flush();
+        str = new String(out.toByteArray(), "utf-8");
+        assertEquals("\u0001\u0002", str);
+
+        writer.write(-1);
+        writer.flush();
+        str = new String(out.toByteArray(), "utf-8");
+        assertEquals("\u0001\u0002\uffff", str);
+
+        writer.write(0xfedcb);
+        writer.flush();
+        str = new String(out.toByteArray(), "utf-8");
+        assertEquals("\u0001\u0002\uffff\uedcb", str);
+
+        writer.close();
+        // After the stream is closed, should throw IOException
         try {
-            out = new OutputStreamWriter(new ByteArrayOutputStream(),
-                    "UTF-16BE");
+            writer.write(1);
+            fail("should throw IOException");
+        } catch (IOException e) {
+            // expected
+        }
+    }
+
+    /*
+     * Class under test for void write(String, int, int)
+     */
+    public void testWriteStringintint() throws IOException {
+        try {
+            writer.write((String) null, 1, 1);
+            fail();
+        } catch (NullPointerException e) {
+            // Expected
+        }
+        try {
+            writer.write("", 0, 1);
+            fail();
+        } catch (StringIndexOutOfBoundsException e) {
+            // Expected
+        }
+        try {
+            writer.write("abc", -1, 1);
+            fail();
+        } catch (StringIndexOutOfBoundsException e) {
+            // Expected
+        }
+        try {
+            writer.write("abc", 0, -1);
+            fail();
+        } catch (IndexOutOfBoundsException e) {
+            // Expected
+        }
+        try {
+            writer.write("abc", 1, 3);
+            fail();
+        } catch (StringIndexOutOfBoundsException e) {
+            // Expected
+        }
+
+        // Throws IndexOutOfBoundsException before NullPointerException if count
+        // is negative
+        try {
+            writer.write((String) null, -1, -1);
+            fail("should throw IndexOutOfBoundsException");
+        } catch (IndexOutOfBoundsException e) {
+            // Expected
+        }
+
+        // Throws NullPointerException before StringIndexOutOfBoundsException
+        try {
+            writer.write((String) null, -1, 0);
+            fail("should throw NullPointerException");
+        } catch (NullPointerException e) {
+            // expected
+        }
+
+        writer.write("abc", 1, 2);
+        writer.flush();
+        assertEquals("bc", out.toString("utf-8"));
+        writer.write(source, 0, source.length());
+        writer.flush();
+        assertEquals("bc" + source, out.toString("utf-8"));
+
+        writer.close();
+        // Throws IndexOutOfBoundsException first if count is negative
+        try {
+            writer.write((String) null, 0, -1);
+            fail("should throw IndexOutOfBoundsException");
+        } catch (IndexOutOfBoundsException e) {
+            // Expected
+        }
+
+        try {
+            writer.write((String) null, -1, 0);
+            fail("should throw NullPointerException");
+        } catch (NullPointerException e) {
+            // Expected
+        }
+
+        try {
+            writer.write("abc", -1, 0);
+            fail("should throw StringIndexOutOfBoundsException");
+        } catch (StringIndexOutOfBoundsException e) {
+            // Expected
+        }
+
+        // Throws IOException
+        try {
+            writer.write("abc", 0, 1);
+            fail("should throw IOException");
+        } catch (IOException e) {
+            // expected
+        }
+    }
+
+    /*
+     * Class under test for void OutputStreamWriter(OutputStream)
+     */
+    public void testOutputStreamWriterOutputStream() throws IOException {
+        try {
+            writer = new OutputStreamWriter(null);
+            fail();
+        } catch (NullPointerException e) {
+            // Expected
+        }
+        OutputStreamWriter writer2 = new OutputStreamWriter(out);
+        writer2.close();
+    }
+
+    /*
+     * Class under test for void OutputStreamWriter(OutputStream, String)
+     */
+    public void testOutputStreamWriterOutputStreamString() throws IOException {
+        try {
+            writer = new OutputStreamWriter(null, "utf-8");
+            fail();
+        } catch (NullPointerException e) {
+            // Expected
+        }
+        try {
+            writer = new OutputStreamWriter(out, "");
+            fail();
         } catch (UnsupportedEncodingException e) {
-            fail("Should not throw UnsupportedEncodingException");
+            // Expected
         }
         try {
-            out.close();
+            writer = new OutputStreamWriter(out, "badname");
+            fail();
+        } catch (UnsupportedEncodingException e) {
+            // Expected
+        }
+        try {
+            writer = new OutputStreamWriter(out, (String) null);
+            fail();
+        } catch (NullPointerException e) {
+            // Expected
+        }
+        OutputStreamWriter writer2 = new OutputStreamWriter(out, "ascii");
+        assertEquals(Charset.forName("ascii"), Charset.forName(writer2
+                .getEncoding()));
+        writer2.close();
+    }
+
+    /*
+     * Class under test for void OutputStreamWriter(OutputStream)
+     */
+    public void testOutputStreamWriterOutputStreamCharset() throws IOException {
+        Charset cs = Charset.forName("ascii");
+        try {
+            writer = new OutputStreamWriter(null, cs);
+            fail();
+        } catch (NullPointerException e) {
+            // Expected
+        }
+        try {
+            writer = new OutputStreamWriter(out, (Charset) null);
+            fail();
+        } catch (NullPointerException e) {
+            // Expected
+        }
+        OutputStreamWriter writer2 = new OutputStreamWriter(out, cs);
+        assertEquals(cs, Charset.forName(writer2.getEncoding()));
+        writer2.close();
+    }
+
+    /*
+     * Class under test for void OutputStreamWriter(OutputStream, String)
+     */
+    public void testOutputStreamWriterOutputStreamCharsetEncoder()
+            throws IOException {
+        Charset cs = Charset.forName("ascii");
+        CharsetEncoder enc = cs.newEncoder();
+        try {
+            writer = new OutputStreamWriter(null, enc);
+            fail();
+        } catch (NullPointerException e) {
+            // Expected
+        }
+        try {
+            writer = new OutputStreamWriter(out, (CharsetEncoder) null);
+            fail();
+        } catch (NullPointerException e) {
+            // Expected
+        }
+        OutputStreamWriter writer2 = new OutputStreamWriter(out, enc);
+        assertEquals(cs, Charset.forName(writer2.getEncoding()));
+        writer2.close();
+    }
+
+    public void testGetEncoding() {
+        Charset cs = Charset.forName("utf-8");
+        assertEquals(cs, Charset.forName(writer.getEncoding()));
+    }
+
+    public void testHandleEarlyEOFChar_1() throws IOException {
+        String str = "All work and no play makes Jack a dull boy\n"; //$NON-NLS-1$
+        int NUMBER = 2048;
+        int j = 0;
+        int len = str.length() * NUMBER;
+        char[] strChars = new char[len];
+        for (int i = 0; i < NUMBER; ++i) {
+            for (int k = 0; k < str.length(); ++k) {
+                strChars[j++] = str.charAt(k);
+            }
+        }
+
+        File f = File.createTempFile("one", "by_one");
+        FileWriter fw = new FileWriter(f);
+        fw.write(strChars);
+        fw.close();
+        FileInputStream fis = new FileInputStream(f);
+        InputStreamReader in = new InputStreamReader(fis);
+        for (int offset = 0; offset < strChars.length; ++offset) {
+            int b = in.read();
+            assertFalse("Early EOF at offset", -1 == b);
+        }
+    }
+
+    public void testHandleEarlyEOFChar_2() throws IOException {
+        int capacity = 65536;
+        byte[] bytes = new byte[capacity];
+        byte[] bs = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H' };
+        for (int i = 0; i < bytes.length; i++) {
+            bytes[i] = bs[i / 8192];
+        }
+        String inputStr = new String(bytes);
+        int len = inputStr.length();
+        File f = File.createTempFile("FileWriterBugTest ", null); //$NON-NLS-1$
+        FileWriter writer = new FileWriter(f);
+        writer.write(inputStr);
+        writer.close();
+        long flen = f.length();
+
+        FileReader reader = new FileReader(f);
+        char[] outChars = new char[capacity];
+        int outCount = reader.read(outChars);
+        String outStr = new String(outChars, 0, outCount);
+
+        f.deleteOnExit();
+        assertEquals(len, flen);
+        assertEquals(inputStr, outStr);
+    }
+
+    public void testSingleCharIO() throws Exception {
+        InputStreamReader isr = null;
+        for (int i = 0; i < MINIMAL_CHARSETS.length; ++i) {
+            try {
+                out = new ByteArrayOutputStream();
+                writer = new OutputStreamWriter(out, MINIMAL_CHARSETS[i]);
+
+                int upper = UPPER;
+                switch (i) {
+                case 0:
+                    upper = 128;
+                    break;
+                case 1:
+                    upper = 256;
+                    break;
+                }
+
+                for (int c = 0; c < upper; ++c) {
+                    writer.write(c);
+                }
+                writer.flush();
+                byte[] result = out.toByteArray();
+
+                isr = new InputStreamReader(new ByteArrayInputStream(result),
+                        MINIMAL_CHARSETS[i]);
+                for (int expected = 0; expected < upper; ++expected) {
+                    assertEquals("Error when reading bytes in "
+                            + MINIMAL_CHARSETS[i], expected, isr.read());
+                }
+            } finally {
+                try {
+                    isr.close();
+                } catch (Exception e) {
+                }
+                try {
+                    writer.close();
+                } catch (Exception e) {
+                }
+            }
+        }
+    }
+
+    public void testBlockIO() throws Exception {
+        InputStreamReader isr = null;
+        char[] largeBuffer = new char[BUFFER_SIZE];
+        for (int i = 0; i < MINIMAL_CHARSETS.length; ++i) {
+            try {
+                out = new ByteArrayOutputStream();
+                writer = new OutputStreamWriter(out, MINIMAL_CHARSETS[i]);
+
+                int upper = UPPER;
+                switch (i) {
+                case 0:
+                    upper = 128;
+                    break;
+                case 1:
+                    upper = 256;
+                    break;
+                }
+
+                int m = 0;
+                for (int c = 0; c < upper; ++c) {
+                    largeBuffer[m++] = (char) c;
+                    if (m == BUFFER_SIZE) {
+                        writer.write(largeBuffer);
+                        m = 0;
+                    }
+                }
+                writer.write(largeBuffer, 0, m);
+                writer.flush();
+                byte[] result = out.toByteArray();
+
+                isr = new InputStreamReader(new ByteArrayInputStream(result),
+                        MINIMAL_CHARSETS[i]);
+                int expected = 0, read = 0, j = 0;
+                while (expected < upper) {
+                    if (j == read) {
+                        read = isr.read(largeBuffer);
+                        j = 0;
+                    }
+                    assertEquals("Error when reading bytes in "
+                            + MINIMAL_CHARSETS[i], expected++, largeBuffer[j++]);
+                }
+            } finally {
+                try {
+                    isr.close();
+                } catch (Exception e) {
+                }
+                try {
+                    writer.close();
+                } catch (Exception e) {
+                }
+            }
+        }
+    }
+
+    /**
+     * @tests java.io.OutputStreamWriter#OutputStreamWriter(java.io.OutputStream)
+     */
+    public void test_ConstructorLjava_io_OutputStream() {
+        assertTrue("Used in tests", true);
+    }
+
+    /**
+     * @tests java.io.OutputStreamWriter#OutputStreamWriter(java.io.OutputStream,
+     *        java.lang.String)
+     */
+    public void test_ConstructorLjava_io_OutputStreamLjava_lang_String()
+            throws UnsupportedEncodingException {
+        osw = new OutputStreamWriter(fos, "8859_1");
+        try {
+            osw = new OutputStreamWriter(fos, "Bogus");
+            fail("Failed to throw Unsupported Encoding exception");
+        } catch (UnsupportedEncodingException e) {
+            // Expected
+        }
+    }
+
+    /**
+     * @tests java.io.OutputStreamWriter#close()
+     */
+    public void test_close() throws IOException {
+        osw.close();
+
+        try {
+            osw.write(testString, 0, testString.length());
+            fail("Chars written after close");
         } catch (IOException e) {
-            fail("Should not throw IOException");
+            // Expected
         }
+
+        ByteArrayOutputStream bout = new ByteArrayOutputStream();
+        try {
+            OutputStreamWriter writer = new OutputStreamWriter(bout,
+                    "ISO2022JP");
+            writer.write(new char[] { 'a' });
+            writer.close();
+            // the default is ASCII, there should not be any mode changes
+            String converted = new String(bout.toByteArray(), "ISO8859_1");
+            assertTrue("invalid conversion 1: " + converted, converted
+                    .equals("a"));
+
+            bout.reset();
+            writer = new OutputStreamWriter(bout, "ISO2022JP");
+            writer.write(new char[] { '\u3048' });
+            writer.flush();
+            // the byte sequence should not switch to ASCII mode until the
+            // stream is closed
+            converted = new String(bout.toByteArray(), "ISO8859_1");
+            assertTrue("invalid conversion 2: " + converted, converted
+                    .equals("\u001b$B$("));
+            writer.close();
+            converted = new String(bout.toByteArray(), "ISO8859_1");
+            assertTrue("invalid conversion 3: " + converted, converted
+                    .equals("\u001b$B$(\u001b(B"));
+
+            bout.reset();
+            writer = new OutputStreamWriter(bout, "ISO2022JP");
+            writer.write(new char[] { '\u3048' });
+            writer.write(new char[] { '\u3048' });
+            writer.close();
+            // there should not be a mode switch between writes
+            assertEquals("invalid conversion 4", "\u001b$B$($(\u001b(B",
+                    new String(bout.toByteArray(), "ISO8859_1"));
+        } catch (UnsupportedEncodingException e) {
+            // Can't test missing converter
+            System.out.println(e);
+        }
+    }
+
+    /**
+     * @tests java.io.OutputStreamWriter#flush()
+     */
+    public void test_flush() throws IOException {
+        char[] buf = new char[testString.length()];
+        osw.write(testString, 0, testString.length());
+        osw.flush();
+        openInputStream();
+        isr.read(buf, 0, buf.length);
+        assertTrue("Chars not flushed", new String(buf, 0, buf.length)
+                .equals(testString));
+    }
+
+    /**
+     * @tests java.io.OutputStreamWriter#getEncoding()
+     */
+    public void test_getEncoding() throws IOException {
+        try {
+            osw = new OutputStreamWriter(fos, "8859_1");
+        } catch (UnsupportedEncodingException e) {
+            assertEquals("Returned incorrect encoding", "8859_1", osw
+                    .getEncoding());
+        }
+
+        OutputStreamWriter out = new OutputStreamWriter(
+                new ByteArrayOutputStream(), "UTF-16BE");
+        out.close();
+
         String result = out.getEncoding();
         assertNull(result);
 
-        
         out = null;
         try {
             out = new OutputStreamWriter(new ByteArrayOutputStream(),
@@ -676,51 +659,44 @@
         assertEquals("UnicodeBigUnmarked", result);
     }
 
-	/**
-	 * @tests java.io.OutputStreamWriter#write(char[], int, int)
-	 */
-	public void test_write$CII() throws Exception {
-		// Test for method void java.io.OutputStreamWriter.write(char [], int,
-		// int)
-                char[] buf = new char[testString.length()];
-                osw.write(testString, 0, testString.length());
-                osw.close();
-                openInputStream();
-                isr.read(buf, 0, buf.length);
-                assertTrue("Incorrect chars returned", new String(buf, 0,
-                                buf.length).equals(testString));
-	}
-
-	/**
-	 * @tests java.io.OutputStreamWriter#write(int)
-	 */
-	public void test_writeI() throws Exception {
-		// Test for method void java.io.OutputStreamWriter.write(int)
-                osw.write('T');
-                osw.close();
-                openInputStream();
-                int c = isr.read();
-                assertEquals("Incorrect char returned", 'T', (char) c);
-	}
-
-	/**
-	 * @tests java.io.OutputStreamWriter#write(java.lang.String, int, int)
-	 */
-	public void test_writeLjava_lang_StringII() throws Exception {
-		// Test for method void
-		// java.io.OutputStreamWriter.write(java.lang.String, int, int)
-
-                char[] buf = new char[testString.length()];
-                osw.write(testString, 0, testString.length());
-                osw.close();
-                openInputStream();
-                isr.read(buf);
-                assertTrue("Incorrect chars returned", new String(buf, 0,
-                                buf.length).equals(testString));
-	}
-
-	private void openInputStream() {
-		isr = new InputStreamReader(new ByteArrayInputStream(fos.toByteArray()));
-	}
+    /**
+     * @tests java.io.OutputStreamWriter#write(char[], int, int)
+     */
+    public void test_write$CII() throws IOException {
+        char[] buf = new char[testString.length()];
+        osw.write(testString, 0, testString.length());
+        osw.close();
+        openInputStream();
+        isr.read(buf, 0, buf.length);
+        assertTrue("Incorrect chars returned", new String(buf, 0, buf.length)
+                .equals(testString));
+    }
 
+    /**
+     * @tests java.io.OutputStreamWriter#write(int)
+     */
+    public void test_writeI() throws IOException {
+        osw.write('T');
+        osw.close();
+        openInputStream();
+        int c = isr.read();
+        assertEquals("Incorrect char returned", 'T', (char) c);
+    }
+
+    /**
+     * @tests java.io.OutputStreamWriter#write(java.lang.String, int, int)
+     */
+    public void test_writeLjava_lang_StringII() throws IOException {
+        char[] buf = new char[testString.length()];
+        osw.write(testString, 0, testString.length());
+        osw.close();
+        openInputStream();
+        isr.read(buf);
+        assertTrue("Incorrect chars returned", new String(buf, 0, buf.length)
+                .equals(testString));
+    }
+
+    private void openInputStream() {
+        isr = new InputStreamReader(new ByteArrayInputStream(fos.toByteArray()));
+    }
 }

Modified: harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/PipedInputStreamTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/PipedInputStreamTest.java?rev=617085&r1=617084&r2=617085&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/PipedInputStreamTest.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/PipedInputStreamTest.java Thu Jan 31 02:04:05 2008
@@ -42,26 +42,11 @@
 		public PWriter(PipedOutputStream pout, int nbytes) {
 			pos = pout;
 			bytes = new byte[nbytes];
-			for (int i = 0; i < bytes.length; i++)
+			for (int i = 0; i < bytes.length; i++) {
 				bytes[i] = (byte) (System.currentTimeMillis() % 9);
+		    }
 		}
 	}
-    
-     static class MockPipedInputStream extends PipedInputStream {
-
-        public MockPipedInputStream(java.io.PipedOutputStream src,
-                int bufferSize) throws IOException {
-            super(src, bufferSize);
-        }
-
-        public MockPipedInputStream(int bufferSize) {
-            super(bufferSize);
-        }
-
-        public int bufferLength() {
-            return super.buffer.length;
-        }
-    }
 
 	Thread t;
 
@@ -87,60 +72,6 @@
         pis = new PipedInputStream(new PipedOutputStream());
         pis.available();
     }
-    
-     /**
-     * @tests java.io.PipedInputStream#PipedInputStream(java.io.PipedOutputStream,
-     *        int)
-     * @since 1.6
-     */
-    public void test_Constructor_LPipedOutputStream_I() throws Exception {
-        // Test for method java.io.PipedInputStream(java.io.PipedOutputStream,
-        // int)
-        MockPipedInputStream mpis = new MockPipedInputStream(
-                new PipedOutputStream(), 100);
-        int bufferLength = mpis.bufferLength();
-        assertEquals(100, bufferLength);
-        
-        try {
-            pis = new PipedInputStream(null, -1);
-            fail("Should throw IllegalArgumentException"); //$NON-NLS-1$
-        } catch (IllegalArgumentException e) {
-            // expected
-        }
-        
-        try {
-            pis = new PipedInputStream(null, 0);
-            fail("Should throw IllegalArgumentException"); //$NON-NLS-1$
-        } catch (IllegalArgumentException e) {
-            // expected
-        }
-    }
-
-    /**
-     * @tests java.io.PipedInputStream#PipedInputStream(int)
-     * @since 1.6
-     */
-    public void test_Constructor_I() throws Exception {
-        // Test for method java.io.PipedInputStream(int)
-        MockPipedInputStream mpis = new MockPipedInputStream(100);
-        int bufferLength = mpis.bufferLength();
-        assertEquals(100, bufferLength);
-
-        try {
-            pis = new PipedInputStream(-1);
-            fail("Should throw IllegalArgumentException"); //$NON-NLS-1$
-        } catch (IllegalArgumentException e) {
-            // expected
-        }
-        
-        try {
-            pis = new PipedInputStream(0);
-            fail("Should throw IllegalArgumentException"); //$NON-NLS-1$
-        } catch (IllegalArgumentException e) {
-            // expected
-        }
-    }
-
 
 	/**
 	 * @tests java.io.PipedInputStream#available()
@@ -165,8 +96,9 @@
         // We know the PipedInputStream buffer size is 1024.
         // Writing another byte would cause the write to wait
         // for a read before returning
-        for (int i = 0; i < 1024; i++)
+        for (int i = 0; i < 1024; i++) {
             pout.write(i);
+        }
         assertEquals("Incorrect available count", 1024 , pin.available());
     }
 
@@ -195,8 +127,6 @@
 	 * @tests java.io.PipedInputStream#connect(java.io.PipedOutputStream)
 	 */
 	public void test_connectLjava_io_PipedOutputStream() throws Exception {
-        // Test for method void
-        // java.io.PipedInputStream.connect(java.io.PipedOutputStream)
         pis = new PipedInputStream();
         pos = new PipedOutputStream();
         assertEquals("Non-conected pipe returned non-zero available bytes", 0,
@@ -217,7 +147,6 @@
 	 * @tests java.io.PipedInputStream#read()
 	 */
 	public void test_read() throws Exception {
-        // Test for method int java.io.PipedInputStream.read()
         pis = new PipedInputStream();
         pos = new PipedOutputStream();
 
@@ -238,7 +167,6 @@
 	 * @tests java.io.PipedInputStream#read(byte[], int, int)
 	 */
 	public void test_read$BII() throws Exception {
-        // Test for method int java.io.PipedInputStream.read(byte [], int, int)
         pis = new PipedInputStream();
         pos = new PipedOutputStream();
 
@@ -320,8 +248,9 @@
             public void run() {
                 try {
                     pos.write(1);
-                    while (readerAlive)
+                    while (readerAlive) {
                         ;
+                    }
                     try {
                         // should throw exception since reader thread
                         // is now dead
@@ -329,7 +258,8 @@
                     } catch (IOException e) {
                         pass = true;
                     }
-                } catch (IOException e) {}
+                } catch (IOException e) {
+                }
             }
         }
         WriteRunnable writeRunnable = new WriteRunnable();
@@ -342,7 +272,8 @@
                 try {
                     pis.read();
                     pass = true;
-                } catch (IOException e) {}
+                } catch (IOException e) {
+                }
             }
         }
         ;
@@ -350,12 +281,14 @@
         Thread readThread = new Thread(readRunnable);
         writeThread.start();
         readThread.start();
-        while (readThread.isAlive())
+        while (readThread.isAlive()) {
             ;
+        }
         writeRunnable.readerAlive = false;
         assertTrue("reader thread failed to read", readRunnable.pass);
-        while (writeThread.isAlive())
+        while (writeThread.isAlive()) {
             ;
+        }
         assertTrue("writer thread failed to recognize dead reader",
                 writeRunnable.pass);
 
@@ -386,7 +319,8 @@
             try {
                 // wait for thread t to get to the call to pis.receive
                 Thread.sleep(100);
-            } catch (InterruptedException e) {}
+            } catch (InterruptedException e) {
+            }
             // now we close
             pos.close();
         }
@@ -414,4 +348,74 @@
 		}
         super.tearDown();
 	}
-}
+	
+	    
+     /**
+     * @tests java.io.PipedInputStream#PipedInputStream(java.io.PipedOutputStream,
+     *        int)
+     * @since 1.6
+     */
+    public void test_Constructor_LPipedOutputStream_I() throws Exception {
+        // Test for method java.io.PipedInputStream(java.io.PipedOutputStream,
+        // int)
+        MockPipedInputStream mpis = new MockPipedInputStream(
+                new PipedOutputStream(), 100);
+        int bufferLength = mpis.bufferLength();
+        assertEquals(100, bufferLength);
+        
+        try {
+            pis = new PipedInputStream(null, -1);
+            fail("Should throw IllegalArgumentException"); //$NON-NLS-1$
+        } catch (IllegalArgumentException e) {
+            // expected
+        }
+        
+        try {
+            pis = new PipedInputStream(null, 0);
+            fail("Should throw IllegalArgumentException"); //$NON-NLS-1$
+        } catch (IllegalArgumentException e) {
+            // expected
+        }
+    }
+
+    /**
+     * @tests java.io.PipedInputStream#PipedInputStream(int)
+     * @since 1.6
+     */
+    public void test_Constructor_I() throws Exception {
+        // Test for method java.io.PipedInputStream(int)
+        MockPipedInputStream mpis = new MockPipedInputStream(100);
+        int bufferLength = mpis.bufferLength();
+        assertEquals(100, bufferLength);
+
+        try {
+            pis = new PipedInputStream(-1);
+            fail("Should throw IllegalArgumentException"); //$NON-NLS-1$
+        } catch (IllegalArgumentException e) {
+            // expected
+        }
+        
+        try {
+            pis = new PipedInputStream(0);
+            fail("Should throw IllegalArgumentException"); //$NON-NLS-1$
+        } catch (IllegalArgumentException e) {
+            // expected
+        }
+    }
+	
+    static class MockPipedInputStream extends PipedInputStream {
+
+        public MockPipedInputStream(java.io.PipedOutputStream src,
+                int bufferSize) throws IOException {
+            super(src, bufferSize);
+        }
+
+        public MockPipedInputStream(int bufferSize) {
+            super(bufferSize);
+        }
+
+        public int bufferLength() {
+            return super.buffer.length;
+        }
+    }
+}
\ No newline at end of file

Modified: harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/PipedOutputStreamTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/PipedOutputStreamTest.java?rev=617085&r1=617084&r2=617085&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/PipedOutputStreamTest.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/PipedOutputStreamTest.java Thu Jan 31 02:04:05 2008
@@ -21,92 +21,91 @@
 import java.io.PipedInputStream;
 import java.io.PipedOutputStream;
 
-public class PipedOutputStreamTest extends junit.framework.TestCase {
+import junit.framework.TestCase;
 
-	static class PReader implements Runnable {
-		PipedInputStream reader;
+public class PipedOutputStreamTest extends TestCase {
+
+    static class PReader implements Runnable {
+        PipedInputStream reader;
+
+        public PipedInputStream getReader() {
+            return reader;
+        }
+
+        public PReader(PipedOutputStream out) {
+            try {
+                reader = new PipedInputStream(out);
+            } catch (Exception e) {
+                System.out.println("Couldn't start reader");
+            }
+        }
+
+        public int available() {
+            try {
+                return reader.available();
+            } catch (Exception e) {
+                return -1;
+            }
+        }
+
+        public void run() {
+            try {
+                while (true) {
+                    Thread.sleep(1000);
+                    Thread.yield();
+                }
+            } catch (InterruptedException e) {
+            }
+        }
+
+        public String read(int nbytes) {
+            byte[] buf = new byte[nbytes];
+            try {
+                reader.read(buf, 0, nbytes);
+                return new String(buf);
+            } catch (IOException e) {
+                System.out.println("Exception reading info");
+                return "ERROR";
+            }
+        }
+    }
+
+    Thread rt;
+
+    PReader reader;
+
+    PipedOutputStream out;
+
+    /**
+     * @tests java.io.PipedOutputStream#PipedOutputStream()
+     */
+    public void test_Constructor() {
+        // Used in tests
+    }
+
+    /**
+     * @tests java.io.PipedOutputStream#PipedOutputStream(java.io.PipedInputStream)
+     */
+    public void test_ConstructorLjava_io_PipedInputStream() throws Exception {
+        out = new PipedOutputStream(new PipedInputStream());
+        out.write('b');
+    }
+
+    /**
+     * @tests java.io.PipedOutputStream#close()
+     */
+    public void test_close() throws Exception {
+        out = new PipedOutputStream();
+        rt = new Thread(reader = new PReader(out));
+        rt.start();
+        out.close();
+    }
 
-		public PipedInputStream getReader() {
-			return reader;
-		}
-
-		public PReader(PipedOutputStream out) {
-			try {
-				reader = new PipedInputStream(out);
-			} catch (Exception e) {
-				System.out.println("Couldn't start reader");
-			}
-		}
-
-		public int available() {
-			try {
-				return reader.available();
-			} catch (Exception e) {
-				return -1;
-			}
-		}
-
-		public void run() {
-			try {
-				while (true) {
-					Thread.sleep(1000);
-					Thread.yield();
-				}
-			} catch (InterruptedException e) {
-			}
-		}
-
-		public String read(int nbytes) {
-			byte[] buf = new byte[nbytes];
-			try {
-				reader.read(buf, 0, nbytes);
-				return new String(buf);
-			} catch (IOException e) {
-				System.out.println("Exception reading info");
-				return "ERROR";
-			}
-		}
-	}
-
-	Thread rt;
-
-	PReader reader;
-
-	PipedOutputStream out;
-
-	/**
-	 * @tests java.io.PipedOutputStream#PipedOutputStream()
-	 */
-	public void test_Constructor() {
-		// Test for method java.io.PipedOutputStream()
-		// Used in tests
-	}
-
-	/**
-	 * @tests java.io.PipedOutputStream#PipedOutputStream(java.io.PipedInputStream)
-	 */
-	public void test_ConstructorLjava_io_PipedInputStream() throws Exception {
-		// Test for method java.io.PipedOutputStream(java.io.PipedInputStream)
-
-                out = new PipedOutputStream(new PipedInputStream());
-                out.write('b');
-	}
-
-	/**
-	 * @tests java.io.PipedOutputStream#close()
-	 */
-	public void test_close() throws Exception {
-		// Test for method void java.io.PipedOutputStream.close()
-                out = new PipedOutputStream();
-                rt = new Thread(reader = new PReader(out));
-                rt.start();
-                out.close();
-	}
-    
     /**
      * @tests java.io.PipedOutputStream#connect(java.io.PipedInputStream)
      */
-    public void test_connectLjava_io_PipedInputStream_Exception() throws IOException {
+    public void test_connectLjava_io_PipedInputStream_Exception()
+            throws IOException {
         out = new PipedOutputStream();
         out.connect(new PipedInputStream());
         try {
@@ -117,72 +116,54 @@
         }
     }
 
-	/**
-	 * @tests java.io.PipedOutputStream#connect(java.io.PipedInputStream)
-	 */
-	public void test_connectLjava_io_PipedInputStream() {
-		// Test for method void
-		// java.io.PipedOutputStream.connect(java.io.PipedInputStream)
-		try {
-			out = new PipedOutputStream();
-			rt = new Thread(reader = new PReader(out));
-			rt.start();
-			out.connect(new PipedInputStream());
-		} catch (IOException e) {
-			// Correct
-			return;
-		}
-		fail(
-				"Failed to throw exception attempting connect on already connected stream");
-
-	}
-
-	/**
-	 * @tests java.io.PipedOutputStream#flush()
-	 */
-	public void test_flush() {
-		// Test for method void java.io.PipedOutputStream.flush()
-		try {
-			out = new PipedOutputStream();
-			rt = new Thread(reader = new PReader(out));
-			rt.start();
-			out.write("HelloWorld".getBytes(), 0, 10);
-			assertTrue("Bytes written before flush", reader.available() != 0);
-			out.flush();
-			assertEquals("Wrote incorrect bytes", 
-					"HelloWorld", reader.read(10));
-		} catch (IOException e) {
-			fail("IOException during write test : " + e.getMessage());
-		}
-	}
-
-	/**
-	 * @tests java.io.PipedOutputStream#write(byte[], int, int)
-	 */
-	public void test_write$BII() {
-		// Test for method void java.io.PipedOutputStream.write(byte [], int,
-		// int)
-		try {
-			out = new PipedOutputStream();
-			rt = new Thread(reader = new PReader(out));
-			rt.start();
-			out.write("HelloWorld".getBytes(), 0, 10);
-			out.flush();
-			assertEquals("Wrote incorrect bytes", 
-					"HelloWorld", reader.read(10));
-		} catch (IOException e) {
-			fail("IOException during write test : " + e.getMessage());
-		}
-	}
+    /**
+     * @tests java.io.PipedOutputStream#connect(java.io.PipedInputStream)
+     */
+    public void test_connectLjava_io_PipedInputStream() {
+        try {
+            out = new PipedOutputStream();
+            rt = new Thread(reader = new PReader(out));
+            rt.start();
+            out.connect(new PipedInputStream());
+            fail("Failed to throw exception attempting connect on already connected stream");
+        } catch (IOException e) {
+            // Expected
+        }
+    }
+
+    /**
+     * @tests java.io.PipedOutputStream#flush()
+     */
+    public void test_flush() throws IOException {
+        out = new PipedOutputStream();
+        rt = new Thread(reader = new PReader(out));
+        rt.start();
+        out.write("HelloWorld".getBytes(), 0, 10);
+        assertTrue("Bytes written before flush", reader.available() != 0);
+        out.flush();
+        assertEquals("Wrote incorrect bytes", "HelloWorld", reader.read(10));
+    }
 
     /**
      * @tests java.io.PipedOutputStream#write(byte[], int, int)
-     * Regression for HARMONY-387
+     */
+    public void test_write$BII() throws IOException {
+        out = new PipedOutputStream();
+        rt = new Thread(reader = new PReader(out));
+        rt.start();
+        out.write("HelloWorld".getBytes(), 0, 10);
+        out.flush();
+        assertEquals("Wrote incorrect bytes", "HelloWorld", reader.read(10));
+    }
+
+    /**
+     * @tests java.io.PipedOutputStream#write(byte[], int, int) Regression for
+     *        HARMONY-387
      */
     public void test_write$BII_2() throws IOException {
         PipedInputStream pis = new PipedInputStream();
         PipedOutputStream pos = null;
-        try{
+        try {
             pos = new PipedOutputStream(pis);
             pos.write(new byte[0], -1, -1);
             fail("IndexOutOfBoundsException expected");
@@ -191,7 +172,7 @@
                     "IndexOutOfBoundsException rather than a subclass expected",
                     IndexOutOfBoundsException.class, t.getClass());
         }
-        
+
         // Regression for HARMONY-4311
         try {
             pis = new PipedInputStream();
@@ -200,39 +181,29 @@
             fail("should throw NullPointerException.");
         } catch (NullPointerException e) {
             // expected
-        } 
+        }
+    }
+
+    /**
+     * @tests java.io.PipedOutputStream#write(int)
+     */
+    public void test_writeI() throws IOException {
+        out = new PipedOutputStream();
+        rt = new Thread(reader = new PReader(out));
+        rt.start();
+        out.write('c');
+        out.flush();
+        assertEquals("Wrote incorrect byte", "c", reader.read(1));
     }
 
-	/**
-	 * @tests java.io.PipedOutputStream#write(int)
-	 */
-	public void test_writeI() {
-		// Test for method void java.io.PipedOutputStream.write(int)
-		try {
-			out = new PipedOutputStream();
-			rt = new Thread(reader = new PReader(out));
-			rt.start();
-			out.write('c');
-			out.flush();
-			assertEquals("Wrote incorrect byte", "c", reader.read(1));
-		} catch (IOException e) {
-			fail("IOException during write test : " + e.getMessage());
-		}
-	}
-
-	/**
-	 * Sets up the fixture, for example, open a network connection. This method
-	 * is called before a test is executed.
-	 */
-	protected void setUp() {
-	}
-
-	/**
-	 * Tears down the fixture, for example, close a network connection. This
-	 * method is called after a test is executed.
-	 */
-	protected void tearDown() {
-		if (rt != null)
-			rt.interrupt();
-	}
+    /**
+     * Tears down the fixture, for example, close a network connection. This
+     * method is called after a test is executed.
+     */
+    @Override
+    protected void tearDown() {
+        if (rt != null) {
+            rt.interrupt();
+        }
+    }
 }

Modified: harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/PipedReaderTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/PipedReaderTest.java?rev=617085&r1=617084&r2=617085&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/PipedReaderTest.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/PipedReaderTest.java Thu Jan 31 02:04:05 2008
@@ -21,55 +21,55 @@
 import java.io.PipedReader;
 import java.io.PipedWriter;
 
-public class PipedReaderTest extends junit.framework.TestCase {
+import junit.framework.TestCase;
 
-	static class PWriter implements Runnable {
-		public PipedWriter pw;
+public class PipedReaderTest extends TestCase {
 
-		public PWriter(PipedReader reader) {
-			try {
-				pw = new PipedWriter(reader);
-			} catch (Exception e) {
-				System.out.println("Couldn't create writer");
-			}
-		}
-
-		public PWriter() {
-			pw = new PipedWriter();
-		}
-
-		public void run() {
-			try {
-				char[] c = new char[11];
-				"Hello World".getChars(0, 11, c, 0);
-				pw.write(c);
-				Thread.sleep(10000);
-			} catch (InterruptedException e) {
-			} catch (Exception e) {
-				System.out.println("Exception occurred: " + e.toString());
-			}
-		}
-	}
+    static class PWriter implements Runnable {
+        public PipedWriter pw;
 
-	PipedReader preader;
+        public PWriter(PipedReader reader) {
+            try {
+                pw = new PipedWriter(reader);
+            } catch (Exception e) {
+                System.out.println("Couldn't create writer");
+            }
+        }
+
+        public PWriter() {
+            pw = new PipedWriter();
+        }
+
+        public void run() {
+            try {
+                char[] c = new char[11];
+                "Hello World".getChars(0, 11, c, 0);
+                pw.write(c);
+                Thread.sleep(10000);
+            } catch (InterruptedException e) {
+            } catch (Exception e) {
+                System.out.println("Exception occurred: " + e.toString());
+            }
+        }
+    }
 
-	PWriter pwriter;
+    PipedReader preader;
 
-	Thread t;
+    PWriter pwriter;
 
-	/**
+    Thread t;
+
+    /**
      * @tests java.io.PipedReader#PipedReader()
      */
     public void test_Constructor() {
-    // Test for method java.io.PipedReader()
-    // Used in test
+        // Used in test
     }
 
     /**
      * @tests java.io.PipedReader#PipedReader(java.io.PipedWriter)
      */
     public void test_ConstructorLjava_io_PipedWriter() throws IOException {
-        // Test for method java.io.PipedReader(java.io.PipedWriter)
         preader = new PipedReader(new PipedWriter());
     }
     
@@ -121,7 +121,6 @@
      * @tests java.io.PipedReader#close()
      */
     public void test_close() throws Exception {
-        // Test for method void java.io.PipedReader.close()
         char[] c = null;
         preader = new PipedReader();
         t = new Thread(new PWriter(preader), "");
@@ -137,7 +136,6 @@
      * @tests java.io.PipedReader#connect(java.io.PipedWriter)
      */
     public void test_connectLjava_io_PipedWriter() throws Exception {
-        // Test for method void java.io.PipedReader.connect(java.io.PipedWriter)
         char[] c = null;
 
         preader = new PipedReader();
@@ -152,16 +150,15 @@
         try {
             preader.connect(pwriter.pw);
             fail("Failed to throw exception connecting to pre-connected reader");
-        } catch (Exception e) {
-            // Correct
+        } catch (IOException e) {
+            // Expected
         }
     }
 
-	/**
-	 * @tests java.io.PipedReader#read()
-	 */
-	public void test_read() throws Exception {
-        // Test for method int java.io.PipedReader.read()
+    /**
+     * @tests java.io.PipedReader#read()
+     */
+    public void test_read() throws Exception {
         char[] c = null;
         preader = new PipedReader();
         t = new Thread(new PWriter(preader), "");
@@ -174,11 +171,10 @@
         assertEquals("Read incorrect chars", "Hello World", new String(c));
     }
 
-	/**
-	 * @tests java.io.PipedReader#read(char[], int, int)
-	 */
-	public void test_read$CII() throws Exception {
-        // Test for method int java.io.PipedReader.read(char [], int, int)
+    /**
+     * @tests java.io.PipedReader#read(char[], int, int)
+     */
+    public void test_read$CII() throws Exception {
         char[] c = null;
         preader = new PipedReader();
         t = new Thread(new PWriter(preader), "");
@@ -196,16 +192,16 @@
             preader.close();
             preader.read(c, 8, 7);
             fail("Failed to throw exception reading from closed reader");
-        } catch (Exception e) {
-            // Correct
+        } catch (IOException e) {
+            // Expected
         }
     }
 
     /**
      * @tests java.io.PipedReader#read(char[], int, int)
-     * Regression for HARMONY-387
      */
-    public void test_read$CII_2() throws IOException{
+    public void test_read$CII_2() throws IOException {
+        // Regression for HARMONY-387
         PipedWriter pw = new PipedWriter();
         PipedReader obj = null;
         try {
@@ -232,6 +228,7 @@
         } catch (ArrayIndexOutOfBoundsException t) {
             fail("IndexOutOfBoundsException expected");
         } catch (IndexOutOfBoundsException t) {
+            // Expected
         }
     }
 
@@ -248,9 +245,10 @@
         } catch (ArrayIndexOutOfBoundsException t) {
             fail("IndexOutOfBoundsException expected");
         } catch (IndexOutOfBoundsException t) {
+            // Expected
         }
     }
-    
+
     /**
      * @tests java.io.PipedReader#read(char[], int, int)
      */
@@ -268,7 +266,7 @@
             pw = null;
             pr = null;
         }
-        
+
         pr = new PipedReader();
         buf = null;
         pr.close();
@@ -280,7 +278,7 @@
         } finally {
             pr = null;
         }
-        
+
         pw = new PipedWriter();
         pr = new PipedReader(pw);
         buf = new char[10];
@@ -294,7 +292,7 @@
             pw = null;
             pr = null;
         }
-        
+
         pw = new PipedWriter();
         pr = new PipedReader(pw);
         buf = new char[10];
@@ -308,7 +306,7 @@
             pw = null;
             pr = null;
         }
-        
+
         pw = new PipedWriter();
         pr = new PipedReader(pw);
         buf = new char[10];
@@ -322,7 +320,7 @@
             pw = null;
             pr = null;
         }
-        
+
         pw = new PipedWriter();
         pr = new PipedReader(pw);
         pr.close();
@@ -335,7 +333,7 @@
             pw = null;
             pr = null;
         }
-        
+
         pw = new PipedWriter();
         pr = new PipedReader(pw);
         pr.close();
@@ -348,7 +346,7 @@
             pw = null;
             pr = null;
         }
-        
+
         pw = new PipedWriter();
         pr = new PipedReader(pw);
         try {
@@ -360,7 +358,7 @@
             pw = null;
             pr = null;
         }
-        
+
         pw = new PipedWriter();
         pr = new PipedReader(pw);
         try {
@@ -372,7 +370,7 @@
             pw = null;
             pr = null;
         }
-        
+
         pw = new PipedWriter();
         pr = new PipedReader(pw);
         try {
@@ -384,7 +382,7 @@
             pw = null;
             pr = null;
         }
-        
+
         pw = new PipedWriter();
         pr = new PipedReader(pw);
         try {
@@ -399,10 +397,9 @@
     }
 
     /**
-	 * @tests java.io.PipedReader#ready()
-	 */
-	public void test_ready() throws Exception {
-        // Test for method boolean java.io.PipedReader.ready()
+     * @tests java.io.PipedReader#ready()
+     */
+    public void test_ready() throws Exception {
         char[] c = null;
         preader = new PipedReader();
         t = new Thread(new PWriter(preader), "");
@@ -416,14 +413,14 @@
                 preader.ready());
     }
 
-	/**
-	 * Tears down the fixture, for example, close a network connection. This
-	 * method is called after a test is executed.
-	 */
-	protected void tearDown() throws Exception {
-		if (t != null) {
-			t.interrupt();
+    /**
+     * Tears down the fixture, for example, close a network connection. This
+     * method is called after a test is executed.
+     */
+    protected void tearDown() throws Exception {
+        if (t != null) {
+            t.interrupt();
         }
         super.tearDown();
-	}
+    }
 }



Mime
View raw message