title: Model Mapper Get Null Pointer Exception When Calling Method on Testing Class
body: <p>When I call the model mapper Entity to DTO converter method I always get null pointer exception.</p>
  <p>This is converter service to convert dto to entity and vice versa</p>
  <p>I have not deal with DTO previously and this is the first time I use DTO and I also need to know is this the best way I've implemented DTO converter service or if there is any suggestions.</p>
  <pre><code>@Autowired
  private ModelMapper modelMapper;
  
  @Bean
  public ModelMapper modelMapper() {
      return new ModelMapper();
  }
  
  @Override
  public NotificationDto entityToDtoNotification(Notification notification) {
      ModelMapper mapper = new ModelMapper();
      return mapper.map(notification, NotificationDto.class);
      
  }
  
  @Override
  public Notification dtoToEntityNotification(NotificationDto notificationDto) {
  
      ModelMapper mapper = new ModelMapper();
      return mapper.map(notificationDto, Notification.class);
  
  }
  </code></pre>
  <p>When I call the method on test calls I get null value</p>
  <pre><code>class NotificationServiceImplTest {
  
      @Autowired
      private NotificationServiceImpl notificationService;
  
      @MockBean
      private NotificationRepository notificationRepository;
  
      @Autowired
      ConverterServiceImpl converterService;
  
      @Test
      public void testCreateTicket() {
  
          Notification notification = new Notification();
          notification.setId(1);
          notification.setMessage(&quot;Hello Hashan&quot;);
  
  
          NotificationDto notificationDto = new NotificationDto();
  
           
          //I get the null value as return
  
          notificationDto=converterService.entityToDtoNotification(notification);
  
  
  
          Mockito.when(notificationRepository.save(notification)).thenReturn(notification);
          
          assertThat(notificationService.save(notificationDto)).isEqualTo(notification);
  
          converterService.entityToDtoNotification(notification);
      }
  
  
  }
  </code></pre>
  <p>Notification Entity</p>
  <pre><code>@Entity
  @Table(name = &quot;notification&quot;)
  public class Notification {
  
      @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      private int id;
      private String message;
  
  
      public int getId() {
          return id;
      }
  
      public void setId(int id) {
          this.id = id;
      }
  
      public String getMessage() {
          return message;
      }
  
      public void setMessage(String message) {
          this.message = message;
      }
  
      public Notification() {
      }
  
      public Notification(int id, String message) {
          this.id = id;
          this.message = message;
      }
  }
  </code></pre>
  <p>Notification DTO</p>
  <pre><code>public class NotificationDto {
  
      private int id;
      private String message;
  
      public int getId() {
          return id;
      }
  
      public void setId(int id) {
          this.id = id;
      }
  
      public String getMessage() {
          return message;
      }
  
      public void setMessage(String message) {
          this.message = message;
      }
  
      public NotificationDto(int id, String message) {
          this.id = id;
          this.message = message;
      }
  
      public NotificationDto() {
      }
  }
  </code></pre>