You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-commits@db.apache.org by rh...@apache.org on 2006/08/08 18:51:59 UTC

svn commit: r429728 - in /db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests: tests/jdbc4/ResultSetTest.java util/BaseTestCase.java

Author: rhillegas
Date: Tue Aug  8 09:51:59 2006
New Revision: 429728

URL: http://svn.apache.org/viewvc?rev=429728&view=rev
Log:
DERBY-1524: Add new assertion overload.

Modified:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/ResultSetTest.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/BaseTestCase.java

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/ResultSetTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/ResultSetTest.java?rev=429728&r1=429727&r2=429728&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/ResultSetTest.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/ResultSetTest.java Tue Aug  8 09:51:59 2006
@@ -1434,56 +1434,4 @@
         return stmt.executeQuery("select " + colName +
                 " from UpdateTestTableResultSet where sno = " + key);
     }
-
-    /**
-     * Compare the contents of two streams.
-     * The streams are closed after they are exhausted.
-     *
-     * @param is1 the first stream
-     * @param is2 the second stream
-     * @throws IOException if reading from the streams fail
-     * @throws AssertionFailedError if the stream contents are not equal
-     */
-    private static void assertEquals(InputStream is1, InputStream is2)
-            throws IOException {
-        long index = 0;
-        int b1 = is1.read();
-        int b2 = is2.read();
-        do {
-            if (b1 != b2) {
-                assertEquals("Streams differ at index " + index, b1, b2);
-            }
-            index++;
-            b1 = is1.read();
-            b2 = is2.read();
-        } while (b1 != -1 || b2 != -1);
-        is1.close();
-        is2.close();
-    }
-
-    /**
-     * Compare the contents of two readers.
-     * The readers are closed after they are exhausted.
-     *
-     * @param r1 the first reader
-     * @param r2 the second reader
-     * @throws IOException if reading from the streams fail
-     * @throws AssertionFailedError if the reader contents are not equal
-     */
-    private static void assertEquals(Reader r1, Reader r2)
-            throws IOException {
-        long index = 0;
-        int b1 = r1.read();
-        int b2 = r2.read();
-        do {
-            if (b1 != b2) {
-                assertEquals("Streams differ at index " + index, b1, b2);
-            }
-            index++;
-            b1 = r1.read();
-            b2 = r2.read();
-        } while (b1 != -1 || b2 != -1);
-        r1.close();
-        r2.close();
-    }
 }

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/BaseTestCase.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/BaseTestCase.java?rev=429728&r1=429727&r2=429728&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/BaseTestCase.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/BaseTestCase.java Tue Aug  8 09:51:59 2006
@@ -20,6 +20,9 @@
 package org.apache.derbyTesting.functionTests.util;
 
 import junit.framework.TestCase;
+import java.io.InputStream;
+import java.io.IOException;
+import java.io.Reader;
 import java.io.PrintStream;
 import java.net.URL;
 import java.sql.SQLException;
@@ -211,5 +214,68 @@
     	assertNotNull("No SecurityManager installed",
     			System.getSecurityManager());
     }
-    
+
+    /**
+     * Compare the contents of two streams.
+     * The streams are closed after they are exhausted.
+     *
+     * @param is1 the first stream
+     * @param is2 the second stream
+     * @throws IOException if reading from the streams fail
+     * @throws AssertionFailedError if the stream contents are not equal
+     */
+    public static void assertEquals(InputStream is1, InputStream is2)
+            throws IOException {
+        if (is1 == null || is2 == null) {
+            assertNull("InputStream is2 is null, is1 is not", is1);
+            assertNull("InputStream is1 is null, is2 is not", is2);
+            return;
+        }
+        long index = 0;
+        int b1 = is1.read();
+        int b2 = is2.read();
+        do {
+            // Avoid string concatenation for every byte in the stream.
+            if (b1 != b2) {
+                assertEquals("Streams differ at index " + index, b1, b2);
+            }
+            index++;
+            b1 = is1.read();
+            b2 = is2.read();
+        } while (b1 != -1 || b2 != -1);
+        is1.close();
+        is2.close();
+    }
+
+    /**
+     * Compare the contents of two readers.
+     * The readers are closed after they are exhausted.
+     *
+     * @param r1 the first reader
+     * @param r2 the second reader
+     * @throws IOException if reading from the streams fail
+     * @throws AssertionFailedError if the reader contents are not equal
+     */
+    public static void assertEquals(Reader r1, Reader r2)
+            throws IOException {
+        long index = 0;
+        if (r1 == null || r2 == null) {
+            assertNull("Reader r2 is null, r1 is not", r1);
+            assertNull("Reader r1 is null, r2 is not", r2);
+            return;
+        }
+        int c1 = r1.read();
+        int c2 = r2.read();
+        do {
+            // Avoid string concatenation for every char in the stream.
+            if (c1 != c2) {
+                assertEquals("Streams differ at index " + index, c1, c2);
+            }
+            index++;
+            c1 = r1.read();
+            c2 = r2.read();
+        } while (c1 != -1 || c2 != -1);
+        r1.close();
+        r2.close();
+    }
 } // End class BaseTestCase