Apply patch for HARMONY-6430: [test] Improve the method coverage rate of unit test for javax.sql


git-svn-id: https://svn.apache.org/repos/asf/harmony/enhanced/classlib/trunk@901560 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/AbstractRowSetImplTest.java b/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/AbstractRowSetImplTest.java
new file mode 100644
index 0000000..33fbef9
--- /dev/null
+++ b/modules/sql/src/test/java/org/apache/harmony/sql/tests/internal/rowset/AbstractRowSetImplTest.java
@@ -0,0 +1,608 @@
+/* 
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.sql.tests.internal.rowset;
+
+import java.io.ByteArrayInputStream;
+import java.io.CharArrayReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Reader;
+import java.math.BigDecimal;
+import java.sql.Date;
+import java.sql.SQLException;
+import java.sql.Time;
+import java.sql.Timestamp;
+import java.sql.Types;
+import java.util.Calendar;
+import java.util.Locale;
+
+import javax.sql.RowSetEvent;
+import javax.sql.RowSetListener;
+
+import org.apache.harmony.sql.internal.rowset.AbstractRowSetImpl;
+
+import junit.framework.TestCase;
+
+public class AbstractRowSetImplTest extends TestCase {
+    private AbstractRowSetImpl rowset;
+
+    private Object[] params;
+
+    public void setUp() {
+        rowset = new AbstractRowSetImpl();
+    }
+
+    public void tearDown() {
+        rowset = null;
+    }
+
+    private class MockRowSetListener implements RowSetListener {
+        boolean cursorMoved;
+
+        boolean rowChanged;
+
+        boolean rowsetChanged;
+
+        public void cursorMoved(RowSetEvent theEvent) {
+            cursorMoved = cursorMoved ? false : true;
+
+        }
+
+        public void rowChanged(RowSetEvent theEvent) {
+            rowChanged = rowChanged ? false : true;
+        }
+
+        public void rowSetChanged(RowSetEvent theEvent) {
+            rowsetChanged = rowsetChanged ? false : true;
+        }
+
+    }
+
+    /**
+     * @add tests
+     *      {@link javax.sql.rowset.BaseRowSet#addRowSetListener(javax.sql.RowSetListener)}
+     * @add tests
+     *      {@link javax.sql.rowset.BaseRowSet#removeRowSetListener(RowSetListener)}
+     */
+    public void test_addRowSetListener_Ljavax_sql_RowsetListener()
+            throws SQLException {
+        final class MockAbstractRowSetImpl extends AbstractRowSetImpl {
+
+            /**
+             * 
+             */
+            private static final long serialVersionUID = 1L;
+
+            protected void notifyCursorMoved() throws SQLException {
+                super.notifyCursorMoved();
+            }
+
+            protected void notifyRowChanged() throws SQLException {
+                super.notifyRowChanged();
+            }
+
+            protected void notifyRowSetChanged() throws SQLException {
+                super.notifyRowSetChanged();
+            }
+
+        }
+        MockRowSetListener listener = new MockRowSetListener();
+        MockAbstractRowSetImpl rowset = new MockAbstractRowSetImpl();
+        rowset.addRowSetListener(listener);
+        assertFalse(listener.cursorMoved);
+        assertFalse(listener.rowChanged);
+        assertFalse(listener.rowsetChanged);
+        rowset.notifyCursorMoved();
+        assertTrue(listener.cursorMoved);
+        rowset.notifyRowChanged();
+        assertTrue(listener.rowChanged);
+        rowset.notifyRowSetChanged();
+        assertTrue(listener.rowsetChanged);
+
+        // this call won't make any effect
+        rowset.removeRowSetListener(null);
+        rowset.notifyCursorMoved();
+        rowset.notifyRowChanged();
+        rowset.notifyRowSetChanged();
+        assertFalse(listener.cursorMoved);
+        assertFalse(listener.rowChanged);
+        assertFalse(listener.rowsetChanged);
+
+        // this call will remove the registered listener
+        rowset.removeRowSetListener(listener);
+        rowset.notifyCursorMoved();
+        rowset.notifyRowChanged();
+        rowset.notifyRowSetChanged();
+        assertFalse(listener.cursorMoved);
+        assertFalse(listener.rowChanged);
+        assertFalse(listener.rowsetChanged);
+    }
+
+    /**
+     *@add tests {@link javax.sql.rowset.BaseRowSet#getUsername()}.
+     */
+    public void test_getUsername() {
+        assertNull("username should init as null", rowset.getUsername());
+    }
+
+    /**
+     * @add tests {@link javax.sql.rowset.BaseRowSet#getPassword()}.
+     */
+    public void test_getPassword() {
+        assertNull("password should init as null", rowset.getPassword());
+    }
+
+    /**
+     * Test method for {@link javax.sql.rowset.BaseRowSet#setInt(int, int)}.
+     */
+    public void test_setInt_II() throws SQLException {
+        try {
+            rowset.setInt(0, 0);
+            fail("should throw SQLException");
+        } catch (SQLException sqlE) {
+            // expected
+        }
+        rowset.setInt(1, 1);
+        params = rowset.getParams();
+        assertEquals("set int failure", 1, ((Integer) params[0]).intValue());
+
+    }
+
+    /**
+     * Test method for {@link javax.sql.rowset.BaseRowSet#setLong(int, long)}.
+     */
+    public void test_setLong_IJ() throws SQLException {
+        try {
+            rowset.setLong(0, 0L);
+            fail("should throw SQLException");
+        } catch (SQLException ex) {
+            // expected
+        }
+        rowset.setLong(1, 1000000L);
+        params = rowset.getParams();
+        assertEquals("set long failure", 1000000L, ((Long) params[0])
+                .longValue());
+    }
+
+    /**
+     * Test method for {@link javax.sql.rowset.BaseRowSet#setFloat(int, float)}.
+     */
+    public void test_setFloat_IF() throws SQLException {
+        try {
+            rowset.setFloat(0, 0f);
+            fail("should throw SQLException");
+        } catch (SQLException e) {
+            // expected
+        }
+        rowset.setFloat(1, 0.5f);
+        params = rowset.getParams();
+        assertEquals("set float failure", 0.5f, ((Float) params[0])
+                .floatValue());
+    }
+
+    /**
+     * Test method for
+     * {@link javax.sql.rowset.BaseRowSet#setDouble(int, double)}.
+     * 
+     * @throws SQLException
+     */
+    public void test_setDouble_ID() throws SQLException {
+        try {
+            rowset.setDouble(0, 0);
+            fail("should throw SQLException");
+        } catch (SQLException e) {
+            // expected
+        }
+        rowset.setDouble(1, 1.5);
+        params = rowset.getParams();
+        assertEquals("set double failure", 1.5, ((Double) params[0])
+                .doubleValue());
+    }
+
+    /**
+     * Test method for
+     * {@link javax.sql.rowset.BaseRowSet#setBigDecimal(int, java.math.BigDecimal)}
+     * 
+     * @throws SQLException
+     */
+    public void test_setBigDecimal_ILjava_math_Bigdecimal() throws SQLException {
+        BigDecimal decimal = new BigDecimal(1000);
+        try {
+            rowset.setBigDecimal(0, decimal);
+            fail("should throw SQLException");
+        } catch (SQLException e) {
+            // expected
+        }
+        rowset.setBigDecimal(1, decimal);
+        params = rowset.getParams();
+        assertEquals("set big decimal failure", decimal, (BigDecimal) params[0]);
+    }
+
+    /**
+     * Test method for {@link javax.sql.rowset.BaseRowSet#setBytes(int, byte[])}
+     * 
+     * @throws SQLException
+     */
+    public void test_setBytes_IB() throws SQLException {
+        try {
+            rowset.setBytes(0, null);
+        } catch (SQLException e) {
+            // expected
+        }
+        byte[] bytes = new byte[] { (byte) 1, (byte) 2 };
+        rowset.setBytes(1, bytes);
+        params = rowset.getParams();
+        assertEquals("set bytes failure", bytes, ((byte[]) params[0]));
+    }
+
+    /**
+     * Test method for
+     * {@link javax.sql.rowset.BaseRowSet#setDate(int, java.sql.Date)}.
+     * 
+     * @throws SQLException
+     */
+    public void test_setDate_ILjava_sql_Date() throws SQLException {
+        Date date = new Date(100000000000L);
+        try {
+            rowset.setDate(0, date);
+            fail("should throw SQLException");
+        } catch (SQLException e) {
+            // expected
+        }
+        rowset.setDate(1, date);
+        params = rowset.getParams();
+        assertEquals("setDate(int,Date) failure", date, (Date) params[0]);
+    }
+
+    /**
+     * Test method for
+     * {@link javax.sql.rowset.BaseRowSet#setTime(int, java.sql.Time)}.
+     * 
+     * @throws SQLException
+     */
+    public void test_setTime_ILjava_sql_Time() throws SQLException {
+        Time time = new Time(1000000000L);
+        try {
+            rowset.setTime(0, time);
+            fail("should throw SQLException");
+        } catch (SQLException e) {
+            // expected
+        }
+        rowset.setTime(1, time);
+        params = rowset.getParams();
+        assertEquals("setTime(int,Time) failure", time, (Time) params[0]);
+    }
+
+    /**
+     * Test method for
+     * {@link javax.sql.rowset.BaseRowSet#setTimestamp(int, java.sql.Timestamp)}
+     * 
+     * @throws SQLException
+     */
+    public void test_setTimestamp_ILjava_sql_Timestamp() throws SQLException {
+        Timestamp stamp = new Timestamp(10000000000L);
+        try {
+            rowset.setTimestamp(0, stamp);
+            fail("should throw SQLException");
+        } catch (SQLException e) {
+            // expected
+        }
+        rowset.setTimestamp(1, stamp);
+        params = rowset.getParams();
+        assertEquals("setTimeStamp(int,Timestamp) failure", stamp,
+                (Timestamp) params[0]);
+    }
+
+    /**
+     * Test method for
+     * {@link javax.sql.rowset.BaseRowSet#setAsciiStream(int, java.io.InputStream, int)}
+     * 
+     * @throws SQLException
+     * @throws IOException
+     */
+    public void test_setAsciiStream_ILjava_io_InputStreamI()
+            throws SQLException, IOException {
+        InputStream in = new ByteArrayInputStream(new byte[] { (byte) 1,
+                (byte) 10 });
+        try {
+            rowset.setAsciiStream(0, null, 0);
+            fail("should throw SQLException");
+        } catch (SQLException e) {
+            // expected
+        }
+        try {
+            rowset.setAsciiStream(0, in, 0);
+            fail("should throw SQLException");
+        } catch (SQLException e) {
+            // expected
+        }
+        rowset.setAsciiStream(1, in, 2);
+        params = rowset.getParams();
+        Object[] array = (Object[]) params[0];
+        assertEquals("first element in params " + array[0]
+                + " did not equal to Inputstream", in, (InputStream) array[0]);
+        in.close();
+        assertEquals("second element in params " + array[1]
+                + " did not equal to 2", 2, array[1]);
+    }
+
+    /**
+     * Test method for
+     * {@link javax.sql.rowset.BaseRowSet#setBinaryStream(int, java.io.InputStream, int)}
+     * 
+     * @throws SQLException
+     * @throws IOException
+     */
+    public void test_setBinaryStream_ILjava_io_InputStreamI()
+            throws SQLException, IOException {
+        InputStream in = new ByteArrayInputStream(new byte[] { (byte) 1,
+                (byte) 10 });
+        try {
+            rowset.setBinaryStream(0, null, 0);
+            fail("should throw SQLException");
+        } catch (SQLException e) {
+            // expected
+        }
+        try {
+            rowset.setBinaryStream(0, in, 0);
+            fail("should throw SQLException");
+        } catch (SQLException e) {
+            // expected
+        }
+        rowset.setBinaryStream(1, in, 2);
+        params = rowset.getParams();
+        Object[] array = (Object[]) params[0];
+        assertEquals("first element in params " + array[0]
+                + " did not equal to Inputstream", in, (InputStream) array[0]);
+        in.close();
+        assertEquals("second element in params " + array[1]
+                + " did not equal to 2", 2, array[1]);
+    }
+
+    /**
+     * Test method for
+     * {@link javax.sql.rowset.BaseRowSet#setUnicodeStream(int, java.io.InputStream, int)}
+     * 
+     * @throws SQLException
+     */
+    @SuppressWarnings("deprecation")
+    public void test_setUnicodeStream_ILjava_io_InputStreamI()
+            throws SQLException {
+        InputStream in = new ByteArrayInputStream(new byte[] { (byte) 1,
+                (byte) 10 });
+        try {
+            rowset.setUnicodeStream(0, null, 0);
+            fail("should throw SQLException");
+        } catch (SQLException e) {
+            // expected
+        }
+        try {
+            rowset.setUnicodeStream(0, in, 0);
+            fail("should throw SQLException");
+        } catch (SQLException e) {
+            // expected
+        }
+        rowset.setUnicodeStream(1, in, 2);
+        params = rowset.getParams();
+        Object[] array = (Object[]) params[0];
+        assertEquals("first element in params " + array[0]
+                + " did not equal to Inputstream", in, (InputStream) array[0]);
+        assertEquals("second element in params " + array[1]
+                + " did not equal to 2", 2, array[1]);
+    }
+
+    /**
+     * Test method for
+     * {@link javax.sql.rowset.BaseRowSet#setCharacterStream(int, java.io.Reader, int)}
+     * 
+     * @throws SQLException
+     */
+    public void test_setCharacterStream_ILjava_io_ReaderI() throws SQLException {
+        Reader reader = new CharArrayReader(new char[] { 'a', 'b' });
+        try {
+            rowset.setCharacterStream(0, null, 0);
+            fail("should throw SQLException");
+        } catch (SQLException e) {
+            // expected
+        }
+        try {
+            rowset.setCharacterStream(0, reader, 0);
+            fail("should throw SQLException");
+        } catch (SQLException e) {
+            // expected
+        }
+        rowset.setCharacterStream(1, reader, 2);
+        // rowset.getCharacterStream(1);
+        params = rowset.getParams();
+        Object[] array = (Object[]) params[0];
+        assertEquals("first element in params " + array[0]
+                + " did not equal to Inputstream", reader, (Reader) array[0]);
+        assertEquals("second element in params " + array[1]
+                + " did not equal to 2", 2, array[1]);
+    }
+
+    /**
+     * Test method for
+     * {@link javax.sql.rowset.BaseRowSet#setObject(int, java.lang.Object, int, int)}
+     * 
+     * @throws SQLException
+     */
+    public void test_setObject_ILjava_lang_ObjectII() throws SQLException {
+        try {
+            rowset.setObject(0, null, 0, 0);
+            fail("should throw SQLExceptions");
+        } catch (SQLException e) {
+            // expected
+        }
+        rowset.setObject(1, null, 0, 0);// should pass
+        rowset.setObject(2, new Float(0.55f), Types.NUMERIC, 0);// should pass
+        rowset.setObject(3, new Double(100.0003), Types.DECIMAL, 4);
+        params = rowset.getParams();
+        Object[] array1 = (Object[]) params[0];
+        assertNull(array1[0]);
+        Object[] array2 = (Object[]) params[1];
+        assertEquals(0.55f, ((Float) array2[0]).floatValue());
+        assertEquals(Types.NUMERIC, array2[1]);
+        Object[] array3 = (Object[]) params[2];
+        assertEquals(100.0003, ((Double) array3[0]).doubleValue());
+        assertEquals(Types.DECIMAL, array3[1]);
+        assertEquals(4, array3[2]);
+    }
+
+    /**
+     * Test method for
+     * {@link javax.sql.rowset.BaseRowSet#setObject(int, java.lang.Object, int)}
+     * 
+     * @throws SQLException
+     */
+    public void test_setObject_ILjava_lang_ObjectI() throws SQLException {
+        try {
+            rowset.setObject(0, null, 0);
+            fail("should throw SQLException");
+        } catch (SQLException e) {
+            // expected
+        }
+        rowset.setObject(1, null, 0);// should pass
+        rowset.setObject(1, new Integer(10), Types.VARCHAR);// should pass
+        rowset.setObject(1, new Integer(10), Types.INTEGER);
+        params = rowset.getParams();
+        Object[] array = (Object[]) params[0];
+        assertEquals(10, ((Integer) array[0]).intValue());
+        assertEquals(Types.INTEGER, array[1]);
+    }
+
+    /**
+     * Test method for
+     * {@link javax.sql.rowset.BaseRowSet#setObject(int, java.lang.Object)}.
+     * 
+     * @throws SQLException
+     */
+    public void test_setObject_IntLjava_lang_Object() throws SQLException {
+        try {
+            rowset.setObject(0, null);
+            fail("should throw SQLException");
+        } catch (SQLException e) {
+            // expected
+        }
+        rowset.setObject(1, new String("test"));
+        params = rowset.getParams();
+        assertEquals("test", (String) params[0]);
+    }
+
+    /**
+     * Test method for
+     * {@link javax.sql.rowset.BaseRowSet#setTime(int, java.sql.Time, java.util.Calendar)}
+     * 
+     * @throws SQLException
+     */
+    public void test_setTime_ILjava_sql_TimeLjava_util_Calendar()
+            throws SQLException {
+        try {
+            rowset.setTimestamp(0, null, null);
+            fail("should throw SQLException");
+        } catch (SQLException e) {
+            // expected
+        }
+        rowset.setTime(1, null, null);// should pass
+        Time t = new Time(100000L);
+        Calendar cal = Calendar.getInstance(Locale.CHINA);
+        rowset.setTime(2, t, cal);
+        params = rowset.getParams();
+        Object[] array1 = (Object[]) params[0];
+        assertNull(array1[0]);
+        assertNull(array1[1]);
+        Object[] array2 = (Object[]) params[1];
+        assertEquals(t, array2[0]);
+        assertEquals(cal, array2[1]);
+    }
+
+    /**
+     * Test method for
+     * {@link javax.sql.rowset.BaseRowSet#setTimestamp(int, java.sql.Timestamp, java.util.Calendar)}
+     * 
+     * @throws SQLException
+     */
+    public void test_setTimestamp_ILjava_sql_TimestampLjava_util_Calendar()
+            throws SQLException {
+        try {
+            rowset.setTimestamp(0, null, null);
+            fail("should throw SQLException");
+        } catch (SQLException e) {
+            // expected
+        }
+        Timestamp ts = new Timestamp(1000000000000000L);
+        Calendar cal = Calendar.getInstance(Locale.CHINA);
+        rowset.setTimestamp(1, null, null);
+        rowset.setTimestamp(2, ts, cal);
+        params = rowset.getParams();
+        Object[] array1 = (Object[]) params[0];
+        Object[] array2 = (Object[]) params[1];
+        assertNull(array1[0]);
+        assertNull(array1[1]);
+        assertEquals(ts, array2[0]);
+        assertEquals(cal, array2[1]);
+    }
+
+    /**
+     * @throws SQLException
+     * @add tests
+     *      {@link javax.sql.rowset.BaseRowSet#setDate(int, Date, Calendar)}
+     */
+    public void test_setDate_ILjava_sql_DateLjava_util_Calendar()
+            throws SQLException {
+        try {
+            rowset.setDate(0, null, null);
+            fail("should throw SQLException");
+        } catch (SQLException e) {
+            // expected
+        }
+        Date date = new Date(10000000000L);
+        Calendar cal = Calendar.getInstance(Locale.CHINA);
+        rowset.setDate(1, null, null);
+        rowset.setDate(2, null, cal);
+        rowset.setDate(3, date, null);
+        rowset.setDate(4, date, cal);
+        params = rowset.getParams();
+        Object[] array1 = (Object[]) params[0];
+        Object[] array2 = (Object[]) params[1];
+        Object[] array3 = (Object[]) params[2];
+        Object[] array4 = (Object[]) params[3];
+        assertNull(array1[0]);
+        assertNull(array1[1]);
+        assertNull(array2[0]);
+        assertEquals(cal, array2[1]);
+        assertEquals(date, array3[0]);
+        assertNull(array3[1]);
+        assertEquals(date, array4[0]);
+        assertEquals(cal, array4[1]);
+    }
+
+    /**
+     * @throws SQLException
+     * @add tests {@link javax.sql.rowset.BaseRowSet#setQueryTimeout(int)}
+     */
+    public void test_setQueryTimeOut_I() throws SQLException {
+        try {
+            rowset.setQueryTimeout(-1);
+        } catch (SQLException e) {
+            // expected
+        }
+        rowset.setQueryTimeout(10);
+        assertEquals(10, rowset.getQueryTimeout());
+    }
+
+}
diff --git a/modules/sql/src/test/java/org/apache/harmony/sql/tests/javax/sql/rowset/BaseRowSetTest.java b/modules/sql/src/test/java/org/apache/harmony/sql/tests/javax/sql/rowset/BaseRowSetTest.java
index 64997fc..5a035b4 100644
--- a/modules/sql/src/test/java/org/apache/harmony/sql/tests/javax/sql/rowset/BaseRowSetTest.java
+++ b/modules/sql/src/test/java/org/apache/harmony/sql/tests/javax/sql/rowset/BaseRowSetTest.java
@@ -296,6 +296,12 @@
         assertEquals(0, baseRowSet.getMaxRows());
         baseRowSet.setFetchSize(3);
         assertEquals("The fetch size should be set to 3.", 3, baseRowSet.getFetchSize());
