From cdbee5e239b9c5b7e5c396853393adceb361f2c2 Mon Sep 17 00:00:00 2001 From: James Seibel Date: Thu, 21 Jul 2022 21:25:17 -0500 Subject: [PATCH] Add a missing test case and fix a typing issue with dependencyInjector --- .../handlers/dependencyInjection/DependencyInjector.java | 8 ++++---- src/test/java/tests/DependencyInjectorTest.java | 4 +++- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/seibel/lod/core/handlers/dependencyInjection/DependencyInjector.java b/src/main/java/com/seibel/lod/core/handlers/dependencyInjection/DependencyInjector.java index abb4124e3..e11fbe721 100644 --- a/src/main/java/com/seibel/lod/core/handlers/dependencyInjection/DependencyInjector.java +++ b/src/main/java/com/seibel/lod/core/handlers/dependencyInjection/DependencyInjector.java @@ -28,7 +28,7 @@ import java.util.Map; * * @param extends IBindable and defines what interfaces this dependency handler can deal with. * @author James Seibel - * @version 2022-7-18 + * @version 2022-7-21 */ public class DependencyInjector { @@ -163,7 +163,7 @@ public class DependencyInjector * @throws ClassCastException If the dependency isn't able to be cast to type T. * (this shouldn't normally happen, unless the bound object changed somehow) */ - public ArrayList getAll(Class interfaceClass) throws ClassCastException + public ArrayList getAll(Class interfaceClass) throws ClassCastException { return getInternalLogic(interfaceClass, false); } @@ -183,7 +183,7 @@ public class DependencyInjector * (this shouldn't normally happen, unless the bound object changed somehow) */ @SuppressWarnings("unchecked") - public T get(Class interfaceClass, boolean allowIncompleteDependencies) throws ClassCastException + public T get(Class interfaceClass, boolean allowIncompleteDependencies) throws ClassCastException { return (T) getInternalLogic(interfaceClass, allowIncompleteDependencies).get(0); } @@ -193,7 +193,7 @@ public class DependencyInjector * if no dependencies have been bound the list will contain null. */ @SuppressWarnings("unchecked") - private ArrayList getInternalLogic(Class interfaceClass, boolean allowIncompleteDependencies) throws ClassCastException + private ArrayList getInternalLogic(Class interfaceClass, boolean allowIncompleteDependencies) throws ClassCastException { ArrayList dependencyList = dependencies.get(interfaceClass); if (dependencyList != null && dependencyList.size() != 0) diff --git a/src/test/java/tests/DependencyInjectorTest.java b/src/test/java/tests/DependencyInjectorTest.java index 34d09f03a..431b1c135 100644 --- a/src/test/java/tests/DependencyInjectorTest.java +++ b/src/test/java/tests/DependencyInjectorTest.java @@ -28,7 +28,7 @@ import java.util.ArrayList; /** * @author James Seibel - * @version 2022-7-20 + * @version 2022-7-21 */ public class DependencyInjectorTest { @@ -55,10 +55,12 @@ public class DependencyInjectorTest ISingletonTestOne testInterOne = TEST_SINGLETON_HANDLER.get(ISingletonTestOne.class); Assert.assertNotNull(ISingletonTestOne.class.getSimpleName() + " not bound.", testInterOne); Assert.assertEquals(ISingletonTestOne.class.getSimpleName() + " incorrect value.", testInterOne.getValue(), ConcreteSingletonTestOne.VALUE); + Assert.assertEquals(ISingletonTestOne.class.getSimpleName() + " incorrect value.", TEST_SINGLETON_HANDLER.get(ISingletonTestOne.class).getValue(), ConcreteSingletonTestOne.VALUE); ISingletonTestTwo testInterTwo = TEST_SINGLETON_HANDLER.get(ISingletonTestTwo.class); Assert.assertNotNull(ISingletonTestTwo.class.getSimpleName() + " not bound.", testInterTwo); Assert.assertEquals(ISingletonTestTwo.class.getSimpleName() + " incorrect value.", testInterTwo.getValue(), ConcreteSingletonTestTwo.VALUE); + Assert.assertEquals(ISingletonTestTwo.class.getSimpleName() + " incorrect value.", TEST_SINGLETON_HANDLER.get(ISingletonTestTwo.class).getValue(), ConcreteSingletonTestTwo.VALUE); // circular dependencies (if this throws an exception the dependency isn't set up)