More refactoring


git-svn-id: https://svn.apache.org/repos/asf/santuario/xml-security-java/trunk@1877725 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/src/main/java/org/apache/xml/security/keys/content/keyvalues/DSAKeyValue.java b/src/main/java/org/apache/xml/security/keys/content/keyvalues/DSAKeyValue.java
index dbe6538..467e780 100644
--- a/src/main/java/org/apache/xml/security/keys/content/keyvalues/DSAKeyValue.java
+++ b/src/main/java/org/apache/xml/security/keys/content/keyvalues/DSAKeyValue.java
@@ -114,9 +114,7 @@
             PublicKey pk = dsaFactory.generatePublic(pkspec);
 
             return pk;
-        } catch (NoSuchAlgorithmException ex) {
-            throw new XMLSecurityException(ex);
-        } catch (InvalidKeySpecException ex) {
+        } catch (NoSuchAlgorithmException | InvalidKeySpecException ex) {
             throw new XMLSecurityException(ex);
         }
     }
diff --git a/src/main/java/org/apache/xml/security/keys/content/keyvalues/ECKeyValue.java b/src/main/java/org/apache/xml/security/keys/content/keyvalues/ECKeyValue.java
index 69e9267..11f1c91 100644
--- a/src/main/java/org/apache/xml/security/keys/content/keyvalues/ECKeyValue.java
+++ b/src/main/java/org/apache/xml/security/keys/content/keyvalues/ECKeyValue.java
@@ -200,11 +200,7 @@
 
             ECPublicKeySpec spec = new ECPublicKeySpec(ecPoint, ecParams);
             return KeyFactory.getInstance("EC").generatePublic(spec);
-        } catch (NoSuchAlgorithmException ex) {
-            throw new XMLSecurityException(ex);
-        } catch (InvalidKeySpecException ex) {
-            throw new XMLSecurityException(ex);
-        } catch (MarshalException ex) {
+        } catch (NoSuchAlgorithmException | InvalidKeySpecException | MarshalException ex) {
             throw new XMLSecurityException(ex);
         }
     }
diff --git a/src/main/java/org/apache/xml/security/keys/content/keyvalues/RSAKeyValue.java b/src/main/java/org/apache/xml/security/keys/content/keyvalues/RSAKeyValue.java
index b0280bd..a83b145 100644
--- a/src/main/java/org/apache/xml/security/keys/content/keyvalues/RSAKeyValue.java
+++ b/src/main/java/org/apache/xml/security/keys/content/keyvalues/RSAKeyValue.java
@@ -105,9 +105,7 @@
             PublicKey pk = rsaFactory.generatePublic(rsaKeyspec);
 
             return pk;
-        } catch (NoSuchAlgorithmException ex) {
-            throw new XMLSecurityException(ex);
-        } catch (InvalidKeySpecException ex) {
+        } catch (NoSuchAlgorithmException | InvalidKeySpecException ex) {
             throw new XMLSecurityException(ex);
         }
     }
diff --git a/src/main/java/org/apache/xml/security/transforms/implementations/TransformXPath.java b/src/main/java/org/apache/xml/security/transforms/implementations/TransformXPath.java
index 32f4e2c..e1a10b6 100644
--- a/src/main/java/org/apache/xml/security/transforms/implementations/TransformXPath.java
+++ b/src/main/java/org/apache/xml/security/transforms/implementations/TransformXPath.java
@@ -115,7 +115,7 @@
         return str.indexOf("namespace") != -1 || str.indexOf("name()") != -1;
     }
 
-    static class XPathNodeFilter implements NodeFilter {
+    private static class XPathNodeFilter implements NodeFilter {
 
         private final XPathAPI xPathAPI;
         private final Node xpathnode;
diff --git a/src/main/java/org/apache/xml/security/utils/resolver/implementations/ResolverDirectHTTP.java b/src/main/java/org/apache/xml/security/utils/resolver/implementations/ResolverDirectHTTP.java
index 7890bc2..9a1403e 100644
--- a/src/main/java/org/apache/xml/security/utils/resolver/implementations/ResolverDirectHTTP.java
+++ b/src/main/java/org/apache/xml/security/utils/resolver/implementations/ResolverDirectHTTP.java
@@ -235,9 +235,7 @@
 
         // if the URI contains a fragment, ignore it
         if (newUri.getFragment() != null) {
-            URI uriNewNoFrag =
-                new URI(newUri.getScheme(), newUri.getSchemeSpecificPart(), null);
-            return uriNewNoFrag;
+            return new URI(newUri.getScheme(), newUri.getSchemeSpecificPart(), null);
         }
         return newUri;
     }
diff --git a/src/main/java/org/apache/xml/security/utils/resolver/implementations/ResolverLocalFilesystem.java b/src/main/java/org/apache/xml/security/utils/resolver/implementations/ResolverLocalFilesystem.java
index f35aef8..5717944 100644
--- a/src/main/java/org/apache/xml/security/utils/resolver/implementations/ResolverLocalFilesystem.java
+++ b/src/main/java/org/apache/xml/security/utils/resolver/implementations/ResolverLocalFilesystem.java
@@ -137,9 +137,7 @@
 
         // if the URI contains a fragment, ignore it
         if (newUri.getFragment() != null) {
-            URI uriNewNoFrag =
-                new URI(newUri.getScheme(), newUri.getSchemeSpecificPart(), null);
-            return uriNewNoFrag;
+            return new URI(newUri.getScheme(), newUri.getSchemeSpecificPart(), null);
         }
         return newUri;
     }
