From 12846891d265965bba19003b3dae3f38124d6f0b Mon Sep 17 00:00:00 2001 From: "R. Kaleta" Date: Sat, 21 Mar 2020 21:35:32 +0100 Subject: [PATCH] Exceptions in runtime --- src/dicontainer/DIContainer.java | 13 +------------ src/dicontainer/DIServiceLocator.java | 3 --- src/dicontainer/TypesContainer.java | 2 -- src/dicontainer/exception/DIException.java | 2 +- test/dicontainer/DIContainerTest.java | 1 - 5 files changed, 2 insertions(+), 19 deletions(-) diff --git a/src/dicontainer/DIContainer.java b/src/dicontainer/DIContainer.java index 6b51a03..b536ad5 100644 --- a/src/dicontainer/DIContainer.java +++ b/src/dicontainer/DIContainer.java @@ -25,7 +25,6 @@ public DIContainer() * @throws AbstractTypeException if type is an abstract class or an interface */ public DIContainer registerType(Class type) - throws AbstractTypeException { return registerType(type, ConstructionPolicy.CONSTRUCT); } @@ -38,7 +37,6 @@ public DIContainer registerType(Class type) * @throws AbstractTypeException if type is an abstract class or an interface */ public DIContainer registerType(Class type, ConstructionPolicy policy) - throws AbstractTypeException { if(TypesContainer.isAbstractType(type)) throw new AbstractTypeException( @@ -102,7 +100,6 @@ public DIContainer registerInstance(Class type, T instance) * @throws DIException if type cannot be resolved */ public T resolve(Class type) - throws DIException { return resolveType(type, new Stack<>()); } @@ -114,7 +111,6 @@ public T resolve(Class type) * @throws DIException if instance cannot be built up */ public T buildUp(T instance) - throws DIException { buildUpObject(instance, new Stack<>()); @@ -128,7 +124,6 @@ private boolean isSetter(Method method) } private T resolveType(Class type, Stack> resolved) - throws DIException { T object = typesContainer.getInstance(type); @@ -141,7 +136,6 @@ private T resolveType(Class type, Stack> resolved) } private T resolveConstructor(Class type, Stack> resolved) - throws DIException { resolved.push(type); @@ -187,7 +181,6 @@ private T resolveConstructor(Class type, Stack> resolved) } private void resolveSetter(T object, Method setter, Stack> resolved) - throws DIException { ArrayList paramObjects = new ArrayList<>(); @@ -205,7 +198,6 @@ private void resolveSetter(T object, Method setter, Stack> resolved } private void buildUpObject(T obj, Stack> resolved) - throws DIException { ArrayList setters = new ArrayList<>(); @@ -215,7 +207,7 @@ private void buildUpObject(T obj, Stack> resolved) if(!isSetter(m)) throw new IncorrectDependencySetterException( "Dependency method must have exactly one argument, void return type " - + "and name starting with \'set\'."); + + "and name starting with 'set'."); setters.add(m); } @@ -225,7 +217,6 @@ private void buildUpObject(T obj, Stack> resolved) } private T createInstance(Constructor ctor, Stack> resolved) - throws DIException { ArrayList params = new ArrayList<>(); @@ -251,7 +242,6 @@ private T createInstance(Constructor ctor, Stack> reso } private Class findRegisteredConcreteType(Class type) - throws DIException { Class subtype = type; @@ -275,7 +265,6 @@ private Class findRegisteredConcreteType(Class type) @SuppressWarnings("unchecked") private Constructor[] getConstructors(Class type) - throws NoSuitableConstructorException { Constructor[] constructors; diff --git a/src/dicontainer/DIServiceLocator.java b/src/dicontainer/DIServiceLocator.java index 6058b13..875f3e3 100644 --- a/src/dicontainer/DIServiceLocator.java +++ b/src/dicontainer/DIServiceLocator.java @@ -1,6 +1,5 @@ package dicontainer; -import dicontainer.exception.DIException; import dicontainer.exception.EmptyContainerProviderException; public final class DIServiceLocator @@ -26,7 +25,6 @@ public static DIContainer getContainer() } public static T resolve(Class type) - throws DIException { if(!hasProvider()) throw new EmptyContainerProviderException("Container provider is empty."); @@ -35,7 +33,6 @@ public static T resolve(Class type) } public static T buildUp(T instance) - throws DIException { if(!hasProvider()) throw new EmptyContainerProviderException("Container provider is empty."); diff --git a/src/dicontainer/TypesContainer.java b/src/dicontainer/TypesContainer.java index 66c1570..5151ceb 100644 --- a/src/dicontainer/TypesContainer.java +++ b/src/dicontainer/TypesContainer.java @@ -9,7 +9,6 @@ import dicontainer.annotation.Register; import dicontainer.annotation.SelfRegister; import dicontainer.exception.AbstractTypeException; -import dicontainer.exception.DIException; import dicontainer.exception.NotDerivedTypeException; final class TypesContainer @@ -28,7 +27,6 @@ public static boolean isAbstractType(Class type) @SuppressWarnings("unchecked") public Class getSubtype(Class type) - throws DIException { if(type.isAnnotationPresent(Register.class)) { diff --git a/src/dicontainer/exception/DIException.java b/src/dicontainer/exception/DIException.java index 42bc99a..9fe7587 100644 --- a/src/dicontainer/exception/DIException.java +++ b/src/dicontainer/exception/DIException.java @@ -1,7 +1,7 @@ package dicontainer.exception; public class DIException - extends Exception + extends RuntimeException { private static final long serialVersionUID = -3019200382390630637L; diff --git a/test/dicontainer/DIContainerTest.java b/test/dicontainer/DIContainerTest.java index 4d41747..54ba4fe 100644 --- a/test/dicontainer/DIContainerTest.java +++ b/test/dicontainer/DIContainerTest.java @@ -480,7 +480,6 @@ public void registerInstance_WhenDerivedConcreteClass_ThenRegisteredInstance() @Test public void registerInstance_WhenInstanceIsNull_ThenNullInstanceException() - throws IllegalArgumentException { Assertions.assertThrows(NullInstanceException.class, () -> testObject.registerInstance( ClassConstructorsDefaultAndParameter.class, null));