title: How to add inner classes to Spring application context for Unit Testing?
body: <p>I have a bean whose business logic loads beans of a certain type from the ApplicationContext in order to process them.</p>
  
  <p>For my jUnit tests, I would like to create some dummy beans within my unit test class and see if my bean under test properly processes them.  However, I am not sure what the best way to accomplish this is.</p>
  
  <p>If I just declare my inner class within my test class, Spring will not have it as part of its application context.  I realize that I could inject my application context within my jUnit class, and then use appContext.registerPrototype() to add it, however, I thought there might be a cleaner way using annotations.</p>
  
  <p>I've tried to annotate the internal class with @Component, but not surprisingly, it did not work.</p>
  
  <pre><code>public class PatchEngineTest extends TestBase {
      @Component
      protected class Patch1 extends PatchBaseImpl implements Patch{
          public void applyPatch() throws Exception {
              // does nothing
          }
      }
  
  
      @Autowired PatchRepository patchRepository;
      @Autowired Patch1 patch1;
  
      @Test
      public void test() {
          fail("Not yet implemented");
      }
  
  }
  </code></pre>
  
  <p>Not surprisingly, I get the following error message:</p>
  
  <pre><code>Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.ia.patch.PatchEngineTest$Patch1] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
  </code></pre>
  
  <p>Is there any way of doing this?</p>