title: I am trying to do a unit test into the service layer with Mockito, JUnit 5 and Spring Boot but I get NullPointerException
body: <p>I am trying to do a unit test into the service layer with Mockito, JUnit 5 and Spring Boot but I get NullPointerException.</p>
  <p>This is my test class:</p>
  <pre><code>class UserServiceTest {
  
  @Mock
  UserRepository userRepository;
  
  @InjectMocks
  IUserService userService;
  
  UserMapper userMapper;
  
  @Test
  void when_save_user_it_should_return_user(){
      UserRequest userRequest = UserRequest.builder()
              .email(&quot;pedro@gmail.com&quot;)
              .password(&quot;123456&quot;)
              .firstName(&quot;Pedro&quot;)
              .lastName(&quot;Perez&quot;)
              .birthDate(LocalDateTime.now())
              .imageUrl(&quot;&quot;)
              .currency(&quot;170&quot;)
              .build();
      Mockito.when(userRepository.save(Mockito.any(UserEntity.class))).thenReturn(new UserEntity());
      UserEntity createdUser = userService.createUser(userRequest);
  
  
      assertThat(createdUser.getFirstName()).isSameAs(userRequest.getFirstName());
  }
  </code></pre>
  <p>}</p>
  <p>And this is my response:</p>
  <pre><code>java.lang.NullPointerException
  at com.jhapdevelopment.moneyhub.usermicroservice.services.implementations.UserServiceTest.when_save_user_it_should_return_user(UserServiceTest.java:41)
  </code></pre>
  <p>I don't understand why I get this response, I mean maybe Is it possible that be a problem with dependency</p>