[java-metadata-aggregator] branch dev/JPAR-186 updated: JSPT-98 Integrate lifecycle checking methods in base classes

Ian Young ian at iay.org.uk
Thu Aug 18 15:54:37 UTC 2022


This is an automated email from the git hooks/post-receive script.

iay pushed a commit to branch dev/JPAR-186
in repository java-metadata-aggregator.

View the commit online:
http://git.shibboleth.net/view/?p=java-metadata-aggregator.git;a=commit;h=b71b9ef943204a741b4a8602f431ebb7b1ee6111

The following commit(s) were added to refs/heads/dev/JPAR-186 by this push:
     new b71b9ef  JSPT-98 Integrate lifecycle checking methods in base classes
b71b9ef is described below

commit b71b9ef943204a741b4a8602f431ebb7b1ee6111
Author: Ian Young <ian at iay.org.uk>
AuthorDate: Thu Aug 18 16:54:29 2022 +0100

    JSPT-98 Integrate lifecycle checking methods in base classes
    
    https://shibboleth.atlassian.net/browse/JSPT-98
---
 .../BaseIdentifiableInitializableComponent.java    | 43 +---------------------
 ...BaseIdentifiableInitializableComponentTest.java | 27 +++++++++-----
 2 files changed, 20 insertions(+), 50 deletions(-)

diff --git a/mda-framework/src/main/java/net/shibboleth/metadata/pipeline/impl/BaseIdentifiableInitializableComponent.java b/mda-framework/src/main/java/net/shibboleth/metadata/pipeline/impl/BaseIdentifiableInitializableComponent.java
index a821abe..0129512 100644
--- a/mda-framework/src/main/java/net/shibboleth/metadata/pipeline/impl/BaseIdentifiableInitializableComponent.java
+++ b/mda-framework/src/main/java/net/shibboleth/metadata/pipeline/impl/BaseIdentifiableInitializableComponent.java
@@ -20,10 +20,6 @@ package net.shibboleth.metadata.pipeline.impl;
 import javax.annotation.concurrent.ThreadSafe;
 
 import net.shibboleth.utilities.java.support.component.AbstractIdentifiableInitializableComponent;
-import net.shibboleth.utilities.java.support.component.DestroyedComponentException;
-import net.shibboleth.utilities.java.support.component.UninitializedComponentException;
-import net.shibboleth.utilities.java.support.component.UnmodifiableComponentException;
-import net.shibboleth.utilities.java.support.primitive.StringSupport;
 
 /**
  * Base class extending {@link AbstractIdentifiableInitializableComponent} with helper methods
@@ -34,45 +30,11 @@ import net.shibboleth.utilities.java.support.primitive.StringSupport;
 @ThreadSafe
 public class BaseIdentifiableInitializableComponent extends AbstractIdentifiableInitializableComponent {
 
-    /**
-     * Checks if the component is destroyed and, if so, throws a {@link DestroyedComponentException}.
-     */
-    protected final void ifDestroyedThrowDestroyedComponentException() {
-        if (isDestroyed()) {
-            throw new DestroyedComponentException("Component '"
-                    + StringSupport.trimOrNull(getId())
-                    + "' has already been destroyed and can no longer be used.");
-        }
-    }
-
-    /**
-     * Checks if a component has not been initialized and, if so, throws a {@link UninitializedComponentException}.
-     */
-    protected final void ifNotInitializedThrowUninitializedComponentException() {
-        if (!isInitialized()) {
-            throw new UninitializedComponentException("Component '"
-                    + StringSupport.trimOrNull(getId())
-                    + "' has not yet been initialized and cannot be used.");
-        }
-    }
-
-    /**
-     * Checks if a component has been initialized and, if so, throws a {@link UnmodifiableComponentException}.
-     */
-    protected final void ifInitializedThrowUnmodifiabledComponentException() {
-        if (isInitialized()) {
-            throw new UnmodifiableComponentException("Component '"
-                    + StringSupport.trimOrNull(getId())
-                    + "' has already been initialized and can no longer be modified");
-        }
-    }
-
     /**
      * Helper for a setter method to check the standard preconditions.
      */
     protected final void throwSetterPreconditionExceptions() {
-        ifDestroyedThrowDestroyedComponentException();
-        ifInitializedThrowUnmodifiabledComponentException();
+        checkSetterPreconditions();
     }
 
     /**
@@ -80,8 +42,7 @@ public class BaseIdentifiableInitializableComponent extends AbstractIdentifiable
      * not initialized, or have been destroyed.
      */
     protected final void throwComponentStateExceptions() {
-        ifDestroyedThrowDestroyedComponentException();
-        ifNotInitializedThrowUninitializedComponentException();
+        checkComponentActive();
     }
 
 }
