title: Null pointer on an autowired bean which is not mocked by mockito
body: <p>I have a service class that I need to unit test. The service has a upload method which in turn calls other services(autowired beans) that updates the database. I need to mock some of these services and some to execute as it is.</p>
  
  <pre><code>@Service
  public class UploadServiceImpl implements UploadService{
    @Autowired
    private ServiceA serviceA;
  
    @Autowired
    private ServiceB serviceB;
  
    public void upload(){
      serviceA.execute();
      serviceB.execute():
  
      //code...
  }
  </code></pre>
  
  <p>In the above example I need to mock ServiceA, but i would like ServiceB to run as is and perform it's function.
  My Junit test looks like this:</p>
  
  <pre><code>@RunWith(SpringJUnit4ClassRunner.class) 
  @SpringBootTest(classes=Swagger2SpringBoot.class) 
  public class UploadServiceTest {
    @Mock
    private ServiceA serviceA;
  
    @InjectMocks
    private UploadServiceImpl uploadService;
  
    @Before
    public void init() {
      MockitoAnnotations.initMocks(this);
    }
  
    @Test
    public void testUpload(){
      uploadService.upload();
  
    }
  </code></pre>
  
  <p>When I execute this I get NPE at <code>serviceB.execute();</code> in <code>UploadServiceImpl</code>.</p>
  
  <p>What could be the problem?</p>
  
  <p><strong>Note:</strong> I am not specifying the behavior of the mocked object because I don't really care and also default behavior of mocked objects are to do nothing.</p>
  
  <p>Thanks!</p>