title: How to mock context.getBeansWithAnnotations with Mockito
body: <p>I have created an interface <strong>Client</strong> with its two concrete implementations
  clientA and clientB and annotated them with my custom annotation.</p>
  
  <pre><code>public interface Client{
      public void dosomething();
  }
  
  @Component
  @Myannotation
  public class clientA implements Client {         
      public void doSomething(){
           sysout("Client A do something");
      }
  }
  
  @Component
  @Myannotation
  public class clientB implements Client {         
      public void doSomething(){
         sysout("Client B do something");
      }
  }
  </code></pre>
  
  <p>Now I am calling the overriden methods of both clientA and clientB from Alien class.</p>
  
  <pre><code>@Component
  class Alien{
     @Autowired
     private ApplicationContext context;  
  
     public void performOperation(){
        Map&lt;String, Object&gt; beans = 
                 context.getBeansWithAnnotation(MyAnnotation.class);
        for(Map.Entry&lt;String, Object&gt; entry: beans.entrySet()) {
            Client c = (Client)entry.getValue();
            c.doSomething();
        }
  
     }
  }
  </code></pre>
  
  <p>I am facing problem with writing test method for performOperation.</p>
  
  <pre><code>@RunWith(MockitoJUnitRunner.class)
  class AlienTest
  {
     @InjectMocks
     Alien a;
  
     @Test
     public void testperformOperation(){
         //how to Mock for beans
         assertEquals(expected, a.performOperation());
     }
  }
  </code></pre>
  
  <p>1) How should I write testperformOperation method(allowed to change the return type of <strong>performOperation</strong> method from void to any other type)</p>
  
  <p>2) Is there any better way to get list of all implementations for Client interface without creating custom annotations.</p>