harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From smish...@apache.org
Subject svn commit: r499341 - in /harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security: DigestOutputStream2Test.java DigestOutputStreamTest.java
Date Wed, 24 Jan 2007 10:23:12 GMT
Author: smishura
Date: Wed Jan 24 02:23:11 2007
New Revision: 499341

URL: http://svn.apache.org/viewvc?view=rev&rev=499341
Log:
Refactor tests for DigestOutputStream constructor

Modified:
    harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/DigestOutputStream2Test.java
    harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/DigestOutputStreamTest.java

Modified: harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/DigestOutputStream2Test.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/DigestOutputStream2Test.java?view=diff&rev=499341&r1=499340&r2=499341
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/DigestOutputStream2Test.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/DigestOutputStream2Test.java
Wed Jan 24 02:23:11 2007
@@ -29,18 +29,6 @@
 	MessageDigest digest;
 
 	/**
-	 * @tests java.security.DigestOutputStream#DigestOutputStream(java.io.OutputStream,
-	 *        java.security.MessageDigest)
-	 */
-	public void test_ConstructorLjava_io_OutputStreamLjava_security_MessageDigest() {
-		// Test for method
-		// java.security.DigestOutputStream(java.io.OutputStream,
-		// java.security.MessageDigest)
-		assertNotNull("Constructor returned null instance",
-				new DigestOutputStream(output1, digest));
-	}
-
-	/**
 	 * @tests java.security.DigestOutputStream#getMessageDigest()
 	 */
 	public void test_getMessageDigest() {

Modified: harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/DigestOutputStreamTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/DigestOutputStreamTest.java?view=diff&rev=499341&r1=499340&r2=499341
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/DigestOutputStreamTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/DigestOutputStreamTest.java
Wed Jan 24 02:23:11 2007
@@ -28,6 +28,7 @@
 import java.util.Arrays;
 
 import org.apache.harmony.security.tests.support.MDGoldenData;
+import org.apache.harmony.security.tests.support.MyMessageDigest1;
 
 import junit.framework.TestCase;
 
@@ -76,35 +77,23 @@
     //
 
     /**
-     * Test #1 for <code>DigestOutputStream</code> constructor<br>
-     * 
-     * Assertion: creates new <code>DigestOutputStream</code> instance
-     * using valid parameters (both non <code>null</code>)
+     * @tests java.security.DigestOutputStream#DigestOutputStream(java.io.OutputStream,
+     *        java.security.MessageDigest)
      */
-    public final void testDigestOutputStream01() {
-        for (int k=0; k<algorithmName.length; k++) {
-            try {
-                MessageDigest md = MessageDigest.getInstance(algorithmName[k]);
-                OutputStream bos = new ByteArrayOutputStream(MY_MESSAGE_LEN);
-                OutputStream dos = new DigestOutputStream(bos, md);
-                assertTrue(dos instanceof DigestOutputStream);
-                return;
-            } catch (NoSuchAlgorithmException e) {
-                // allowed failure
-            }
-        }
-        fail(getName() + ": no MessageDigest algorithms available - test not performed");
-    }
+    public void test_CtorLjava_io_OutputStreamLjava_security_MessageDigest() {
 
-    /**
-     * Test #2 for <code>DigestOutputStream</code> constructor<br>
-     * 
-     * Assertion: creates new <code>DigestOutputStream</code> instance
-     * using valid parameters (both <code>null</code>)
-     */
-    public final void testDigestOutputStream02() {
-        OutputStream dos = new DigestOutputStream(null, null);
-        assertTrue(dos instanceof DigestOutputStream);
+        // non-null parameters
+        MessageDigest md = new MyMessageDigest1();
+        MyOutputStream out = new MyOutputStream();
+
+        MyDigestOutputStream dos = new MyDigestOutputStream(out, md);
+        assertSame(out, dos.myOutputStream());
+        assertSame(md, dos.myMessageDigest());
+
+        // null parameters
+        dos = new MyDigestOutputStream(null, null);
+        assertNull(dos.myOutputStream());
+        assertNull(dos.myMessageDigest());
     }
 
     /**
@@ -498,4 +487,23 @@
         fail(getName() + ": no MessageDigest algorithms available - test not performed");
     }
 
+    private class MyOutputStream extends OutputStream {
+        @Override
+        public void write(int arg0) throws IOException {
+        }
+    }
+    
+    private class MyDigestOutputStream extends DigestOutputStream {
+        public MyDigestOutputStream(OutputStream out, MessageDigest digest) {
+            super(out, digest);
+        }
+
+        public MessageDigest myMessageDigest() {
+            return digest;
+        }
+
+        public OutputStream myOutputStream() {
+            return out;
+        }
+    }
 }



Mime
View raw message