title: Mock JWT Utils to validate Token
body: <p>I want to create JUnkt test for this endpoint:</p>
  <pre><code>    @Autowired
      private JwtTokenProvider jwtTokenProvider;
  
      @PostMapping(&quot;reset_token&quot;)
      public ResponseEntity&lt;?&gt; resetToken(@Valid @RequestBody ResetPasswordTokenDTO resetPasswordTokenDTO, BindingResult bindResult) {
  
          final String login = jwtTokenProvider.getUsername(resetPasswordTokenDTO.getResetPasswordToken());
      }
  </code></pre>
  <p>Full code: <a href="https://github.com/rcbandit111/wiki/blob/master/src/main/java/org/engine/rest/UsersController.java#L149" rel="nofollow noreferrer">Github</a></p>
  <p>JUnit test:</p>
  <pre><code>@Test
  public void resetTokenTest_NOT_FOUND() throws Exception {
      when(usersService.findByResetPasswordToken(anyString())).thenReturn(Optional.empty());
  
      mockMvc.perform(post(&quot;/users/reset_token&quot;)
              .contentType(MediaType.APPLICATION_JSON)
              .content(ResetPasswordTokenDTO))
              .andExpect(status().isNotFound());
  }
  </code></pre>
  <p>I get NPE at this line when I run the code:</p>
  <pre><code>final String login = jwtTokenProvider.getUsername(resetPasswordTokenDTO.getResetPasswordToken());
  </code></pre>
  <p>How I can mock <a href="https://github.com/rcbandit111/wiki/blob/dc70adbe2326def1eb9c8390845fa7f2c7cfb9ad/src/main/java/org/engine/security/JwtTokenProvider.java#L27" rel="nofollow noreferrer">jwtTokenProvider</a> properly? As you can see I have a file with test <a href="https://github.com/rcbandit111/wiki/blob/dc70adbe2326def1eb9c8390845fa7f2c7cfb9ad/src/test/resources/json/ResetPasswordTokenDTO.json" rel="nofollow noreferrer">data</a> which I load but the token is not extracted. Do you know how I can fix this issue?</p>