title: Issue when unit testing a service using Thymeleaf template Engine
body: <p>I got a nullPointerException when unit testing my service and i do not understand why? I m using Spring boot.
  This is my simple service which provide Templating. I autowired TemplateEngine Component.</p>
  
  <pre><code>@Service
  public class TicketTemplatingService implements ITemplatingService{
  
      @Autowired
      private TemplateEngine templateEngine;
  
      /**
       * This method will return a ticket template
       */
      @Override
      public String buildHtmlTemplating(Object object, String templateName) {
          Ticket ticket= (Ticket)object;
          //Build the template
          Context context = new Context();
          context.setVariable("id", ticket.getId());
          context.setVariable("date", ticket.getDate());        
          return  templateEngine.process(templateName, context);
      }
  
  }
  </code></pre>
  
  <p>The unit test of this class is below:</p>
  
  <pre><code>@SpringBootTest
  @RunWith(SpringRunner.class)
  @ActiveProfiles("test")
  public class TemplatingServiceTest {
  
  
      @InjectMocks
      private TicketTemplatingService ticketTemplatingService;
  
      @Mock
      private TemplateEngine templateEngine;
  
      @Before
      public void setup(){
          MockitoAnnotations.initMocks(this);
      }
  
      @Test
      public void testHtmlTemplateReturnTheHtmlTemplate(){
          Ticket ticket= new Ticket();
          ticket.setId(1L);
          Date date=new Date();
          ticket.setDate(date);
  
          Context context=new Context();
          context.setVariable("id", 1L);
          context.setVariable("date", date);
  
          //Mock the process method of the templateEngine bean
          when(templateEngine.process("TemplateName", refEq(context))).thenReturn("Html template result");
  
          //Now we can test the method
          String htmlTemplate=ticketTemplatingService.buildHtmlTemplating(ticket, "TemplateName");
          assertThat(htmlTemplate).isEqualTo("Html template result");
      }
  }
  </code></pre>
  
  <p>In this test class, the templateEngine variable mocked return null, and then i got nullPointerException when doing this "when(templateEngine.process("TemplateName", refEq(context))).thenReturn("Html template result");"</p>
  
  <p>Please can you help me? i really do not unsderstand why.</p>