title: How to mock a single injection in a chain of injections - Arquillian
body: <p>How can a mock of a class that is in an injection chain? For example, <strong>ServiceA</strong> injects <strong>ServiceB</strong> that injects <strong>ServiceC</strong> (<em>ServiceA -> ServiceB -> ServiceC</em>).</p>
  
  <p>In the Arquillian test I need to test <strong>ServiceA</strong> and mock <strong>ServiceC</strong>, which is called in my injection chain.</p>
  
  <p>What I want is (<em>ServiceA -> ServiceB -> Mocked(ServiceC)</em>).</p>
  
  <p>How can I do that using Arquillian?</p>
  
  <pre><code>@RunWith(Arquillian.class)
  public class ServiceATest {
  
    @Inject
    private ServiceA serviceA;
  
    public void shouldTestServiceA() {
      //Mock ServiceC.execute();
      serviceA.execute();
    }
  
  }
  
  public class ServiceA {
  
    @Inject
    private ServiceB serviceB;
  
    public void execute() {
      serviceB.execute();
    }
  
  }
  
  public class ServiceB {
  
    @Inject
    private ServiceC serviceC;
  
    public void execute() {
      serviceC.execute();
    }
  
  }
  
  //needs to be mocked
  public class ServiceC {
  
    public void execute() {
  
    }
  
  }
  </code></pre>