Skip to content

Commit

Permalink
tests: get back some tests we removed while migrating to Java 11
Browse files Browse the repository at this point in the history
  • Loading branch information
jknack committed Oct 18, 2022
1 parent e46ba8d commit 29f6296
Showing 1 changed file with 16 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,11 @@
import java.io.IOException;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.junit.Ignore;
import org.apache.commons.lang3.StringUtils;
import org.junit.Test;

import com.github.jknack.handlebars.context.JavaBeanValueResolver;
Expand Down Expand Up @@ -57,28 +60,29 @@ public String getBody() {
.build();
}

@Ignore
@Test
public void eachKeyWithString() throws IOException {
String result = compile("{{#each this}}{{@key}} {{/each}}").apply("String");
Set<String> result = Stream.of(StringUtils.split(
compile("{{#each this}}{{@key}} {{/each}}").apply(configureContext("String")), " "))
.collect(Collectors.toSet());

String expected1 = "empty bytes ";
String expected2 = "bytes empty ";
assertTrue(result.equals(expected1) || result.equals(expected2));
Set<String> expected = Stream.of("empty", "bytes").collect(Collectors.toSet());
assertTrue(result.containsAll(expected));
}

@Ignore
@Test
public void eachKeyWithInt() throws IOException {
shouldCompileTo("{{#each this}}{{@key}} {{/each}}", 7, "");
shouldCompileTo("{{#each this}}{{@key}} {{/each}}", configureContext(7), "");
}

@Test
public void eachKeyWithJavaBean() throws IOException {
Blog blog = new Blog("Handlebars.java", "...");
String result = compile("{{#each this}}{{@key}}: {{this}} {{/each}}").apply(configureContext(blog));
Set<String> result = Stream.of(StringUtils.split(compile("{{#each this}}{{@key}}:{{this}} {{/each}}").apply(configureContext(blog)), " ")).collect(
Collectors.toSet());

String expected1 = "body: ... title: Handlebars.java ";
String expected2 = "title: Handlebars.java body: ... ";
assertTrue(result.equals(expected1) || result.equals(expected2));
Set<String> expected = Stream.of("body:...", "title:Handlebars.java").collect(Collectors.toSet());
assertTrue(result.containsAll(expected));
}

@Test
Expand Down

0 comments on commit 29f6296

Please sign in to comment.