[java-metadata-aggregator] 02/02: JSPT-98 Integrate lifecycle checking methods in base classes

Ian Young ian at iay.org.uk
Thu Aug 25 16:18:47 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=a4dca61add96c7ad8fc92deb4fec0e28d19235a5

commit a4dca61add96c7ad8fc92deb4fec0e28d19235a5
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    | 54 ----------------------
 .../pipeline/impl/BaseInitializableComponent.java  | 48 -------------------
 ...BaseIdentifiableInitializableComponentTest.java | 27 +++++++----
 .../impl/BaseInitializableComponentTest.java       | 23 ++++++---
 4 files changed, 35 insertions(+), 117 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 1458c34..2bbdf83 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,54 +30,4 @@ 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 checkSetterPreconditions() {
-        ifDestroyedThrowDestroyedComponentException();
-        ifInitializedThrowUnmodifiabledComponentException();
-    }
-
-    /**
-     * Helper for any method to throw appropriate exceptions if we are either
-     * not initialized, or have been destroyed.
-     */
-    protected final void checkComponentActive() {
-        ifDestroyedThrowDestroyedComponentException();
-        ifNotInitializedThrowUninitializedComponentException();
-    }
-
 }
diff --git a/mda-framework/src/main/java/net/shibboleth/metadata/pipeline/impl/BaseInitializableComponent.java b/mda-framework/src/main/java/net/shibboleth/metadata/pipeline/impl/BaseInitializableComponent.java
index 5f278c6..12003e8 100644
--- a/mda-framework/src/main/java/net/shibboleth/metadata/pipeline/impl/BaseInitializableComponent.java
+++ b/mda-framework/src/main/java/net/shibboleth/metadata/pipeline/impl/BaseInitializableComponent.java
@@ -20,9 +20,6 @@ package net.shibboleth.metadata.pipeline.impl;
 import javax.annotation.concurrent.ThreadSafe;
 
 import net.shibboleth.utilities.java.support.component.AbstractInitializableComponent;
-import net.shibboleth.utilities.java.support.component.DestroyedComponentException;
-import net.shibboleth.utilities.java.support.component.UninitializedComponentException;
-import net.shibboleth.utilities.java.support.component.UnmodifiableComponentException;
 
 /**
  * Base class extending {@link AbstractInitializableComponent} with helper methods
@@ -33,49 +30,4 @@ import net.shibboleth.utilities.java.support.component.UnmodifiableComponentExce
 @ThreadSafe
 public class BaseInitializableComponent extends AbstractInitializableComponent {
 
-    /**
-     * Checks if the component is destroyed and, if so, throws a {@link DestroyedComponentException}.
-     */
-    protected final void ifDestroyedThrowDestroyedComponentException() {
-        if (isDestroyed()) {
-            throw new DestroyedComponentException("Component 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 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 has already been initialized and can no longer be modified");
-        }
-    }
-
-    /**
-     * Helper for a setter method to check the standard preconditions.
-     */
-    protected final void checkSetterPreconditions() {
-        ifDestroyedThrowDestroyedComponentException();
-        ifInitializedThrowUnmodifiabledComponentException();
-    }
-
-    /**
-     * Helper for any method to throw appropriate exceptions if we are either
-     * not initialized, or have been destroyed.
-     */
-    protected final void checkComponentActive() {
-        ifDestroyedThrowDestroyedComponentException();
-        ifNotInitializedThrowUninitializedComponentException();
-    }
-
 }
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();
     }
 
-
 }
diff --git a/mda-framework/src/test/java/net/shibboleth/metadata/pipeline/impl/BaseInitializableComponentTest.java b/mda-framework/src/test/java/net/shibboleth/metadata/pipeline/impl/BaseInitializableComponentTest.java
index ab65b79..47f3485 100644
--- a/mda-framework/src/test/java/net/shibboleth/metadata/pipeline/impl/BaseInitializableComponentTest.java
+++ b/mda-framework/src/test/java/net/shibboleth/metadata/pipeline/impl/BaseInitializableComponentTest.java
@@ -10,6 +10,17 @@ import net.shibboleth.utilities.java.support.component.UnmodifiableComponentExce
 public class BaseInitializableComponentTest {
 
     private class TestClass extends BaseInitializableComponent {
+        public void checkIfDestroyedThrowDestroyedComponentException() {
+            ifDestroyedThrowDestroyedComponentException();
+        }
+
+        public void checkIfNotInitializedThrowUninitializedComponentException() {
+            ifNotInitializedThrowUninitializedComponentException();
+        }
+
+        public void checkIfInitializedThrowUnmodifiabledComponentException() {
+            ifInitializedThrowUnmodifiabledComponentException();
+        }
     }
     
     @Test(expectedExceptions = {DestroyedComponentException.class})
@@ -17,28 +28,28 @@ public class BaseInitializableComponentTest {
         final var c = new TestClass();
         c.initialize();
         c.destroy();
-        c.ifDestroyedThrowDestroyedComponentException();
+        c.checkIfDestroyedThrowDestroyedComponentException();
     }
 
     @Test
     public void ifDestroyedNo() throws Exception {
         final var c = new TestClass();
         c.initialize();
-        c.ifDestroyedThrowDestroyedComponentException();
+        c.checkIfDestroyedThrowDestroyedComponentException();
         c.destroy();
     }
 
     @Test(expectedExceptions = {UninitializedComponentException.class})
     public void ifNotInitializedYes() throws Exception {
         final var c = new TestClass();
-        c.ifNotInitializedThrowUninitializedComponentException();
+        c.checkIfNotInitializedThrowUninitializedComponentException();
     }
 
     @Test
     public void ifNotInitializedNo() throws Exception {
         final var c = new TestClass();
         c.initialize();
-        c.ifNotInitializedThrowUninitializedComponentException();
+        c.checkIfNotInitializedThrowUninitializedComponentException();
         c.destroy();
     }
 
@@ -46,13 +57,13 @@ public class BaseInitializableComponentTest {
     public void ifInitializedYes() throws Exception {
         final var c = new TestClass();
         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