BAEL-2981: Updated tests

This commit is contained in:
isaolmez 2019-06-24 23:13:05 +03:00
parent ca3ef57f04
commit 2e2af71a58
4 changed files with 16 additions and 16 deletions

View File

@ -32,9 +32,9 @@ public class BasicUsageUnitTest {
public void whenParameterMapIsSupplied_thenDisplays() throws IOException { public void whenParameterMapIsSupplied_thenDisplays() throws IOException {
Handlebars handlebars = new Handlebars(); Handlebars handlebars = new Handlebars();
Template template = handlebars.compileInline("Hi {{name}}!"); Template template = handlebars.compileInline("Hi {{name}}!");
Map<String, String> parameterMap = new HashMap<>(); Map<String, String> parameterMap = new HashMap<>();
parameterMap.put("name", "Baeldung"); parameterMap.put("name", "Baeldung");
String templateString = template.apply(parameterMap); String templateString = template.apply(parameterMap);
assertThat(templateString).isEqualTo("Hi Baeldung!"); assertThat(templateString).isEqualTo("Hi Baeldung!");
@ -44,9 +44,9 @@ public class BasicUsageUnitTest {
public void whenParameterObjectIsSupplied_ThenDisplays() throws IOException { public void whenParameterObjectIsSupplied_ThenDisplays() throws IOException {
Handlebars handlebars = new Handlebars(); Handlebars handlebars = new Handlebars();
Template template = handlebars.compileInline("Hi {{name}}!"); Template template = handlebars.compileInline("Hi {{name}}!");
Person person = new Person(); Person person = new Person();
person.setName("Baeldung"); person.setName("Baeldung");
String templateString = template.apply(person); String templateString = template.apply(person);
assertThat(templateString).isEqualTo("Hi Baeldung!"); assertThat(templateString).isEqualTo("Hi Baeldung!");
@ -56,10 +56,10 @@ public class BasicUsageUnitTest {
public void whenMultipleParametersAreSupplied_ThenDisplays() throws IOException { public void whenMultipleParametersAreSupplied_ThenDisplays() throws IOException {
Handlebars handlebars = new Handlebars(); Handlebars handlebars = new Handlebars();
Template template = handlebars.compileInline("Hi {{name}}! This is {{topic}}."); Template template = handlebars.compileInline("Hi {{name}}! This is {{topic}}.");
Map<String, String> parameterMap = new HashMap<>(); Map<String, String> parameterMap = new HashMap<>();
parameterMap.put("name", "Baeldung"); parameterMap.put("name", "Baeldung");
parameterMap.put("topic", "Handlebars"); parameterMap.put("topic", "Handlebars");
String templateString = template.apply(parameterMap); String templateString = template.apply(parameterMap);
assertThat(templateString).isEqualTo("Hi Baeldung! This is Handlebars."); assertThat(templateString).isEqualTo("Hi Baeldung! This is Handlebars.");
@ -69,8 +69,8 @@ public class BasicUsageUnitTest {
public void whenNoLoaderIsGiven_ThenSearchesClasspath() throws IOException { public void whenNoLoaderIsGiven_ThenSearchesClasspath() throws IOException {
Handlebars handlebars = new Handlebars(); Handlebars handlebars = new Handlebars();
Template template = handlebars.compile("greeting"); Template template = handlebars.compile("greeting");
Person person = getPerson("Baeldung"); Person person = getPerson("Baeldung");
String templateString = template.apply(person); String templateString = template.apply(person);
assertThat(templateString).isEqualTo("Hi Baeldung!"); assertThat(templateString).isEqualTo("Hi Baeldung!");
@ -81,8 +81,8 @@ public class BasicUsageUnitTest {
TemplateLoader loader = new ClassPathTemplateLoader("/handlebars", ".html"); TemplateLoader loader = new ClassPathTemplateLoader("/handlebars", ".html");
Handlebars handlebars = new Handlebars(loader); Handlebars handlebars = new Handlebars(loader);
Template template = handlebars.compile("greeting"); Template template = handlebars.compile("greeting");
Person person = getPerson("Baeldung"); Person person = getPerson("Baeldung");
String templateString = template.apply(person); String templateString = template.apply(person);
assertThat(templateString).isEqualTo("Hi Baeldung!"); assertThat(templateString).isEqualTo("Hi Baeldung!");
@ -94,8 +94,8 @@ public class BasicUsageUnitTest {
TemplateLoader secondLoader = new ClassPathTemplateLoader("/templates", ".html"); TemplateLoader secondLoader = new ClassPathTemplateLoader("/templates", ".html");
Handlebars handlebars = new Handlebars().with(firstLoader, secondLoader); Handlebars handlebars = new Handlebars().with(firstLoader, secondLoader);
Template template = handlebars.compile("greeting"); Template template = handlebars.compile("greeting");
Person person = getPerson("Baeldung"); Person person = getPerson("Baeldung");
String templateString = template.apply(person); String templateString = template.apply(person);
assertThat(templateString).isEqualTo("Hi Baeldung!"); assertThat(templateString).isEqualTo("Hi Baeldung!");

View File

@ -22,9 +22,9 @@ public class BuiltinHelperUnitTest {
public void whenUsedWith_ThenContextChanges() throws IOException { public void whenUsedWith_ThenContextChanges() throws IOException {
Handlebars handlebars = new Handlebars(templateLoader); Handlebars handlebars = new Handlebars(templateLoader);
Template template = handlebars.compile("with"); Template template = handlebars.compile("with");
Person person = getPerson("Baeldung"); Person person = getPerson("Baeldung");
person.getAddress().setStreet("World"); person.getAddress().setStreet("World");
String templateString = template.apply(person); String templateString = template.apply(person);
assertThat(templateString).isEqualTo("\n<h4>I live in World</h4>\n"); assertThat(templateString).isEqualTo("\n<h4>I live in World</h4>\n");
@ -34,9 +34,9 @@ public class BuiltinHelperUnitTest {
public void whenUsedWithMustacheStyle_ThenContextChanges() throws IOException { public void whenUsedWithMustacheStyle_ThenContextChanges() throws IOException {
Handlebars handlebars = new Handlebars(templateLoader); Handlebars handlebars = new Handlebars(templateLoader);
Template template = handlebars.compile("with_mustache"); Template template = handlebars.compile("with_mustache");
Person person = getPerson("Baeldung"); Person person = getPerson("Baeldung");
person.getAddress().setStreet("World"); person.getAddress().setStreet("World");
String templateString = template.apply(person); String templateString = template.apply(person);
assertThat(templateString).isEqualTo("\n<h4>I live in World</h4>\n"); assertThat(templateString).isEqualTo("\n<h4>I live in World</h4>\n");
@ -46,12 +46,12 @@ public class BuiltinHelperUnitTest {
public void whenUsedEach_ThenIterates() throws IOException { public void whenUsedEach_ThenIterates() throws IOException {
Handlebars handlebars = new Handlebars(templateLoader); Handlebars handlebars = new Handlebars(templateLoader);
Template template = handlebars.compile("each"); Template template = handlebars.compile("each");
Person person = getPerson("Baeldung"); Person person = getPerson("Baeldung");
Person friend1 = getPerson("Java"); Person friend1 = getPerson("Java");
Person friend2 = getPerson("Spring"); Person friend2 = getPerson("Spring");
person.getFriends().add(friend1); person.getFriends().add(friend1);
person.getFriends().add(friend2); person.getFriends().add(friend2);
String templateString = template.apply(person); String templateString = template.apply(person);
assertThat(templateString).isEqualTo("\n<span>Java is my friend.</span>\n" assertThat(templateString).isEqualTo("\n<span>Java is my friend.</span>\n"
@ -62,12 +62,12 @@ public class BuiltinHelperUnitTest {
public void whenUsedEachMustacheStyle_ThenIterates() throws IOException { public void whenUsedEachMustacheStyle_ThenIterates() throws IOException {
Handlebars handlebars = new Handlebars(templateLoader); Handlebars handlebars = new Handlebars(templateLoader);
Template template = handlebars.compile("each_mustache"); Template template = handlebars.compile("each_mustache");
Person person = getPerson("Baeldung"); Person person = getPerson("Baeldung");
Person friend1 = getPerson("Java"); Person friend1 = getPerson("Java");
Person friend2 = getPerson("Spring"); Person friend2 = getPerson("Spring");
person.getFriends().add(friend1); person.getFriends().add(friend1);
person.getFriends().add(friend2); person.getFriends().add(friend2);
String templateString = template.apply(person); String templateString = template.apply(person);
assertThat(templateString).isEqualTo("\n<span>Java is my friend.</span>\n" assertThat(templateString).isEqualTo("\n<span>Java is my friend.</span>\n"
@ -78,9 +78,9 @@ public class BuiltinHelperUnitTest {
public void whenUsedIf_ThenPutsCondition() throws IOException { public void whenUsedIf_ThenPutsCondition() throws IOException {
Handlebars handlebars = new Handlebars(templateLoader); Handlebars handlebars = new Handlebars(templateLoader);
Template template = handlebars.compile("if"); Template template = handlebars.compile("if");
Person person = getPerson("Baeldung"); Person person = getPerson("Baeldung");
person.setBusy(true); person.setBusy(true);
String templateString = template.apply(person); String templateString = template.apply(person);
assertThat(templateString).isEqualTo("\n<h4>Baeldung is busy.</h4>\n"); assertThat(templateString).isEqualTo("\n<h4>Baeldung is busy.</h4>\n");
@ -90,9 +90,9 @@ public class BuiltinHelperUnitTest {
public void whenUsedIfMustacheStyle_ThenPutsCondition() throws IOException { public void whenUsedIfMustacheStyle_ThenPutsCondition() throws IOException {
Handlebars handlebars = new Handlebars(templateLoader); Handlebars handlebars = new Handlebars(templateLoader);
Template template = handlebars.compile("if_mustache"); Template template = handlebars.compile("if_mustache");
Person person = getPerson("Baeldung"); Person person = getPerson("Baeldung");
person.setBusy(true); person.setBusy(true);
String templateString = template.apply(person); String templateString = template.apply(person);
assertThat(templateString).isEqualTo("\n<h4>Baeldung is busy.</h4>\n"); assertThat(templateString).isEqualTo("\n<h4>Baeldung is busy.</h4>\n");

View File

@ -31,8 +31,8 @@ public class CustomHelperUnitTest {
} }
}); });
Template template = handlebars.compile("person"); Template template = handlebars.compile("person");
Person person = getPerson("Baeldung"); Person person = getPerson("Baeldung");
String templateString = template.apply(person); String templateString = template.apply(person);
assertThat(templateString).isEqualTo("Baeldung - busy"); assertThat(templateString).isEqualTo("Baeldung - busy");
@ -43,8 +43,8 @@ public class CustomHelperUnitTest {
Handlebars handlebars = new Handlebars(templateLoader); Handlebars handlebars = new Handlebars(templateLoader);
handlebars.registerHelpers(new HelperSource()); handlebars.registerHelpers(new HelperSource());
Template template = handlebars.compile("person"); Template template = handlebars.compile("person");
Person person = getPerson("Baeldung"); Person person = getPerson("Baeldung");
String templateString = template.apply(person); String templateString = template.apply(person);
assertThat(templateString).isEqualTo("Baeldung - busy"); assertThat(templateString).isEqualTo("Baeldung - busy");

View File

@ -22,9 +22,9 @@ public class ReusingTemplatesUnitTest {
public void whenOtherTemplateIsReferenced_ThenCanReuse() throws IOException { public void whenOtherTemplateIsReferenced_ThenCanReuse() throws IOException {
Handlebars handlebars = new Handlebars(templateLoader); Handlebars handlebars = new Handlebars(templateLoader);
Template template = handlebars.compile("page"); Template template = handlebars.compile("page");
Person person = new Person(); Person person = new Person();
person.setName("Baeldung"); person.setName("Baeldung");
String templateString = template.apply(person); String templateString = template.apply(person);
assertThat(templateString).isEqualTo("<h4>Hi Baeldung!</h4>\n<p>This is the page Baeldung</p>"); assertThat(templateString).isEqualTo("<h4>Hi Baeldung!</h4>\n<p>This is the page Baeldung</p>");
@ -34,9 +34,9 @@ public class ReusingTemplatesUnitTest {
public void whenBlockIsDefined_ThenCanOverrideWithPartial() throws IOException { public void whenBlockIsDefined_ThenCanOverrideWithPartial() throws IOException {
Handlebars handlebars = new Handlebars(templateLoader); Handlebars handlebars = new Handlebars(templateLoader);
Template template = handlebars.compile("simplemessage"); Template template = handlebars.compile("simplemessage");
Person person = new Person(); Person person = new Person();
person.setName("Baeldung"); person.setName("Baeldung");
String templateString = template.apply(person); String templateString = template.apply(person);
assertThat(templateString).isEqualTo("\n<html>\n" assertThat(templateString).isEqualTo("\n<html>\n"