Class AbstractDependencyInjectionSpringContextTests
- java.lang.Object
-
- org.junit.Assert
-
- org.springframework.test.AbstractSpringContextTests
-
- org.springframework.test.AbstractSingleSpringContextTests
-
- org.springframework.test.AbstractDependencyInjectionSpringContextTests
-
- Direct Known Subclasses:
TeamCitySpringTestBase
@Deprecated public abstract class AbstractDependencyInjectionSpringContextTests extends AbstractSingleSpringContextTests
Deprecated.as of Spring 3.0, in favor of using the listener-based test context framework (org.springframework.test.context.junit38.AbstractJUnit38SpringContextTests
)Convenient superclass for JUnit 3.8 based tests depending on a Spring context. The test instance itself is populated by Dependency Injection.
Really for integration testing, not unit testing. You should not normally use the Spring container for unit tests: simply populate your POJOs in plain JUnit tests!
This supports two modes of populating the test:
- Via Setter Dependency Injection. Simply express dependencies on objects in the test fixture, and they will be satisfied by autowiring by type.
- Via Field Injection. Declare protected variables of the required type
which match named beans in the context. This is autowire by name, rather than
type. This approach is based on an approach originated by Ara Abrahmian.
Setter Dependency Injection is the default: set the
populateProtectedVariables
property totrue
in the constructor to switch on Field Injection.
- Since:
- 1.1.1
- Author:
- Rod Johnson, Rob Harrop, Rick Evans, Sam Brannen
- See Also:
AbstractSingleSpringContextTests.setDirty()
,AbstractSingleSpringContextTests.contextKey()
,AbstractSpringContextTests.getContext(java.lang.Object)
,AbstractSingleSpringContextTests.getConfigLocations()
-
-
Field Summary
-
Fields inherited from class org.springframework.test.AbstractSingleSpringContextTests
applicationContext
-
Fields inherited from class org.springframework.test.AbstractSpringContextTests
logger
-
-
Constructor Summary
Constructors Constructor Description AbstractDependencyInjectionSpringContextTests()
Deprecated.Default constructor for AbstractDependencyInjectionSpringContextTests.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description int
getAutowireMode()
Deprecated.Return the autowire mode for test properties set by Dependency Injection.protected void
injectDependencies()
Deprecated.Inject dependencies into 'this' instance (that is, this test instance).boolean
isDependencyCheck()
Deprecated.Return whether or not dependency checking should be performed for test properties set by Dependency Injection.protected void
prepareTestInstance()
Deprecated.Prepare this test instance, injecting dependencies into its protected fields and its bean properties.-
Methods inherited from class org.springframework.test.AbstractSingleSpringContextTests
contextKey, createApplicationContext, createBeanDefinitionReader, customizeBeanFactory, getApplicationContext, getConfigLocations, loadContext, loadContextLocations, onSetUp, onTearDown, setDirty, setUp, tearDown
-
Methods inherited from class org.springframework.test.AbstractSpringContextTests
contextKeyString, getContext, getContextKeyToContextMap, isContextKeyEmpty, setDirty
-
Methods inherited from class org.junit.Assert
assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertFalse, assertFalse, assertNotEquals, assertNotEquals, assertNotEquals, assertNotEquals, assertNotEquals, assertNotEquals, assertNotEquals, assertNotEquals, assertNotNull, assertNotNull, assertNotSame, assertNotSame, assertNull, assertNull, assertSame, assertSame, assertThat, assertThat, assertThrows, assertThrows, assertTrue, assertTrue, fail, fail
-
-
-
-
Method Detail
-
getAutowireMode
public final int getAutowireMode()
Deprecated.Return the autowire mode for test properties set by Dependency Injection.
-
isDependencyCheck
public final boolean isDependencyCheck()
Deprecated.Return whether or not dependency checking should be performed for test properties set by Dependency Injection.
-
prepareTestInstance
protected void prepareTestInstance() throws Exception
Deprecated.Prepare this test instance, injecting dependencies into its protected fields and its bean properties.Note: if the
ApplicationContext
for this test instance has not been configured (e.g., isnull
), dependency injection will naturally not be performed, but an informational message will be written to the log.- Overrides:
prepareTestInstance
in classAbstractSingleSpringContextTests
- Throws:
Exception
- in case of preparation failure- See Also:
injectDependencies()
-
injectDependencies
protected void injectDependencies() throws Exception
Deprecated.Inject dependencies into 'this' instance (that is, this test instance).The default implementation populates protected variables if the
appropriate flag is set
, else uses autowiring if autowiring is switched on (which it is by default).Override this method if you need full control over how dependencies are injected into the test instance.
- Throws:
Exception
- in case of dependency injection failureIllegalStateException
- if theApplicationContext
for this test instance has not been configured- See Also:
#populateProtectedVariables()
-
-