mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-12 16:35:45 +01:00
added test for defect templates
This commit is contained in:
@@ -57,11 +57,39 @@ public class FreemarkerTemplateTest extends TemplateTestBase
|
||||
* @throws IOException
|
||||
*/
|
||||
@Override
|
||||
public Template getTemplate() throws IOException
|
||||
public Template getFailureTemplate() throws IOException
|
||||
{
|
||||
return getTemplate("sonia/scm/template/002.ftl");
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
@Override
|
||||
public Template getHelloTemplate() throws IOException
|
||||
{
|
||||
return getTemplate("sonia/scm/template/004.ftl");
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param path
|
||||
*
|
||||
* @return
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
private Template getTemplate(String path) throws IOException
|
||||
{
|
||||
ServletContext context = mock(ServletContext.class);
|
||||
|
||||
return new FreemarkerTemplateEngine(context).getTemplate(
|
||||
"sonia/scm/template/002.ftl");
|
||||
return new FreemarkerTemplateEngine(context).getTemplate(path);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,6 +36,10 @@ package sonia.scm.template;
|
||||
import com.github.mustachejava.DefaultMustacheFactory;
|
||||
import com.github.mustachejava.Mustache;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
@@ -48,13 +52,40 @@ public class MustacheTemplateTest extends TemplateTestBase
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
@Override
|
||||
public Template getTemplate()
|
||||
public Template getFailureTemplate() throws IOException
|
||||
{
|
||||
return getTemplate("sonia/scm/template/003.mustache");
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Template getHelloTemplate()
|
||||
{
|
||||
return getTemplate("sonia/scm/template/001.mustache");
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param path
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private Template getTemplate(String path)
|
||||
{
|
||||
DefaultMustacheFactory factory = new DefaultMustacheFactory();
|
||||
Mustache mustache = factory.compile("sonia/scm/template/001.mustache");
|
||||
Mustache mustache = factory.compile(path);
|
||||
|
||||
return new MustacheTemplate("sonia/scm/template/001.mustache", mustache);
|
||||
return new MustacheTemplate(path, mustache);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,7 +59,17 @@ public abstract class TemplateTestBase
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public abstract Template getTemplate() throws IOException;
|
||||
public abstract Template getFailureTemplate() throws IOException;
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
public abstract Template getHelloTemplate() throws IOException;
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
@@ -72,8 +82,37 @@ public abstract class TemplateTestBase
|
||||
@Test
|
||||
public void testRender() throws IOException
|
||||
{
|
||||
Template template = getTemplate();
|
||||
Template template = getHelloTemplate();
|
||||
|
||||
assertEquals("Hello marvin!", execute(template));
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
@Test(expected = IOException.class)
|
||||
public void testRenderFailure() throws IOException
|
||||
{
|
||||
Template template = getFailureTemplate();
|
||||
|
||||
execute(template);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param template
|
||||
*
|
||||
* @return
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
private String execute(Template template) throws IOException
|
||||
{
|
||||
Map<String, String> env = Maps.newHashMap();
|
||||
|
||||
env.put("name", "marvin");
|
||||
@@ -82,6 +121,6 @@ public abstract class TemplateTestBase
|
||||
|
||||
template.execute(writer, env);
|
||||
|
||||
assertEquals("Hello marvin!", writer.toString());
|
||||
return writer.toString();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user