title: Spring Boot test mock bean
body: <p>How mock 2 beans when one is into second ?</p>
  
  <pre><code>public class A {
  ...
  }
  
  public class B {
  private A a;
  }
  </code></pre>
  
  <p>I tried:</p>
  
  <pre><code>@MockBean 
  private A a;
  
  @InjectMocks 
  private B b;
  
  @Before
  public void executedBeforeEach() {
  MockitoAnnotations.initMocks(this);
  }
  </code></pre>
  
  <p>but had exception:</p>
  
  <pre><code>org.mockito.exceptions.base.MockitoException: 
  Cannot instantiate @InjectMocks field named 'B'.
  You haven't provided the instance at field declaration so I tried to     construct the instance.
  However, I failed because: the type 'B' is an interface.
  </code></pre>
  
  <p>spring version:</p>
  
  <pre><code>&lt;parent&gt;
      &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
      &lt;artifactId&gt;spring-boot-starter-parent&lt;/artifactId&gt;
      &lt;version&gt;1.5.8.RELEASE&lt;/version&gt;
      &lt;relativePath/&gt;
  &lt;/parent&gt;
  </code></pre>
  
  <p>test dependency:</p>
  
  <pre><code>&lt;dependencies&gt;
  ...
  &lt;dependency&gt;
     &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
     &lt;artifactId&gt;spring-boot-starter-test&lt;/artifactId&gt;
      &lt;scope&gt;test&lt;/scope&gt;
      &lt;/dependency&gt;
   &lt;/dependencies&gt;
  </code></pre>
  
  <p>how to do it right  ?where did I make a mistake ?</p>