Package nl.pim16aap2.testing
Class MockInjector<T>
java.lang.Object
nl.pim16aap2.testing.MockInjector<T>
- Type Parameters:
T- The type of the class to create an instance of.
Simple class that creates real instances of a class using its constructor that is annotated with
Inject.
All arguments to the constructor are mocked instances of those classes.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionCreates a new instance of the class using the constructor annotated withInject.static <T> TinjectInto(Class<T> clz) Creates a new instance of the class using the constructor annotated withInject.
-
Constructor Details
-
MockInjector
Creates a new instance of this class.- Parameters:
clz- The class to create an instance of. This class must have a constructor annotated withInject.- Throws:
IllegalArgumentException- If no constructor annotated withInjectis found.
-
-
Method Details
-
createInstance
Creates a new instance of the class using the constructor annotated withInject.- Returns:
- The new instance.
- Throws:
RuntimeException- If an exception occurs while creating the instance.
-
injectInto
Creates a new instance of the class using the constructor annotated withInject.- Type Parameters:
T- The type of the class to create an instance of.- Parameters:
clz- The class to create an instance of. This class must have a constructor annotated withInject.- Returns:
- The new instance.
- Throws:
IllegalArgumentException- If no constructor annotated withInjectis found.RuntimeException- If an exception occurs while creating the instance.
-