Class 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 to true 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()
    • Constructor Detail

      • AbstractDependencyInjectionSpringContextTests

        public AbstractDependencyInjectionSpringContextTests()
        Deprecated.
        Default constructor for AbstractDependencyInjectionSpringContextTests.
    • 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., is null), dependency injection will naturally not be performed, but an informational message will be written to the log.

        Overrides:
        prepareTestInstance in class AbstractSingleSpringContextTests
        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 failure
        IllegalStateException - if the ApplicationContext for this test instance has not been configured
        See Also:
        #populateProtectedVariables()