title: Mockito - underlying service is null
body: <p>I have a Service A which autowired Service  B and is using a method from Service B. 
  Service B autowired another Service C and is using a method from it.</p>
  
  <p>I am writing a test for Service A and the test fails at the call where Service B is invoked.At this point Service C is null.</p>
  
  <p>I have tried  @Mock for Service B. Nothing seems to work. How can i successfully test this service which is failing on a service that it isnt explicitly autowiring.</p>
  
  <pre><code>//Service A
  
  @Service
  public class FileServiceImpl{
    @Autowired
    private FileNameServiceImpl fileNameService;
  
    public void createFile(String fileName){
    String targetFileName = fileNameService.getTargetFileName(fileName);
    }
  }
  //Service B
  @Service
  public class FileNameServiceImpl{
    @Autowired
    private CustomDateService customDateService
  
    public String getTargetFileName(String fileName){
      return fileName + customDateService.getCustomDate();
      }
  }
  //CustomDate - this is an interace. The Impl is in another package.
  public interfaceCustomDateService{
   public String getCustomDate();
    }
  </code></pre>
  
  <p>I am trying to test FileServiceImpl , however it fails with a NullPointer Exception because customDateService is null.
  Even though, FileServiceImpl is not calling customDateService.</p>
  
  <p>This is what I have for test thus far: </p>
  
  <pre><code>@Category(UnitTest.class)
  @RunWith(MockitoJUnitRunner.class)
  public class FileServiceImplTest {
    @Spy
    @InjectMocks
    private FileServiceImpl fileServiceImpl;
  
     @Mock
    private FileNameServiceImpl fileNameService;
  
   @Before
   public void init() throws Exception {
      MockitoAnnotations.initMocks(this);
    }
  
    @Test
  public void testFileName() {
      String fileName = "test1.txt"; 
  
      fileServiceImpl.createFile(fileName);  // Test Fails here 
      Mockito.validateMockitoUsage();
  
  
  
  }
  </code></pre>