title: JUnit - java.lang.NullPointerException: Cannot invoke "..." because "this.modelMapper" is null
body: <p>I've been learning Java for about 4 months, so please excuse basic mistakes.</p>
  <p>I'm trying to unit test a method from my Service layer:</p>
  <pre><code>    @Override
      @Transactional
      public List&lt;StudentDto&gt; getStudentList() {
          List&lt;Student&gt; tempList = studentDAO.getStudentList();
  
          List&lt;StudentDto&gt; tempListStudentDto = new ArrayList&lt;&gt;();
  
          for (Student theStudent: tempList) {
              tempListStudentDto.add(convertToDto(theStudent));
          }
  
          return tempListStudentDto;
      }
  </code></pre>
  <p>With this @Test:</p>
  <pre><code>    // JUnit test for getStudentList()
      @Test
      @DisplayName(&quot;getStudentList()&quot;)
      public void givenStudentList_whenGettingList_thenReturnList() {
          // given -precondition
          BDDMockito.given(studentDao.getStudentList())
                  .willReturn(List.of(newStudentOne, newStudentTwo));
  
          // when - behaviour that we are going to test
  
          List&lt;StudentDto&gt; studentList = studentService.getStudentList();
  
          // then - verify the output
          assertAll(
                  () -&gt; org.assertj.core.api.Assertions.assertThat(studentList).isNotNull(),
                  () -&gt; org.assertj.core.api.Assertions.assertThat(studentList).size().isEqualTo(2)
          );
  </code></pre>
  <p>And I'm constantly getting this error:
  java.lang.NullPointerException: Cannot invoke &quot;org.modelmapper.ModelMapper.getConfiguration()&quot; because &quot;this.modelMapper&quot; is null</p>
  <p>Could you please help me here or tell me how to convert the Student class to DTO in a testable way?</p>
  <p>I've googled the issue and tried all of the suggestions, but could not make it to work.</p>