Skip to content

Commit

Permalink
Exceptions in runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
R. Kaleta committed Mar 21, 2020
1 parent 373e509 commit 1284689
Show file tree
Hide file tree
Showing 5 changed files with 2 additions and 19 deletions.
13 changes: 1 addition & 12 deletions src/dicontainer/DIContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ public DIContainer()
* @throws AbstractTypeException if type is an abstract class or an interface
*/
public <T> DIContainer registerType(Class<T> type)
throws AbstractTypeException
{
return registerType(type, ConstructionPolicy.CONSTRUCT);
}
Expand All @@ -38,7 +37,6 @@ public <T> DIContainer registerType(Class<T> type)
* @throws AbstractTypeException if type is an abstract class or an interface
*/
public <T> DIContainer registerType(Class<T> type, ConstructionPolicy policy)
throws AbstractTypeException
{
if(TypesContainer.isAbstractType(type))
throw new AbstractTypeException(
Expand Down Expand Up @@ -102,7 +100,6 @@ public <T> DIContainer registerInstance(Class<T> type, T instance)
* @throws DIException if type cannot be resolved
*/
public <T> T resolve(Class<T> type)
throws DIException
{
return resolveType(type, new Stack<>());
}
Expand All @@ -114,7 +111,6 @@ public <T> T resolve(Class<T> type)
* @throws DIException if instance cannot be built up
*/
public <T> T buildUp(T instance)
throws DIException
{
buildUpObject(instance, new Stack<>());

Expand All @@ -128,7 +124,6 @@ private boolean isSetter(Method method)
}

private <T> T resolveType(Class<T> type, Stack<Class<?>> resolved)
throws DIException
{
T object = typesContainer.getInstance(type);

Expand All @@ -141,7 +136,6 @@ private <T> T resolveType(Class<T> type, Stack<Class<?>> resolved)
}

private <T> T resolveConstructor(Class<T> type, Stack<Class<?>> resolved)
throws DIException
{
resolved.push(type);

Expand Down Expand Up @@ -187,7 +181,6 @@ private <T> T resolveConstructor(Class<T> type, Stack<Class<?>> resolved)
}

private <T> void resolveSetter(T object, Method setter, Stack<Class<?>> resolved)
throws DIException
{
ArrayList<Object> paramObjects = new ArrayList<>();

Expand All @@ -205,7 +198,6 @@ private <T> void resolveSetter(T object, Method setter, Stack<Class<?>> resolved
}

private <T> void buildUpObject(T obj, Stack<Class<?>> resolved)
throws DIException
{
ArrayList<Method> setters = new ArrayList<>();

Expand All @@ -215,7 +207,7 @@ private <T> void buildUpObject(T obj, Stack<Class<?>> 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);
}
Expand All @@ -225,7 +217,6 @@ private <T> void buildUpObject(T obj, Stack<Class<?>> resolved)
}

private <T> T createInstance(Constructor<? extends T> ctor, Stack<Class<?>> resolved)
throws DIException
{
ArrayList<Object> params = new ArrayList<>();

Expand All @@ -251,7 +242,6 @@ private <T> T createInstance(Constructor<? extends T> ctor, Stack<Class<?>> reso
}

private <T> Class<? extends T> findRegisteredConcreteType(Class<T> type)
throws DIException
{
Class<? extends T> subtype = type;

Expand All @@ -275,7 +265,6 @@ private <T> Class<? extends T> findRegisteredConcreteType(Class<T> type)

@SuppressWarnings("unchecked")
private <T> Constructor<? extends T>[] getConstructors(Class<? extends T> type)
throws NoSuitableConstructorException
{
Constructor<?>[] constructors;

Expand Down
3 changes: 0 additions & 3 deletions src/dicontainer/DIServiceLocator.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package dicontainer;

import dicontainer.exception.DIException;
import dicontainer.exception.EmptyContainerProviderException;

public final class DIServiceLocator
Expand All @@ -26,7 +25,6 @@ public static DIContainer getContainer()
}

public static <T> T resolve(Class<T> type)
throws DIException
{
if(!hasProvider())
throw new EmptyContainerProviderException("Container provider is empty.");
Expand All @@ -35,7 +33,6 @@ public static <T> T resolve(Class<T> type)
}

public static <T> T buildUp(T instance)
throws DIException
{
if(!hasProvider())
throw new EmptyContainerProviderException("Container provider is empty.");
Expand Down
2 changes: 0 additions & 2 deletions src/dicontainer/TypesContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -28,7 +27,6 @@ public static boolean isAbstractType(Class<?> type)

@SuppressWarnings("unchecked")
public <T> Class<? extends T> getSubtype(Class<T> type)
throws DIException
{
if(type.isAnnotationPresent(Register.class))
{
Expand Down
2 changes: 1 addition & 1 deletion src/dicontainer/exception/DIException.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package dicontainer.exception;

public class DIException
extends Exception
extends RuntimeException
{
private static final long serialVersionUID = -3019200382390630637L;

Expand Down
1 change: 0 additions & 1 deletion test/dicontainer/DIContainerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down

0 comments on commit 1284689

Please sign in to comment.