harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From smish...@apache.org
Subject svn commit: r488533 - /harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/AlgorithmParametersTest.java
Date Tue, 19 Dec 2006 05:46:54 GMT
Author: smishura
Date: Mon Dec 18 21:46:53 2006
New Revision: 488533

URL: http://svn.apache.org/viewvc?view=rev&rev=488533
Log:
Evaluation for HARMONY-2733:
[java][security]AlgorithmParameters.getParamterSpec should throw NullPointerException if the
input AlgorithmSpec class is null.

Added a separate test case for AlgorithmParameters.getParameterSpec(Class<T> paramSpec)
Removed duplicated testing

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

Modified: harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/AlgorithmParametersTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/AlgorithmParametersTest.java?view=diff&rev=488533&r1=488532&r2=488533
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/AlgorithmParametersTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/AlgorithmParametersTest.java
Mon Dec 18 21:46:53 2006
@@ -23,13 +23,11 @@
 package org.apache.harmony.security.tests.java.security;
 
 import java.io.IOException;
-import java.math.BigInteger;
 import java.security.AlgorithmParameters;
 import java.security.AlgorithmParametersSpi;
 import java.security.Provider;
 import java.security.Security;
 import java.security.spec.AlgorithmParameterSpec;
-import java.security.spec.DSAParameterSpec;
 import java.security.spec.InvalidParameterSpecException;
 
 import junit.framework.TestCase;
@@ -215,6 +213,64 @@
     }
 
     /**
+     * @tests java.security.AlgorithmParameters#getParameterSpec(Class)
+     */
+    public void test_getParameterSpecLjava_lang_Class() throws Exception {
+
+        final MyAlgorithmParameterSpec myParamSpec = new MyAlgorithmParameterSpec();
+
+        MyAlgorithmParameters paramSpi = new MyAlgorithmParameters() {
+            protected AlgorithmParameterSpec engineGetParameterSpec(
+                    Class paramSpec) {
+                return myParamSpec;
+            }
+        };
+
+        AlgorithmParameters params = new DummyAlgorithmParameters(paramSpi, p,
+                "algorithm");
+
+        //
+        // test: InvalidParameterSpecException if not initialized
+        //
+        try {
+            params.getParameterSpec(null);
+            fail("No expected InvalidParameterSpecException");
+        } catch (InvalidParameterSpecException e) {
+            // expected
+        }
+        try {
+            params.getParameterSpec(MyAlgorithmParameterSpec.class);
+            fail("No expected InvalidParameterSpecException");
+        } catch (InvalidParameterSpecException e) {
+            // expected
+        }
+
+        //
+        // test: corresponding spi method is invoked
+        //
+        params.init(new MyAlgorithmParameterSpec());
+        assertSame(myParamSpec, params
+                .getParameterSpec(MyAlgorithmParameterSpec.class));
+
+        //
+        // test: if paramSpec is null
+        //
+        paramSpi = new MyAlgorithmParameters() {
+
+            protected AlgorithmParameterSpec engineGetParameterSpec(
+                    Class paramSpec) {
+                assertNull(paramSpec); // null is passed to spi-provider
+                return null;
+            }
+        };
+
+        params = new DummyAlgorithmParameters(paramSpi, p, "algorithm");
+        params.init(new MyAlgorithmParameterSpec());
+        assertNull(params.getParameterSpec(null));
+
+    }
+
+    /**
      * @tests java.security.AlgorithmParameters#getInstance(String, Provider)
      */
     public void test_getInstanceLjava_lang_StringLjava_security_Provider()
@@ -254,13 +310,6 @@
     }
 
 	private void checkUnititialized(AlgorithmParameters ap) {
-		try {
-		    //make it compilable on 1.5
-			ap.getParameterSpec((Class<AlgorithmParameterSpec>)new Object().getClass());
-			fail("getParameterSpec(): No expected InvalidParameterSpecException");
-		} catch (java.security.spec.InvalidParameterSpecException e) {
-		}
-		
         assertNull("Unititialized: toString() failed", ap.toString());
 	}
 	
@@ -269,12 +318,6 @@
         assertSame("getProvider() failed", p, ap.getProvider());
         assertEquals("getAlgorithm() failed", "ABC", ap.getAlgorithm());
 
-        //make it compilable on 1.5
-        ap.getParameterSpec((Class<AlgorithmParameterSpec>) new Object()
-                .getClass());
-        assertTrue("getParameterSpec() failed",
-                MyAlgorithmParameters.runEngineGetParameterSpec);
-
         assertEquals("AlgorithmParameters", ap.toString());
         assertTrue("toString() failed", MyAlgorithmParameters.runEngineToString);
     }
@@ -308,8 +351,6 @@
 
         public static boolean runEngineInit3 = false;
 
-        public static boolean runEngineGetParameterSpec = false;
-
         public static boolean runEngineToString = false;
 
         protected void engineInit(AlgorithmParameterSpec paramSpec)
@@ -328,7 +369,6 @@
 
         protected AlgorithmParameterSpec engineGetParameterSpec(Class paramSpec)
                 throws InvalidParameterSpecException {
-            runEngineGetParameterSpec = true;
             return null;
         }
 



Mime
View raw message