title: how to unit test method dependent on springBoot applicationContext?
body: <p>I am trying to write a unit test for a static method which takes a class and method name and does some reflection to call the method with arguments and store the results.  I'm using <code>spring-boot</code>.</p>
  
  <p>My test actually works when I run the full suite, but when I run the test as standalone it fails. The problem is that I've created a mock class (a hand written mock, not using <code>mockito</code> or <code>easymock</code>) which I want the static method to use.  However, the reflection can not detect my mock class because the class has not been loaded into the <code>applicationContext</code> by <code>spring-boot</code>.  Here is the line that fails:</p>
  
  <pre><code>T proxy = SpringApplicationContext.getBean(clazz);
  </code></pre>
  
  <p>SpringApplicationContext definition:</p>
  
  <pre><code>@Component
  public class SpringApplicationContext implements ApplicationContextAware
  {
      private static ApplicationContext applicationContext_;
  
  @Override 
  public void setApplicationContext(ApplicationContext applicaitonContext) throws BeansException {
      applicationContext_=applicaitonContext;
  }
  
  public static &lt;T&gt; T getBean(Class&lt;T&gt; requiredType) throws beanException {
        return applicationContext_.getBean(requiredType);
  }
  </code></pre>
  
  <p>*note, I had to retype by hand, please assume obvious syntax errors are typos.</p>
  
  <p>so basically my <code>applicationContext</code> is not being set or defined. I only need one mock bean in the <code>applicationContext</code>, I could do it by hand, but is there a more <code>spring</code> approach using annotations?</p>