diff --git a/mda-framework/src/test/java/net/shibboleth/metadata/pipeline/impl/BaseIdentifiableInitializableComponentTest.java b/mda-framework/src/test/java/net/shibboleth/metadata/pipeline/impl/BaseIdentifiableInitializableComponentTest.java
index 84408a7..6acd9b1 100644
--- a/mda-framework/src/test/java/net/shibboleth/metadata/pipeline/impl/BaseIdentifiableInitializableComponentTest.java
+++ b/mda-framework/src/test/java/net/shibboleth/metadata/pipeline/impl/BaseIdentifiableInitializableComponentTest.java
@@ -10,22 +10,32 @@ import net.shibboleth.utilities.java.support.component.UnmodifiableComponentExce
 public class BaseIdentifiableInitializableComponentTest {
 
     private class TestClass extends BaseIdentifiableInitializableComponent {
+        public void checkIfDestroyedThrowDestroyedComponentException() {
+            ifDestroyedThrowDestroyedComponentException();
+        }
+
+        public void checkIfNotInitializedThrowUninitializedComponentException() {
+            ifNotInitializedThrowUninitializedComponentException();
+        }
+
+        public void checkIfInitializedThrowUnmodifiabledComponentException() {
+            ifInitializedThrowUnmodifiabledComponentException();
+        }
     }
-    
-    
+
     @Test(expectedExceptions = {DestroyedComponentException.class})
     public void ifDestroyedYes() throws Exception {
         final var c = new TestClass();
         c.setId("test");
         c.initialize();
         c.destroy();
-        c.ifDestroyedThrowDestroyedComponentException();
+        c.checkIfDestroyedThrowDestroyedComponentException();
     }
 
     @Test
     public void ifDestroyedNo() throws Exception {
         final var c = new TestClass();
-        c.ifDestroyedThrowDestroyedComponentException();
+        c.checkIfDestroyedThrowDestroyedComponentException();
         c.setId("test");
         c.initialize();
         c.destroy();
@@ -34,7 +44,7 @@ public class BaseIdentifiableInitializableComponentTest {
     @Test(expectedExceptions = {UninitializedComponentException.class})
     public void ifNotInitializedYes() throws Exception {
         final var c = new TestClass();
-        c.ifNotInitializedThrowUninitializedComponentException();
+        c.checkIfNotInitializedThrowUninitializedComponentException();
     }
 
     @Test
@@ -42,7 +52,7 @@ public class BaseIdentifiableInitializableComponentTest {
         final var c = new TestClass();
         c.setId("test");
         c.initialize();
-        c.ifNotInitializedThrowUninitializedComponentException();
+        c.checkIfNotInitializedThrowUninitializedComponentException();
         c.destroy();
     }
 
@@ -51,14 +61,13 @@ public class BaseIdentifiableInitializableComponentTest {
         final var c = new TestClass();
         c.setId("test");
         c.initialize();
-        c.ifInitializedThrowUnmodifiabledComponentException();
+        c.checkIfInitializedThrowUnmodifiabledComponentException();
     }
 
     @Test
     public void ifInitializedNo() throws Exception {
         final var c = new TestClass();
-        c.ifInitializedThrowUnmodifiabledComponentException();
+        c.checkIfInitializedThrowUnmodifiabledComponentException();
     }
 
-
 }

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the commits mailing list