Merge pull request #8686 from kwoyke/BAEL-20602-2

BAEL-20602: Use contains instead of verifying strings' equality
This commit is contained in:
Loredana Crusoveanu 2020-02-09 10:27:43 +02:00 committed by GitHub
commit d3c6a1af82
2 changed files with 22 additions and 31 deletions

View File

@ -1,15 +1,14 @@
package com.baeldung.handlebars; package com.baeldung.handlebars;
import static org.assertj.core.api.Assertions.assertThat;
import com.github.jknack.handlebars.Handlebars; import com.github.jknack.handlebars.Handlebars;
import com.github.jknack.handlebars.Template; import com.github.jknack.handlebars.Template;
import com.github.jknack.handlebars.io.ClassPathTemplateLoader; import com.github.jknack.handlebars.io.ClassPathTemplateLoader;
import com.github.jknack.handlebars.io.TemplateLoader; import com.github.jknack.handlebars.io.TemplateLoader;
import org.junit.Test;
import java.io.IOException; import java.io.IOException;
import org.junit.Ignore; import static org.assertj.core.api.Assertions.assertThat;
import org.junit.Test;
/** /**
* Showcases the built-in template helpers. * Showcases the built-in template helpers.
@ -20,7 +19,6 @@ public class BuiltinHelperUnitTest {
private TemplateLoader templateLoader = new ClassPathTemplateLoader("/handlebars", ".html"); private TemplateLoader templateLoader = new ClassPathTemplateLoader("/handlebars", ".html");
@Ignore
@Test @Test
public void whenUsedWith_ThenContextChanges() throws IOException { public void whenUsedWith_ThenContextChanges() throws IOException {
Handlebars handlebars = new Handlebars(templateLoader); Handlebars handlebars = new Handlebars(templateLoader);
@ -30,10 +28,9 @@ public class BuiltinHelperUnitTest {
String templateString = template.apply(person); String templateString = template.apply(person);
assertThat(templateString).isEqualTo("\n<h4>I live in World</h4>\n"); assertThat(templateString).contains("<h4>I live in World</h4>");
} }
@Ignore
@Test @Test
public void whenUsedWithMustacheStyle_ThenContextChanges() throws IOException { public void whenUsedWithMustacheStyle_ThenContextChanges() throws IOException {
Handlebars handlebars = new Handlebars(templateLoader); Handlebars handlebars = new Handlebars(templateLoader);
@ -43,10 +40,9 @@ public class BuiltinHelperUnitTest {
String templateString = template.apply(person); String templateString = template.apply(person);
assertThat(templateString).isEqualTo("\n<h4>I live in World</h4>\n"); assertThat(templateString).contains("<h4>I live in World</h4>");
} }
@Ignore
@Test @Test
public void whenUsedEach_ThenIterates() throws IOException { public void whenUsedEach_ThenIterates() throws IOException {
Handlebars handlebars = new Handlebars(templateLoader); Handlebars handlebars = new Handlebars(templateLoader);
@ -59,11 +55,10 @@ public class BuiltinHelperUnitTest {
String templateString = template.apply(person); String templateString = template.apply(person);
assertThat(templateString).isEqualTo("\n<span>Java is my friend.</span>\n" assertThat(templateString)
+ "\n<span>Spring is my friend.</span>\n"); .contains("<span>Java is my friend.</span>", "<span>Spring is my friend.</span>");
} }
@Ignore
@Test @Test
public void whenUsedEachMustacheStyle_ThenIterates() throws IOException { public void whenUsedEachMustacheStyle_ThenIterates() throws IOException {
Handlebars handlebars = new Handlebars(templateLoader); Handlebars handlebars = new Handlebars(templateLoader);
@ -76,11 +71,10 @@ public class BuiltinHelperUnitTest {
String templateString = template.apply(person); String templateString = template.apply(person);
assertThat(templateString).isEqualTo("\n<span>Java is my friend.</span>\n" assertThat(templateString)
+ "\n<span>Spring is my friend.</span>\n"); .contains("<span>Java is my friend.</span>", "<span>Spring is my friend.</span>");
} }
@Ignore
@Test @Test
public void whenUsedIf_ThenPutsCondition() throws IOException { public void whenUsedIf_ThenPutsCondition() throws IOException {
Handlebars handlebars = new Handlebars(templateLoader); Handlebars handlebars = new Handlebars(templateLoader);
@ -90,10 +84,9 @@ public class BuiltinHelperUnitTest {
String templateString = template.apply(person); String templateString = template.apply(person);
assertThat(templateString).isEqualTo("\n<h4>Baeldung is busy.</h4>\n"); assertThat(templateString).contains("<h4>Baeldung is busy.</h4>");
} }
@Ignore
@Test @Test
public void whenUsedIfMustacheStyle_ThenPutsCondition() throws IOException { public void whenUsedIfMustacheStyle_ThenPutsCondition() throws IOException {
Handlebars handlebars = new Handlebars(templateLoader); Handlebars handlebars = new Handlebars(templateLoader);
@ -103,7 +96,7 @@ public class BuiltinHelperUnitTest {
String templateString = template.apply(person); String templateString = template.apply(person);
assertThat(templateString).isEqualTo("\n<h4>Baeldung is busy.</h4>\n"); assertThat(templateString).contains("<h4>Baeldung is busy.</h4>");
} }
private Person getPerson(String name) { private Person getPerson(String name) {

View File

@ -1,15 +1,14 @@
package com.baeldung.handlebars; package com.baeldung.handlebars;
import static org.assertj.core.api.Assertions.assertThat;
import com.github.jknack.handlebars.Handlebars; import com.github.jknack.handlebars.Handlebars;
import com.github.jknack.handlebars.Template; import com.github.jknack.handlebars.Template;
import com.github.jknack.handlebars.io.ClassPathTemplateLoader; import com.github.jknack.handlebars.io.ClassPathTemplateLoader;
import com.github.jknack.handlebars.io.TemplateLoader; import com.github.jknack.handlebars.io.TemplateLoader;
import org.junit.Test;
import java.io.IOException; import java.io.IOException;
import org.junit.Ignore; import static org.assertj.core.api.Assertions.assertThat;
import org.junit.Test;
/** /**
* Showcases reusing the existing templates. * Showcases reusing the existing templates.
@ -20,7 +19,6 @@ public class ReusingTemplatesUnitTest {
private TemplateLoader templateLoader = new ClassPathTemplateLoader("/handlebars", ".html"); private TemplateLoader templateLoader = new ClassPathTemplateLoader("/handlebars", ".html");
@Ignore
@Test @Test
public void whenOtherTemplateIsReferenced_ThenCanReuse() throws IOException { public void whenOtherTemplateIsReferenced_ThenCanReuse() throws IOException {
Handlebars handlebars = new Handlebars(templateLoader); Handlebars handlebars = new Handlebars(templateLoader);
@ -30,10 +28,10 @@ public class ReusingTemplatesUnitTest {
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)
.contains("<h4>Hi Baeldung!</h4>", "<p>This is the page Baeldung</p>");
} }
@Ignore
@Test @Test
public void whenBlockIsDefined_ThenCanOverrideWithPartial() throws IOException { public void whenBlockIsDefined_ThenCanOverrideWithPartial() throws IOException {
Handlebars handlebars = new Handlebars(templateLoader); Handlebars handlebars = new Handlebars(templateLoader);
@ -43,11 +41,11 @@ public class ReusingTemplatesUnitTest {
String templateString = template.apply(person); String templateString = template.apply(person);
assertThat(templateString).isEqualTo("\n<html>\n" assertThat(templateString).contains("<html>",
+ "<body>\n" "<body>",
+ "\n This is the intro\n\n" "This is the intro",
+ "\n Hi there!\n\n" "Hi there!",
+ "</body>\n" "</body>",
+ "</html>"); "</html>");
} }
} }