mirror of
https://github.com/apache/struts.git
synced 2026-08-11 01:27:14 +00:00
add test for mergeTemplate method
Test that a ConfigurationException is thrown when the TemplateEngineManager returns null instead of a TemplateEngine instance.
This commit is contained in:
@@ -19,11 +19,16 @@
|
||||
package org.apache.struts2.components;
|
||||
|
||||
import com.opensymphony.xwork2.ActionContext;
|
||||
import com.opensymphony.xwork2.config.ConfigurationException;
|
||||
import com.opensymphony.xwork2.util.ValueStack;
|
||||
import org.apache.struts2.StrutsInternalTestCase;
|
||||
import org.apache.struts2.components.template.Template;
|
||||
import org.apache.struts2.components.template.TemplateEngine;
|
||||
import org.apache.struts2.components.template.TemplateEngineManager;
|
||||
import org.springframework.mock.web.MockHttpServletRequest;
|
||||
import org.springframework.mock.web.MockHttpServletResponse;
|
||||
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -161,4 +166,26 @@ public class UIBeanTest extends StrutsInternalTestCase {
|
||||
assertEquals("12", txtFld.getTheme());
|
||||
}
|
||||
|
||||
public void testMergeTemplateNullEngineException() throws Exception {
|
||||
ValueStack stack = ActionContext.getContext().getValueStack();
|
||||
MockHttpServletRequest req = new MockHttpServletRequest();
|
||||
MockHttpServletResponse res = new MockHttpServletResponse();
|
||||
//templateEngineManager that returns null as TemplateEngine
|
||||
TemplateEngineManager templateEngineManager = new TemplateEngineManager() {
|
||||
public TemplateEngine getTemplateEngine(Template template, String templateTypeOverride) {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
TextField txtFld = new TextField(stack, req, res);
|
||||
|
||||
txtFld.setTemplateEngineManager(templateEngineManager);
|
||||
|
||||
try {
|
||||
txtFld.mergeTemplate(null, new Template(null, null, null));
|
||||
fail("Exception not thrown");
|
||||
} catch(final Exception e){
|
||||
assertTrue(e instanceof ConfigurationException);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user