BAEL-20602: Use contains instead of verifying strings' equality

This commit is contained in:
Krzysiek 2020-02-08 23:32:34 +01:00
parent fbbafeb4d2
commit 733c46db9b
2 changed files with 22 additions and 31 deletions

View File

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

View File

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