/
NikolayIvkin
/
tutorials1
Обзор
Документация
Войти
/
NikolayIvkin
/
tutorials1
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
libraries-2/src/test/java/com/baeldung/handlebars/ReusingTemplatesUnitTest.java
51 строка
2 KB
Krzysiek
BAEL-20602: Use contains instead of verifying strings' equality
09 фев 2020, 01:32
09 фев 2020, 01:32
733c46d
Код
Авторство
О чём код?
package com.baeldung.handlebars; import com.github.jknack.handlebars.Handlebars; import com.github.jknack.handlebars.Template; import com.github.jknack.handlebars.io.ClassPathTemplateLoader; import com.github.jknack.handlebars.io.TemplateLoader; import org.junit.Test; import java.io.IOException; import static org.assertj.core.api.Assertions.assertThat; /** * Showcases reusing the existing templates. * * @author isaolmez */ public class ReusingTemplatesUnitTest { private TemplateLoader templateLoader = new ClassPathTemplateLoader("/handlebars", ".html"); @Test public void whenOtherTemplateIsReferenced_ThenCanReuse() throws IOException { Handlebars handlebars = new Handlebars(templateLoader); Template template = handlebars.compile("page"); Person person = new Person(); person.setName("Baeldung"); String templateString = template.apply(person); assertThat(templateString) .contains("<h4>Hi Baeldung!</h4>", "<p>This is the page Baeldung</p>"); } @Test public void whenBlockIsDefined_ThenCanOverrideWithPartial() throws IOException { Handlebars handlebars = new Handlebars(templateLoader); Template template = handlebars.compile("simplemessage"); Person person = new Person(); person.setName("Baeldung"); String templateString = template.apply(person); assertThat(templateString).contains("<html>", "<body>", "This is the intro", "Hi there!", "</body>", "</html>"); } }