title: Thymeleaf 3 with Spring Boot 2, unable to process template
body: <p>Before reading, please note that I am new to Thymeleaf, Spring, and Mockito. So I'm expecting that there is some amateur mistake that I'm making.</p>
  
  <p>I am writing code to send emails using thymeleaf HTML templates. I have been looking at different tutorials online and trying to set everything up. I think that my setup is fine, however when I write a test to check that the template is being processed, I get back "null" instead of some form of string. </p>
  
  <p>I have placed a template file in both: src/main/resources/templates and src/test/resources/templates</p>
  
  <p>The file name is email.html</p>
  
  <p>The following is my code to configure the template engine and resolver.</p>
  
  <pre><code>    @Configuration
      public class SpringMailConfig{
  ...
      @Bean
          public SpringTemplateEngine springTemplateEngine(){
              SpringTemplateEngine templateEngine = new SpringTemplateEngine();
              templateEngine.addTemplateResolver(htmlTemplateResolver());
              templateEngine.setTemplateEngineMessageSource(emailMessageSource());
              return templateEngine;
          }
  
          @Bean
          public SpringResourceTemplateResolver htmlTemplateResolver() {
              SpringResourceTemplateResolver templateResolver = new SpringResourceTemplateResolver();
              templateResolver.setPrefix("/templates/");
              templateResolver.setSuffix(".html");
              templateResolver.setTemplateMode(TemplateMode.HTML);
              templateResolver.setCharacterEncoding(StandardCharsets.UTF_8.name());
              return templateResolver;
          }
  ...
      }
  </code></pre>
  
  <p>This is the class in which I want to process the template, I'm only showing what I think is important for this question. </p>
  
  <pre><code>@Component
  public class EmailServiceHelper {
  
      @Autowired
      public SpringTemplateEngine springTemplateEngine;
  
     private  Context prepareContext(Locale locale, Map&lt;String, Object&gt; contextMap){
          final Context context = new Context(locale);
          context.setVariables(contextMap);
          return context;
      }
  
      //returns as a string the template with the custom values inserted
      private String returnHtmlContent(String templatePath, Locale locale, Map&lt;String,Object&gt; map){
          Context ctx = prepareContext(locale, map);
          return springTemplateEngine.process(templatePath, ctx);
      }
  
  }
  </code></pre>
  
  <p>And this is the test class (part of it) in which I get the error, that springTemplateEngine.process(templatePath, ctx) is returning null.</p>
  
  <pre><code>@RunWith(MockitoJUnitRunner.class )
  public class EmailServiceHelperTest {
  @Mock
      SpringTemplateEngine springTemplateEngine;
  
      @Mock
      SpringResourceTemplateResolver springResourceTemplateResolver;
  @InjectMocks
  EmailServiceHelper helper;
  
     @Before
      public void setup(){
  
          MockitoAnnotations.initMocks(this);
          helper = new EmailServiceHelper();
          helper.springTemplateEngine = springTemplateEngine;
      helper.springTemplateEngine.setTemplateResolver(springResourceTemplateResolver);
      }
  
  @Test
      public void testTemplateMessageHasContent(){
          try {
              Locale locale = new Locale("en");
              Map&lt;String, Object&gt; contextMap = new HashMap&lt;&gt;();
              contextMap.put("name", "Test name");
              MimeMessage message = helper.prepareMimeMessage(mail, mailSender, contextMap, "email", locale);
              assertNotNull(message.getContent());
          }catch (MessagingException | IOException e){
              e.printStackTrace();
              fail("Testing if template message has content failed!");
          }
      }
  }
  </code></pre>
  
  <p>This is what my email template looks like.</p>
  
  <pre><code>&lt;html xmlns:th="http://www.thymeleaf.org"&gt;
  &lt;head&gt;
      &lt;title&gt;TEMPLATE&lt;/title&gt;
      &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;h1 th:text="${name}"&gt;Hello, Static Person!&lt;/h1&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>