|
12 | 12 | import java.util.Set; |
13 | 13 |
|
14 | 14 | import static org.junit.Assert.assertEquals; |
| 15 | +import static org.junit.Assert.fail; |
15 | 16 |
|
16 | 17 | /** |
17 | 18 | * Shows a simple way to add indexes for arrays. |
@@ -64,6 +65,32 @@ public Object coerce(final Object object) { |
64 | 65 | assertEquals(result, writer.toString()); |
65 | 66 | } |
66 | 67 |
|
| 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 | + |
67 | 94 | private static class ArrayMap extends AbstractMap<Object, Object> implements Iterable<Object> { |
68 | 95 | private final Object object; |
69 | 96 |
|
|
0 commit comments