From 2e2af71a58fff5ad98068e4c332d72438420e732 Mon Sep 17 00:00:00 2001 From: isaolmez Date: Mon, 24 Jun 2019 23:13:05 +0300 Subject: [PATCH] BAEL-2981: Updated tests --- .../com/baeldung/handlebars/BasicUsageUnitTest.java | 12 ++++++------ .../baeldung/handlebars/BuiltinHelperUnitTest.java | 12 ++++++------ .../baeldung/handlebars/CustomHelperUnitTest.java | 4 ++-- .../handlebars/ReusingTemplatesUnitTest.java | 4 ++-- 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/libraries-2/src/test/java/com/baeldung/handlebars/BasicUsageUnitTest.java b/libraries-2/src/test/java/com/baeldung/handlebars/BasicUsageUnitTest.java index bf7afa0fc9..3eb325dbb6 100644 --- a/libraries-2/src/test/java/com/baeldung/handlebars/BasicUsageUnitTest.java +++ b/libraries-2/src/test/java/com/baeldung/handlebars/BasicUsageUnitTest.java @@ -32,9 +32,9 @@ public class BasicUsageUnitTest { public void whenParameterMapIsSupplied_thenDisplays() throws IOException { Handlebars handlebars = new Handlebars(); Template template = handlebars.compileInline("Hi {{name}}!"); - Map parameterMap = new HashMap<>(); parameterMap.put("name", "Baeldung"); + String templateString = template.apply(parameterMap); assertThat(templateString).isEqualTo("Hi Baeldung!"); @@ -44,9 +44,9 @@ public class BasicUsageUnitTest { public void whenParameterObjectIsSupplied_ThenDisplays() throws IOException { Handlebars handlebars = new Handlebars(); Template template = handlebars.compileInline("Hi {{name}}!"); - Person person = new Person(); person.setName("Baeldung"); + String templateString = template.apply(person); assertThat(templateString).isEqualTo("Hi Baeldung!"); @@ -56,10 +56,10 @@ public class BasicUsageUnitTest { public void whenMultipleParametersAreSupplied_ThenDisplays() throws IOException { Handlebars handlebars = new Handlebars(); Template template = handlebars.compileInline("Hi {{name}}! This is {{topic}}."); - Map parameterMap = new HashMap<>(); parameterMap.put("name", "Baeldung"); parameterMap.put("topic", "Handlebars"); + String templateString = template.apply(parameterMap); assertThat(templateString).isEqualTo("Hi Baeldung! This is Handlebars."); @@ -69,8 +69,8 @@ public class BasicUsageUnitTest { public void whenNoLoaderIsGiven_ThenSearchesClasspath() throws IOException { Handlebars handlebars = new Handlebars(); Template template = handlebars.compile("greeting"); - Person person = getPerson("Baeldung"); + String templateString = template.apply(person); assertThat(templateString).isEqualTo("Hi Baeldung!"); @@ -81,8 +81,8 @@ public class BasicUsageUnitTest { TemplateLoader loader = new ClassPathTemplateLoader("/handlebars", ".html"); Handlebars handlebars = new Handlebars(loader); Template template = handlebars.compile("greeting"); - Person person = getPerson("Baeldung"); + String templateString = template.apply(person); assertThat(templateString).isEqualTo("Hi Baeldung!"); @@ -94,8 +94,8 @@ public class BasicUsageUnitTest { TemplateLoader secondLoader = new ClassPathTemplateLoader("/templates", ".html"); Handlebars handlebars = new Handlebars().with(firstLoader, secondLoader); Template template = handlebars.compile("greeting"); - Person person = getPerson("Baeldung"); + String templateString = template.apply(person); assertThat(templateString).isEqualTo("Hi Baeldung!"); diff --git a/libraries-2/src/test/java/com/baeldung/handlebars/BuiltinHelperUnitTest.java b/libraries-2/src/test/java/com/baeldung/handlebars/BuiltinHelperUnitTest.java index 84529a74ce..6749f7fe0a 100644 --- a/libraries-2/src/test/java/com/baeldung/handlebars/BuiltinHelperUnitTest.java +++ b/libraries-2/src/test/java/com/baeldung/handlebars/BuiltinHelperUnitTest.java @@ -22,9 +22,9 @@ public class BuiltinHelperUnitTest { public void whenUsedWith_ThenContextChanges() throws IOException { Handlebars handlebars = new Handlebars(templateLoader); Template template = handlebars.compile("with"); - Person person = getPerson("Baeldung"); person.getAddress().setStreet("World"); + String templateString = template.apply(person); assertThat(templateString).isEqualTo("\n

I live in World

\n"); @@ -34,9 +34,9 @@ public class BuiltinHelperUnitTest { public void whenUsedWithMustacheStyle_ThenContextChanges() throws IOException { Handlebars handlebars = new Handlebars(templateLoader); Template template = handlebars.compile("with_mustache"); - Person person = getPerson("Baeldung"); person.getAddress().setStreet("World"); + String templateString = template.apply(person); assertThat(templateString).isEqualTo("\n

I live in World

\n"); @@ -46,12 +46,12 @@ public class BuiltinHelperUnitTest { public void whenUsedEach_ThenIterates() throws IOException { Handlebars handlebars = new Handlebars(templateLoader); Template template = handlebars.compile("each"); - Person person = getPerson("Baeldung"); Person friend1 = getPerson("Java"); Person friend2 = getPerson("Spring"); person.getFriends().add(friend1); person.getFriends().add(friend2); + String templateString = template.apply(person); assertThat(templateString).isEqualTo("\nJava is my friend.\n" @@ -62,12 +62,12 @@ public class BuiltinHelperUnitTest { public void whenUsedEachMustacheStyle_ThenIterates() throws IOException { Handlebars handlebars = new Handlebars(templateLoader); Template template = handlebars.compile("each_mustache"); - Person person = getPerson("Baeldung"); Person friend1 = getPerson("Java"); Person friend2 = getPerson("Spring"); person.getFriends().add(friend1); person.getFriends().add(friend2); + String templateString = template.apply(person); assertThat(templateString).isEqualTo("\nJava is my friend.\n" @@ -78,9 +78,9 @@ public class BuiltinHelperUnitTest { public void whenUsedIf_ThenPutsCondition() throws IOException { Handlebars handlebars = new Handlebars(templateLoader); Template template = handlebars.compile("if"); - Person person = getPerson("Baeldung"); person.setBusy(true); + String templateString = template.apply(person); assertThat(templateString).isEqualTo("\n

Baeldung is busy.

\n"); @@ -90,9 +90,9 @@ public class BuiltinHelperUnitTest { public void whenUsedIfMustacheStyle_ThenPutsCondition() throws IOException { Handlebars handlebars = new Handlebars(templateLoader); Template template = handlebars.compile("if_mustache"); - Person person = getPerson("Baeldung"); person.setBusy(true); + String templateString = template.apply(person); assertThat(templateString).isEqualTo("\n

Baeldung is busy.

\n"); diff --git a/libraries-2/src/test/java/com/baeldung/handlebars/CustomHelperUnitTest.java b/libraries-2/src/test/java/com/baeldung/handlebars/CustomHelperUnitTest.java index 6966d69cef..a3c6667654 100644 --- a/libraries-2/src/test/java/com/baeldung/handlebars/CustomHelperUnitTest.java +++ b/libraries-2/src/test/java/com/baeldung/handlebars/CustomHelperUnitTest.java @@ -31,8 +31,8 @@ public class CustomHelperUnitTest { } }); Template template = handlebars.compile("person"); - Person person = getPerson("Baeldung"); + String templateString = template.apply(person); assertThat(templateString).isEqualTo("Baeldung - busy"); @@ -43,8 +43,8 @@ public class CustomHelperUnitTest { Handlebars handlebars = new Handlebars(templateLoader); handlebars.registerHelpers(new HelperSource()); Template template = handlebars.compile("person"); - Person person = getPerson("Baeldung"); + String templateString = template.apply(person); assertThat(templateString).isEqualTo("Baeldung - busy"); diff --git a/libraries-2/src/test/java/com/baeldung/handlebars/ReusingTemplatesUnitTest.java b/libraries-2/src/test/java/com/baeldung/handlebars/ReusingTemplatesUnitTest.java index 8741294703..36f78f486e 100644 --- a/libraries-2/src/test/java/com/baeldung/handlebars/ReusingTemplatesUnitTest.java +++ b/libraries-2/src/test/java/com/baeldung/handlebars/ReusingTemplatesUnitTest.java @@ -22,9 +22,9 @@ public class ReusingTemplatesUnitTest { 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).isEqualTo("

Hi Baeldung!

\n

This is the page Baeldung

"); @@ -34,9 +34,9 @@ public class ReusingTemplatesUnitTest { 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).isEqualTo("\n\n"