de.akquinet.jbosscc.needle
Class NeedleTestcase

java.lang.Object
  extended by de.akquinet.jbosscc.needle.NeedleTestcase
Direct Known Subclasses:
AbstractNeedleTestcase, NeedleRule, NeedleTestRule

public abstract class NeedleTestcase
extends Object

Abstract test case to process and initialize all fields annotated with ObjectUnderTest. After initialization, InjectIntoMany and InjectInto annotations are processed for optional additional injections.

Supported injections are:

  1. Constructor injection
  2. Field injection
  3. Method injection

See Also:
ObjectUnderTest, InjectInto, InjectIntoMany, InjectionProvider

Constructor Summary
protected NeedleTestcase(InjectionProvider<?>... injectionProvider)
          Create an instance of NeedleTestcase with optional additional injection provider.
 
Method Summary
protected  void addInjectionProvider(InjectionProvider<?>... injectionProvider)
           
<X> X
getInjectedObject(Object key)
          Returns the injected object for the given key, or null if no object was injected with the given key.
<X extends MockProvider>
X
getMockProvider()
          Returns an instance of the configured MockProvider
protected  void initInstance(Object instance)
          Inject dependencies into the given instance.
protected  void initTestcase(Object test)
          Initialize all fields annotated with ObjectUnderTest.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NeedleTestcase

protected NeedleTestcase(InjectionProvider<?>... injectionProvider)
Create an instance of NeedleTestcase with optional additional injection provider.

Parameters:
injectionProvider - optional additional injection provider
See Also:
InjectionProvider
Method Detail

addInjectionProvider

protected final void addInjectionProvider(InjectionProvider<?>... injectionProvider)

initTestcase

protected final void initTestcase(Object test)
                           throws Exception
Initialize all fields annotated with ObjectUnderTest. Is an object under test annotated field already initialized, only the injection of dependencies will be executed. After initialization, InjectIntoMany and InjectInto annotations are processed for optional additional injections.

Parameters:
test - an instance of the test
Throws:
Exception - thrown if an initialization error occurs.

initInstance

protected final void initInstance(Object instance)
Inject dependencies into the given instance. First, all field injections are executed, if there exists an InjectionProvider for the target. Then the method injection is executed, if the injection annotations are supported.

Parameters:
instance - the instance to initialize.
Throws:
ObjectUnderTestInstantiationException

getInjectedObject

public <X> X getInjectedObject(Object key)
Returns the injected object for the given key, or null if no object was injected with the given key.

Parameters:
key - the key of the injected object, see InjectionProvider.getKey(InjectionTargetInformation)
Returns:
the injected object or null

getMockProvider

public <X extends MockProvider> X getMockProvider()
Returns an instance of the configured MockProvider

Returns:
the configured MockProvider


Copyright © 2013 akquinet AG. All Rights Reserved.