diff --git a/src/test/java/org/apache/xml/security/test/dom/algorithms/DigestAlgorithmTest.java b/src/test/java/org/apache/xml/security/test/dom/algorithms/DigestAlgorithmTest.java
index f0bab65..ad35933 100644
--- a/src/test/java/org/apache/xml/security/test/dom/algorithms/DigestAlgorithmTest.java
+++ b/src/test/java/org/apache/xml/security/test/dom/algorithms/DigestAlgorithmTest.java
@@ -25,6 +25,7 @@
 import java.security.Security;
 
 import org.apache.xml.security.algorithms.MessageDigestAlgorithm;
+import org.apache.xml.security.signature.XMLSignatureException;
 import org.apache.xml.security.test.dom.TestUtils;
 import org.junit.jupiter.api.Assumptions;
 import org.w3c.dom.Document;
@@ -32,6 +33,7 @@
 import static org.junit.jupiter.api.Assertions.assertArrayEquals;
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
 import static org.junit.jupiter.api.Assertions.assertTrue;
 
 
@@ -294,4 +296,15 @@
         assertArrayEquals(digest, digest2);
     }
 
+    @org.junit.jupiter.api.Test
+    public void testNullAlgorithm() throws Exception {
+        assertThrows(XMLSignatureException.class, () ->
+                MessageDigestAlgorithm.getInstance(TestUtils.newDocument(), null));
+    }
+
+    @org.junit.jupiter.api.Test
+    public void testNoSuchAlgorithm() throws Exception {
+        assertThrows(XMLSignatureException.class, () ->
+                MessageDigestAlgorithm.getInstance(TestUtils.newDocument(), "xyz"));
+    }
 }
diff --git a/src/test/java/org/apache/xml/security/test/dom/algorithms/SignatureAlgorithmTest.java b/src/test/java/org/apache/xml/security/test/dom/algorithms/SignatureAlgorithmTest.java
index ab0e80c..49254b6 100644
--- a/src/test/java/org/apache/xml/security/test/dom/algorithms/SignatureAlgorithmTest.java
+++ b/src/test/java/org/apache/xml/security/test/dom/algorithms/SignatureAlgorithmTest.java
@@ -34,6 +34,8 @@
 import javax.crypto.SecretKey;
 
 import org.apache.xml.security.algorithms.SignatureAlgorithm;
+import org.apache.xml.security.algorithms.implementations.SignatureBaseRSA;
+import org.apache.xml.security.exceptions.AlgorithmAlreadyRegisteredException;
 import org.apache.xml.security.exceptions.XMLSecurityException;
 import org.apache.xml.security.signature.XMLSignature;
 import org.apache.xml.security.signature.XMLSignatureException;
@@ -194,4 +196,20 @@
         assertThrows(XMLSignatureException.class, () ->
                 signatureAlgorithm.initVerify(keyPair.getPublic()));
     }
+
+    @org.junit.jupiter.api.Test
+    public void testAlreadyRegisteredException() throws Exception {
+        assertThrows(AlgorithmAlreadyRegisteredException.class, () ->
+            SignatureAlgorithm.register(XMLSignature.ALGO_ID_SIGNATURE_RSA_SHA256,
+                    SignatureBaseRSA.SignatureRSASHA256.class)
+        );
+    }
+
+    @org.junit.jupiter.api.Test
+    public void testAlreadyRegisteredExceptionFromString() throws Exception {
+        assertThrows(AlgorithmAlreadyRegisteredException.class, () ->
+                SignatureAlgorithm.register(XMLSignature.ALGO_ID_SIGNATURE_RSA_SHA256,
+                        SignatureBaseRSA.SignatureRSASHA256.class.getName())
+        );
+    }
 }
diff --git a/src/test/java/org/apache/xml/security/test/dom/transforms/TransformTest.java b/src/test/java/org/apache/xml/security/test/dom/transforms/TransformTest.java
new file mode 100644
index 0000000..f975601
--- /dev/null
+++ b/src/test/java/org/apache/xml/security/test/dom/transforms/TransformTest.java
@@ -0,0 +1,49 @@
+/**
+ * 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.xml.security.test.dom.transforms;
+
+import org.apache.xml.security.Init;
+import org.apache.xml.security.exceptions.AlgorithmAlreadyRegisteredException;
+import org.apache.xml.security.transforms.Transform;
+import org.apache.xml.security.transforms.Transforms;
+import org.apache.xml.security.transforms.implementations.TransformC14N11;
+
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+public class TransformTest {
+
+    static {
+        Init.init();
+    }
+
+    @org.junit.jupiter.api.Test
+    public void testAlreadyRegisteredException() throws Exception {
+        assertThrows(AlgorithmAlreadyRegisteredException.class, () ->
+                Transform.register(Transforms.TRANSFORM_C14N11_OMIT_COMMENTS, TransformC14N11.class)
+        );
+    }
+
+    @org.junit.jupiter.api.Test
+    public void testAlreadyRegisteredExceptionFromString() throws Exception {
+        assertThrows(AlgorithmAlreadyRegisteredException.class, () ->
+                Transform.register(Transforms.TRANSFORM_C14N11_OMIT_COMMENTS,
+                        TransformC14N11.class.getName())
+        );
+    }
+}
\ No newline at end of file