+        try {
+            baseRowSet.setFetchSize(-1);
+            fail("should throw SQLException");
+        } catch (SQLException e) {
+            // expected
+        }
     }
     
     private static final class BaseRowSetImpl extends BaseRowSet {
diff --git a/modules/sql/src/test/java/org/apache/harmony/sql/tests/javax/sql/rowset/RowSetWarningTest.java b/modules/sql/src/test/java/org/apache/harmony/sql/tests/javax/sql/rowset/RowSetWarningTest.java
new file mode 100644
index 0000000..5a026a0
--- /dev/null
+++ b/modules/sql/src/test/java/org/apache/harmony/sql/tests/javax/sql/rowset/RowSetWarningTest.java
@@ -0,0 +1,78 @@
+/* 
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.sql.tests.javax.sql.rowset;
+
+import javax.sql.rowset.RowSetWarning;
+
+import junit.framework.TestCase;
+
+public class RowSetWarningTest extends TestCase {
+
+    /**
+     * Test method for {@link javax.sql.rowset.RowSetWarning#RowSetWarning()}.
+     */
+
+    public void test_constructor() {
+        RowSetWarning warn = new RowSetWarning();
+        assertNull(warn.getMessage());
+    }
+
+    /**
+     * Test method for
+     * {@link javax.sql.rowset.RowSetWarning#RowSetWarning(java.lang.String)}.
+     */
+
+    public void test_constructor_Ljava_lang_String() {
+        RowSetWarning war = new RowSetWarning("test");
+        assertEquals("test", war.getMessage());
+    }
+
+    /**
+     * Test method for
+     * {@link javax.sql.rowset.RowSetWarning#RowSetWarning(java.lang.String, java.lang.String)}
+     */
+
+    public void test_constructor_Ljava_lang_StringLjava_lang_String() {
+        RowSetWarning warn = new RowSetWarning("test", "testState");
+        assertEquals("test", warn.getMessage());
+        assertEquals("testState", warn.getSQLState());
+    }
+
+    /**
+     * Test method for
+     * {@link javax.sql.rowset.RowSetWarning#RowSetWarning(java.lang.String, java.lang.String, int)}
+     */
+
+    public void test_constructor_Ljava_lang_StringLjava_lang_StringI() {
+        RowSetWarning warn = new RowSetWarning("test", "testState", 0);
+        assertEquals("test", warn.getMessage());
+        assertEquals("testState", warn.getSQLState());
+        assertEquals(0, warn.getErrorCode());
+    }
+
+    /**
+     * Test method for {@link javax.sql.rowset.RowSetWarning#getNextWarning()}.
+     * {@link javax.sql.rowset.RowSetWarning#setNextWarning(javax.sql.rowset.RowSetWarning)}
+     */
+
+    public void test_set_getNextWarning() {
+        RowSetWarning warn = new RowSetWarning();
+        warn.setNextWarning(new RowSetWarning("test"));
+        assertEquals("test", warn.getNextWarning().getMessage());
+    }
+
+}
diff --git a/modules/sql/src/test/java/org/apache/harmony/sql/tests/javax/sql/rowset/spi/SyncFactoryExceptionTest.java b/modules/sql/src/test/java/org/apache/harmony/sql/tests/javax/sql/rowset/spi/SyncFactoryExceptionTest.java
new file mode 100644
index 0000000..63727d1
--- /dev/null
+++ b/modules/sql/src/test/java/org/apache/harmony/sql/tests/javax/sql/rowset/spi/SyncFactoryExceptionTest.java
@@ -0,0 +1,45 @@
+/* 
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.sql.tests.javax.sql.rowset.spi;
+
+import javax.sql.rowset.spi.SyncFactoryException;
+
+import junit.framework.TestCase;
+
+public class SyncFactoryExceptionTest extends TestCase {
+
+    /**
+     * Test method for
+     * {@link javax.sql.rowset.spi.SyncFactoryException#SyncFactoryException()}.
+     */
+    public void testSyncFactoryException() {
+        SyncFactoryException ex = new SyncFactoryException();
+        assertNull(ex.getMessage());
+    }
+
+    /**
+     * Test method for
+     * {@link javax.sql.rowset.spi.SyncFactoryException#SyncFactoryException(java.lang.String)}
+     */
+    public void testSyncFactoryExceptionString() {
+        SyncFactoryException ex = new SyncFactoryException("test");
+        assertEquals("test", ex.getMessage());
+        ex = new SyncFactoryException(null);
+        assertNull(ex.getMessage());
+    }
+
+}
diff --git a/modules/sql/src/test/java/org/apache/harmony/sql/tests/javax/sql/rowset/spi/SyncFactoryTest.java b/modules/sql/src/test/java/org/apache/harmony/sql/tests/javax/sql/rowset/spi/SyncFactoryTest.java
new file mode 100644
index 0000000..7e8848a
--- /dev/null
+++ b/modules/sql/src/test/java/org/apache/harmony/sql/tests/javax/sql/rowset/spi/SyncFactoryTest.java
@@ -0,0 +1,188 @@
+/* 
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.sql.tests.javax.sql.rowset.spi;
+
+import java.util.Enumeration;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+import javax.sql.rowset.spi.SyncFactory;
+import javax.sql.rowset.spi.SyncFactoryException;
+import javax.sql.rowset.spi.SyncProvider;
+
+import junit.framework.TestCase;
+
+public class SyncFactoryTest extends TestCase {
+
+    /**
+     * Test method for
+     * {@link javax.sql.rowset.spi.SyncFactory#registerProvider(java.lang.String)}
+     * and
+     * {@link javax.sql.rowset.spi.SyncFactory#unregisterProvider(java.lang.String)}
+     * 
+     * @throws SyncFactoryException
+     */
+    public void test_registerProvider_Ljava_lang_String()
+            throws SyncFactoryException {
+        final String proID = "org.apache.harmony.sql.tests.TestProvider";
+        SyncFactory.registerProvider(proID);
+        Enumeration<SyncProvider> providers = SyncFactory
+                .getRegisteredProviders();
+        boolean ifContains = false;
+        while (providers.hasMoreElements()) {
+            if (providers.nextElement().getProviderID().equals(proID)) {
+                ifContains = true;
+                break;
+            }
+        }
+        assertTrue("register provider error", ifContains);
+        SyncFactory.unregisterProvider(proID);
+        providers = SyncFactory.getRegisteredProviders();
+        ifContains = false;
+        while (providers.hasMoreElements()) {
+            if (providers.nextElement().getProviderID().equals(proID)) {
+                ifContains = true;
+                break;
+            }
+        }
+        assertFalse("unregister provider error", ifContains);
+        try {
+            SyncFactory.registerProvider(null);
+            fail("should throw SyncFactoryException");
+        } catch (SyncFactoryException e) {
+            // expected
+        }
+        try {
+            SyncFactory.registerProvider("");
+            fail("should throw SyncFactoryException");
+        } catch (SyncFactoryException e) {
+            // expected
+        }
+        try {
+            SyncFactory.unregisterProvider("test");
+            fail("should throw SyncFactoryException");
+        } catch (SyncFactoryException e) {
+            // expected
+        }
+        try {
+            SyncFactory.unregisterProvider(null);
+            fail("should throw NullPointerException");
+        } catch (NullPointerException e) {
+            // expected
+        }
+
+    }
+
+    /**
+     * Test method for {@link javax.sql.rowset.spi.SyncFactory#getSyncFactory()}
+     */
+    public void test_getSyncFactory() {
+        SyncFactory fac1 = SyncFactory.getSyncFactory();
+        SyncFactory fac2 = SyncFactory.getSyncFactory();
+        assertSame("SyncFactory instance should be Singleton", fac1, fac2);
+    }
+
+    /**
+     * Test method for
+     * {@link javax.sql.rowset.spi.SyncFactory#getInstance(java.lang.String)}.
+     * 
+     * @throws SyncFactoryException
+     */
+    public void test_getInstance_Ljava_lang_String()
+            throws SyncFactoryException {
+        Enumeration<SyncProvider> providers = SyncFactory
+                .getRegisteredProviders();
+        SyncProvider expected = providers.nextElement();
+        String id = expected.getProviderID();
+        SyncProvider provider = SyncFactory.getInstance(id);
+        assertEquals("getInstance error", expected.getVersion(), provider
+                .getVersion());
+        provider = SyncFactory.getInstance("nonExist");// should return default
+        assertNotNull(provider);
+        try {
+            provider = SyncFactory.getInstance(null);
+            fail("should throw NullPointerException");
+        } catch (NullPointerException e) {
+            // expected
+        }
+    }
+
+    /**
+     * Test method for
+     * {@link javax.sql.rowset.spi.SyncFactory#setLogger(java.util.logging.Logger)}
+     * {@link javax.sql.rowset.spi.SyncFactory#getLogger()} .
+     * 
+     * @throws SyncFactoryException
+     */
+    public void test_setLogger_Ljava_util_logging_Logger()
+            throws SyncFactoryException {
+        Logger logger = Logger.getAnonymousLogger();
+        SyncFactory.setLogger(logger);
+        assertEquals(logger, SyncFactory.getLogger());
+        SyncFactory.setLogger(null);
+        try {
+            SyncFactory.getLogger();
+            fail("should throw SyncFactoryException");
+        } catch (SyncFactoryException e) {
+            // expected
+        }
+    }
+
+    /**
+     * Test method for
+     * {@link javax.sql.rowset.spi.SyncFactory#setLogger(java.util.logging.Logger, java.util.logging.Level)}
+     *
+     * @throws SyncFactoryException
+     */
+    public void test_setLogger_Ljava_util_logging_LoggerLjava_util_logging_Level()
+            throws SyncFactoryException {
+        Logger logger = Logger.getAnonymousLogger();
+        Level level = Level.parse("WARNING");
+        SyncFactory.setLogger(logger, level);
+        Logger actual = SyncFactory.getLogger();
+        assertEquals("set logger or get logger error", logger, actual);
+        assertEquals("set logger error in set level", level, logger.getLevel());
+        try {
+            SyncFactory.setLogger(null, level);
+            fail("should throw NullPointerException");
+        } catch (NullPointerException e) {
+            // expected
+        }
+        SyncFactory.setLogger(logger, null);
+        assertNull(SyncFactory.getLogger().getLevel());
+    }
+
+    /**
+     * Test method for
+     * {@link javax.sql.rowset.spi.SyncFactory#setJNDIContext(javax.naming.Context)}
+     * 
+     * @throws NamingException
+     * @throws SyncFactoryException
+     */
+    public void test_setJNDIContext_Ljavax_naming_Context()
+            throws NamingException, SyncFactoryException {
+        try {
+            SyncFactory.setJNDIContext(null);
+            fail("Should throw SyncFactoryException");
+        } catch (SyncFactoryException e) {
+            // expected
+        }
+        SyncFactory.setJNDIContext(new InitialContext());
+    }
+}
diff --git a/modules/sql/src/test/java/org/apache/harmony/sql/tests/javax/sql/rowset/spi/SyncProviderExceptionTest.java b/modules/sql/src/test/java/org/apache/harmony/sql/tests/javax/sql/rowset/spi/SyncProviderExceptionTest.java
new file mode 100644
index 0000000..2f9daae
--- /dev/null
+++ b/modules/sql/src/test/java/org/apache/harmony/sql/tests/javax/sql/rowset/spi/SyncProviderExceptionTest.java
@@ -0,0 +1,71 @@
+/* 
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.sql.tests.javax.sql.rowset.spi;
+
+import javax.sql.rowset.spi.SyncProviderException;
+import javax.sql.rowset.spi.SyncResolver;
+
+import junit.framework.TestCase;
+
+public class SyncProviderExceptionTest extends TestCase {
+
+    /**
+     * @add tests
+     *      {@link javax.sql.rowset.spi.SyncProviderException#SyncProviderException()}
+     * @add tests
+     *      {@link javax.sql.rowset.spi.SyncProviderException#SyncProviderException(String)}
+     */
+    public void test_constructor() {
+        SyncProviderException ex = new SyncProviderException();
+        assertNull(ex.getMessage());
+        ex = new SyncProviderException("test");
+        assertEquals("test", ex.getMessage());
+        ex = new SyncProviderException((String) null);
+        assertNull(ex.getMessage());
+    }
+
+    /**
+     * @add tests
+     *      {@link javax.sql.rowset.spi.SyncProviderException#SyncProviderException(javax.sql.rowset.spi.SyncResolver)}
+     */
+    public void test_constructor_Ljavax_sql_rowset_spi_SyncResolver() {
+        try {
+            new SyncProviderException((SyncResolver) null);
+            fail("should throw IllegalArgumentException");
+        } catch (IllegalArgumentException e) {
+            // expected
+        }
+    }
+
+    /**
+     * @add tests
+     *      {@link javax.sql.rowset.spi.SyncProviderException#setSyncResolver(SyncResolver)}
+     * @add tests
+     *      {@link javax.sql.rowset.spi.SyncProviderException#getSyncResolver()}
+     */
+    public void test_setSyncResolver_Ljavax_sql_rowset_spi_SyncResolver() {
+        SyncProviderException ex = new SyncProviderException();
+        try {
+            ex.setSyncResolver(null);
+            fail("should throw IllegalArgumentException");
+        } catch (IllegalArgumentException e) {
+            // expected
+        }
+        assertNull(ex.getSyncResolver());
+    }
+
+}