title: How to mock an interface with two different implementation
body: <p>I have a class I need to test that has two instance of different class but same interface. This is how the codes looks like,</p>
  
  <p>Class to be tested:</p>
  
  <pre><code>@Service
  public class MainClass {
     @Resource(name = "aClass")
     private IClass instance1;
     @Resource(name = "bClass")
     private IClass instance2;
  }
  </code></pre>
  
  <p>Other classes:</p>
  
  <pre><code>@Service("aClass")
  public class A implements IClass {}
  
  @Service("bClass")
  public class B implements IClass {}
  </code></pre>
  
  <p>My Unit Test:</p>
  
  <pre><code>public MainClassTest {
     @InjectMocks
     private MainClass mainClass;
  
     @Mock
     private IClass instance1;
     @Mock
     private IClass instance2;
  
     @Test
     public void test() {...}
  }
  </code></pre>
  
  <p>When I run the test, both instance1 and instance2 are null since they are not mocked. This doesn't happen when the interface has only one implementation.</p>
  
  <p>Any idea how to handle this?</p>
  
  <p>Thanks,
  Angelo</p>