title: Java Spring + Maven Testing Error : Request processing failed; nested exception is java.lang.NullPointerException
body: <p>I am trying to test a get method but I receive this error unfortunately: </p>
  
  <p>org.springframework.web.util.NestedServletException: Request processing failed; nested exception is java.lang.NullPointerException</p>
  
  <p>I am new to this and I really have no idea what I'm doing wrong. I autowired so I don't see where is the problem:</p>
  
  <pre><code>@RestController
  public class RegisterController {
  
  
  @Autowired
  private UserService userService;
  @Autowired
  private SmtpMailSender smtpMailSender;
  @Autowired
  private ConfirmEmailServiceImpl confirmEmailService;
  
  @RequestMapping(value="/register/validate",method = RequestMethod.GET)
  public ResponseEntity&lt;String&gt; checkEmailCode(String email,String code) {
  
      ConfirmEmail confirmEmail=new ConfirmEmail();
      confirmEmail=confirmEmailService.findEmail(email);
      if(confirmEmail!=null &amp;&amp; confirmEmail.getCode().compareTo(code)==0) {
              User user=userService.findByEmail(email);
              user.setActive(true);
              userService.save(user);
              return new ResponseEntity&lt;String&gt;("Correct",HttpStatus.OK);
          }
          else
              return  new ResponseEntity&lt;String&gt;("Wrong",HttpStatus.valueOf("Wrong code"));
  
  }
  
  
  
  
  }
  
  
  
  
  public class RegisterControllerTest {
  @InjectMocks
  private RegisterController controller;
  
  private MockMvc mockMvc;
  
  @Before
  public void setup(){
  
      MockitoAnnotations.initMocks(this);
  
      mockMvc = MockMvcBuilders.standaloneSetup(controller).build();
  }
  
  @Test
  public void test() throws Exception {
  
      mockMvc.perform(get("/register/validate")).andDo(print());
  
  }
  </code></pre>
  
  <p>}</p>
  
  <p>When I try to run the test I get the error</p>