Skip to content

Commit 5c7d15d

Browse files
danglotbspullara
authored andcommitted
test: verify that a MustacheException is thrown when the hanlder is null
1 parent 6625bd8 commit 5c7d15d

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

compiler/src/test/java/com/github/mustachejava/ArraysIndexesTest.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import java.util.Set;
1313

1414
import static org.junit.Assert.assertEquals;
15+
import static org.junit.Assert.fail;
1516

1617
/**
1718
* Shows a simple way to add indexes for arrays.
@@ -64,6 +65,32 @@ public Object coerce(final Object object) {
6465
assertEquals(result, writer.toString());
6566
}
6667

68+
@Test
69+
public void testThrowMustacheExceptionInCaseOfNullHandler() throws Exception {
70+
try {
71+
String template = "<ol>\n" +
72+
" <li>{{test.1}}</li>\n" +
73+
" <li>{{test.0}}</li>\n" +
74+
" <li>{{test.3}}</li>\n" +
75+
"</ol>\n" +
76+
"<ol>\n" +
77+
"{{#test}}\n" +
78+
" <li>{{.}}</li>\n" +
79+
"{{/test}}\n" +
80+
"</ol>";
81+
Object scope = new Object() {
82+
String[] test = new String[]{ "a", "b", "c", "d" };
83+
};
84+
DefaultMustacheFactory mf = new DefaultMustacheFactory();
85+
mf.setObjectHandler(null);
86+
Mustache m = mf.compile(new StringReader(template), "template");
87+
m.execute(new StringWriter(), scope).flush();
88+
fail("should have thrown MustacheException");
89+
} catch (MustacheException expected) {
90+
assertEquals("Failed to get value for test.1 @[template:2]", expected.getMessage());
91+
}
92+
}
93+
6794
private static class ArrayMap extends AbstractMap<Object, Object> implements Iterable<Object> {
6895
private final Object object;
6996

0 commit comments

Comments
 (0)