added test for null and empty template directory
@@ -156,6 +156,28 @@ public class HandlebarsTemplateTest extends WebTestBase {
testTemplateHandler(engine, "src/test/filesystemtemplates", "sub/test-handlebars-template9", "\ntext from template8\n\ntext from template9\n\n\n");
}
+ @Test
+ public void testTemplateDirectoryNullAndEmpty() throws Exception {
+ // null or empty templateDirectory should resolve to current working directory,
+ // which is target/classes while testing
+ TemplateEngine engine = HandlebarsTemplateEngine.create();
+ File temp = File.createTempFile("template", ".hbs", new File("target/classes"));
+ temp.deleteOnExit();
+
+ router.clear();
+ router.route().handler(TemplateHandler.create(engine, null, "text/html"));
+ // template that doesn't exist
+ testRequest(HttpMethod.GET, "/foo.hbs", 500, "Internal Server Error");
+ // created template
+ testRequest(HttpMethod.GET, "/" + temp.getName(), 200, "OK");
+
+ // same tests with empty path
+ router.clear();
+ router.route().handler(TemplateHandler.create(engine, "", "text/html"));
+ testRequest(HttpMethod.GET, "/foo.hbs", 500, "Internal Server Error");
+ testRequest(HttpMethod.GET, "/" + temp.getName(), 200, "OK");
+ }
+
@Test
public void testTemplateNoExtension() throws Exception {
TemplateEngine engine = HandlebarsTemplateEngine.create();
