title: Spring/Mockito Junit testing Null Pointer Exception
body: <p>Trying to get JUnit with mockito testing to work and getting a NPE on my test here. I'm wanting to have a verify that when <code>createRegistrant(registrationDTO)</code> is called, <code>saveUpdateRegistration(Registration reg)</code> method is called right after. An issue I find strange is that on <code>Mockito.verify(registrationServiceImpl, Mockito.times(1)).createRegistrant(registrationDTO);</code> it is not suggesting I can test if <code>saveUpdateRegistration(Registration reg)</code> method was called? IntelliJ only suggests methods that are in my interface?</p>
  
  <p>My test code below:</p>
  
  <pre><code>@RunWith(MockitoJUnitRunner.class)
  public class RegistrationServiceImplTest {
  
      @InjectMocks
      private RegistrationServiceImpl registrationServiceImpl;
  
      @Mock
      private RegistrationDTO registrationDTO;
  
      @Mock
      private Registration registration;
  
  
      @Before
      public void setup() {
          registrationDTO.seteId("abc123");
          registrationDTO.setTech("AWS");
          registrationDTO.setFirstName("Bob");
          registrationDTO.setLastName("Tom");
  
      }
  
  
      @Test
      public void createRegistrant() throws Exception {
  //        Mockito.when(registrationServiceImpl.createRegistrant(registrationDTO)).thenReturn(registrationDTO);
          Mockito.when(registrationServiceImpl.createRegistrant(registrationDTO)).thenReturn(registrationDTO);
          registrationServiceImpl.createRegistrant(registrationDTO);
          Mockito.verify(registrationServiceImpl, Mockito.times(1)).createRegistrant(registrationDTO);
      }
  </code></pre>
  
  <p>Here is the code I'm testing: </p>
  
  <pre><code>package com.TechODex.service;
  
  import com.TechODex.dto.RegistrationDTO;
  import com.TechODex.model.Registration;
  import com.TechODex.dao.RegistrationDAO;
  
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.stereotype.Service;
  import org.springframework.transaction.annotation.Transactional;
  
  import java.util.List;
  
  @Service
  @Transactional
  public class RegistrationServiceImpl implements RegistrationService {
  
      @Autowired
      private RegistrationDAO registrationDAO;
  
      public RegistrationDTO createRegistrant(RegistrationDTO reg) {
          saveUpdateRegistration(setDTOToModel(reg));
          return reg;
      }
      public void deleteRegistrant(Long id) { deleteUserRegistrant(id); }
      public List&lt;Registration&gt; findAllRegistrant(String tech) { return findAllRegistrantDAO(tech);}
      public List&lt;Registration&gt; findAllTech() { return findAllTechDAO();}
  
  
      private Registration setDTOToModel(RegistrationDTO dto){
          Registration registration = new Registration();
  
          registration.setFirstName(dto.getFirstName());
          registration.setLastName(dto.getLastName());
          registration.seteId(dto.geteId());
          registration.setTech(dto.getTech());
  
          return registration;
      }
  
      private void saveUpdateRegistration(Registration reg){ registrationDAO.save(reg);}
  
  }
  </code></pre>