harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ndbe...@apache.org
Subject svn commit: r726259 - in /harmony/enhanced/classlib/trunk/modules/x-net/src: main/java/javax/net/ssl/KeyStoreBuilderParameters.java test/api/java/org/apache/harmony/xnet/tests/javax/net/ssl/KeyStoreBuilderParametersTest.java
Date Sat, 13 Dec 2008 19:23:07 GMT
Author: ndbeyer
Date: Sat Dec 13 11:23:07 2008
New Revision: 726259

URL: http://svn.apache.org/viewvc?rev=726259&view=rev
Log:
Code clean up and documentation

Modified:
    harmony/enhanced/classlib/trunk/modules/x-net/src/main/java/javax/net/ssl/KeyStoreBuilderParameters.java
    harmony/enhanced/classlib/trunk/modules/x-net/src/test/api/java/org/apache/harmony/xnet/tests/javax/net/ssl/KeyStoreBuilderParametersTest.java

Modified: harmony/enhanced/classlib/trunk/modules/x-net/src/main/java/javax/net/ssl/KeyStoreBuilderParameters.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/x-net/src/main/java/javax/net/ssl/KeyStoreBuilderParameters.java?rev=726259&r1=726258&r2=726259&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/x-net/src/main/java/javax/net/ssl/KeyStoreBuilderParameters.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/x-net/src/main/java/javax/net/ssl/KeyStoreBuilderParameters.java
Sat Dec 13 11:23:07 2008
@@ -23,31 +23,52 @@
 import java.security.KeyStore;
 
 /**
- * @com.intel.drl.spec_ref
- *  
+ * A parameters object for {@link X509KeyManager}
+ * 
+ * @since 1.5
+ * @see X509KeyManager
+ * @see KeyStore.Builder
  */
 public class KeyStoreBuilderParameters implements ManagerFactoryParameters {
 
-    private List ksbuilders;
+    private final List<KeyStore.Builder> ksbuilders;
 
+    /**
+     * Constructs an instance for the builder passed.
+     * 
+     * @param builder a builder
+     */
     public KeyStoreBuilderParameters(KeyStore.Builder builder) {
-        ksbuilders = new ArrayList();
-        if (builder != null) {
-            ksbuilders.add(builder);
-        }
+        super();
+        ksbuilders = Collections.singletonList(builder);
     }
 
+    /**
+     * Constructs an instance for the builder list passed.
+     * 
+     * @param parameters the builder list
+     * @throws NullPointerException if {@code parameters} is {@code null}
+     * @throws IllegalArgumentException if {@code parameters} is empty
+     */
+    @SuppressWarnings("unchecked")
     public KeyStoreBuilderParameters(List parameters) {
+        super();
         if (parameters == null) {
             throw new NullPointerException("Builders list is null");
         }
         if (parameters.isEmpty()) {
             throw new IllegalArgumentException("Builders list is empty");
         }
-        ksbuilders = new ArrayList(parameters);
+        ksbuilders = Collections.unmodifiableList(new ArrayList<KeyStore.Builder>(parameters));
     }
 
+    /**
+     * The list of builder parameters.
+     * 
+     * @return an unmodifiable list of parameters
+     */
+    @SuppressWarnings("unchecked")
     public List getParameters() {
-        return Collections.unmodifiableList(ksbuilders);
+        return ksbuilders;
     }
 }

Modified: harmony/enhanced/classlib/trunk/modules/x-net/src/test/api/java/org/apache/harmony/xnet/tests/javax/net/ssl/KeyStoreBuilderParametersTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/x-net/src/test/api/java/org/apache/harmony/xnet/tests/javax/net/ssl/KeyStoreBuilderParametersTest.java?rev=726259&r1=726258&r2=726259&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/x-net/src/test/api/java/org/apache/harmony/xnet/tests/javax/net/ssl/KeyStoreBuilderParametersTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/x-net/src/test/api/java/org/apache/harmony/xnet/tests/javax/net/ssl/KeyStoreBuilderParametersTest.java
Sat Dec 13 11:23:07 2008
@@ -19,6 +19,7 @@
 
 import java.security.KeyStore;
 import java.security.KeyStoreException;
+import java.security.KeyStore.Builder;
 import java.util.ArrayList;
 import java.util.List;
 
@@ -31,13 +32,28 @@
  * methods.
  */
 public class KeyStoreBuilderParametersTest extends TestCase {
+    
+    class EmptyBuilder extends KeyStore.Builder {
+        public KeyStore getKeyStore() throws KeyStoreException {
+            return null;
+        }
+
+        public KeyStore.ProtectionParameter getProtectionParameter(String alias)
+                throws KeyStoreException {
+            return null;
+        }
+    }
 
     /*
      * Class under test for void KeyStoreBuilderParameters(KeyStore.Builder)
      */
     public final void testKeyStoreBuilderParametersBuilder() {
-        // should not throw NullPointerException
-        new KeyStoreBuilderParameters((KeyStore.Builder) null);
+        try {
+            new KeyStoreBuilderParameters((KeyStore.Builder) null);
+        } catch (NullPointerException e) {
+            // javadoc says this should throw NPE, but it doesn't
+            fail("no NPE expected");
+        }
     }
 
     /*
@@ -45,36 +61,37 @@
      */
     public final void testKeyStoreBuilderParametersList() {
         try {
-            new KeyStoreBuilderParameters((List) null);
-            fail("No expected NullPointerException");
+            new KeyStoreBuilderParameters((List<?>) null);
+            fail("expected a NPE");
         } catch (NullPointerException e) {
         }
 
         try {
-            new KeyStoreBuilderParameters(new ArrayList());
-            fail("No expected IllegalArgumentException");
+            new KeyStoreBuilderParameters(new ArrayList<Builder>());
+            fail("expected a IAE");
         } catch (IllegalArgumentException e) {
         }
 
     }
 
+    @SuppressWarnings("unchecked")
     public final void testGetParameters() {
-        List ksbuilders;
-        KeyStore.Builder builder = new myBuilder();
-        List result;
+        List<Builder> ksbuilders;
+        KeyStore.Builder builder = new EmptyBuilder();
+        List<Object> result;
         KeyStoreBuilderParameters param = new KeyStoreBuilderParameters(builder);
         result = param.getParameters();
         try {
-            result.add(new myBuilder());
+            result.add(new EmptyBuilder());
             fail("The list is modifiable");
         } catch (UnsupportedOperationException e) {
         }
         assertEquals("incorrect size", 1, result.size());
         assertTrue("incorrect list", result.contains(builder));
         
-        ksbuilders = new ArrayList();
+        ksbuilders = new ArrayList<Builder>();
         ksbuilders.add(builder);
-        ksbuilders.add(new myBuilder());  
+        ksbuilders.add(new EmptyBuilder());  
         param = new KeyStoreBuilderParameters(ksbuilders);
         result = param.getParameters();
         try {
@@ -86,14 +103,3 @@
         assertTrue("incorrect list", result.containsAll(ksbuilders));
     }
 }
-
-class myBuilder extends KeyStore.Builder {
-    public KeyStore getKeyStore() throws KeyStoreException {
-        return null;
-    }
-
-    public KeyStore.ProtectionParameter getProtectionParameter(String alias)
-            throws KeyStoreException {
-        return null;
-    }
-}



Mime
View raw message