Commits

Sebastian Sdorra  committed 191467d

added test for defect templates

  • Participants
  • Parent commits ed37a3f

Comments (0)

Files changed (5)

File scm-webapp/src/test/java/sonia/scm/template/FreemarkerTemplateTest.java

    * @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);
   }
 }

File scm-webapp/src/test/java/sonia/scm/template/MustacheTemplateTest.java

 import com.github.mustachejava.DefaultMustacheFactory;
 import com.github.mustachejava.Mustache;
 
+//~--- JDK imports ------------------------------------------------------------
+
+import java.io.IOException;
+
 /**
  *
  * @author Sebastian Sdorra
    *
    *
    * @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);
   }
 }

File scm-webapp/src/test/java/sonia/scm/template/TemplateTestBase.java

    *
    * @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 --------------------------------------------------------------
 
   @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");
 
     template.execute(writer, env);
 
-    assertEquals("Hello marvin!", writer.toString());
+    return writer.toString();
   }
 }

File scm-webapp/src/test/resources/sonia/scm/template/003.mustache

+Hello {{/name}}!

File scm-webapp/src/test/resources/sonia/scm/template/004.ftl

+Hello <#list a>!