Class SpringRule

  • All Implemented Interfaces:
    org.junit.rules.TestRule

    public class SpringRule
    extends java.lang.Object
    implements org.junit.rules.TestRule
    Captures the ConfigurableApplicationContext from SpringSupplierSource.
    Author:
    Daniel Sagenschneider
    • Constructor Summary

      Constructors 
      Constructor Description
      SpringRule()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      org.junit.runners.model.Statement apply​(org.junit.runners.model.Statement base, org.junit.runner.Description description)  
      org.springframework.context.ConfigurableApplicationContext getApplicationContext()
      Obtains the ConfigurableApplicationContext.
      <B> B getBean​(java.lang.Class<B> requiredType)
      Obtains the Spring bean by type.
      java.lang.Object getBean​(java.lang.String name)
      Obtains the Spring bean by name.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • SpringRule

        public SpringRule()
    • Method Detail

      • getApplicationContext

        public org.springframework.context.ConfigurableApplicationContext getApplicationContext()
        Obtains the ConfigurableApplicationContext.
        Returns:
        ConfigurableApplicationContext.
      • getBean

        public java.lang.Object getBean​(java.lang.String name)
        Obtains the Spring bean by name.
        Parameters:
        name - Name of bean.
        Returns:
        Bean.
      • getBean

        public <B> B getBean​(java.lang.Class<B> requiredType)
        Obtains the Spring bean by type.
        Parameters:
        requiredType - Required type.
        Returns:
        Bean.
      • apply

        public org.junit.runners.model.Statement apply​(org.junit.runners.model.Statement base,
                                                       org.junit.runner.Description description)
        Specified by:
        apply in interface org.junit.rules.TestRule