public void createEngineDirectly() throws Exception {
initServlet("webapp/WEB-INF/web.xml");
// no servletContext
try {
new JspEngineImpl(null, null, null);
fail();
} catch (IllegalArgumentException e) {
assertThat(e, exception("servletContext"));
}
// no request
try {
new JspEngineImpl(servletContext, null, null);
fail();
} catch (IllegalArgumentException e) {
assertThat(e, exception("request"));
}
// no response
try {
new JspEngineImpl(servletContext, createMock(MockRequestProxy.class), null);
fail();
} catch (IllegalArgumentException e) {
assertThat(e, exception("response"));
}
// request not a proxy
try {
new JspEngineImpl(servletContext, request, response);
fail();
} catch (IllegalArgumentException e) {
assertThat(e, exception("expects a proxy delegating to a real object, but got an object of type "
+ request.getClass().getName()));
}
// response not a proxy
try {
new JspEngineImpl(servletContext, createMock(MockRequestProxy.class), response);
fail();
} catch (IllegalArgumentException e) {
assertThat(e, exception("expects a proxy delegating to a real object, but got an object of type "
+ response.getClass().getName()));
}
// no resource loader
JspEngineImpl engine = new JspEngineImpl(servletContext, createMock(MockRequestProxy.class),
createMock(MockResponseProxy.class));
try {
engine.afterPropertiesSet();
fail();
} catch (IllegalArgumentException e) {
assertThat(e, exception("resourceLoader"));
}
// ok
engine = new JspEngineImpl(servletContext, createMock(MockRequestProxy.class),
createMock(MockResponseProxy.class));
engine.setResourceLoader(createMock(ResourceLoader.class));
// not inited yet
try {
engine.getPathWithinServletContext("/test");
fail();
} catch (IllegalStateException e) {
assertThat(e, exception("has not been initialized yet"));
}
engine.afterPropertiesSet();
}