ViewEngineBase implements ViewEngine { protected String resolveView(ViewEngineContext context) { final String view = context.getView(); if (!PathUtils.hasStartingSlash(view)) { final String viewFolder = PropertyUtils.getProperty(context.getConfiguration(), VIEW_FOLDER, DEFAULT_VIEW_FOLDER); return PathUtils.ensureEndingSlash(viewFolder) + view; } return view; }    }
@Test public void resolveView() { ViewEngineContext ctx = EasyMock.createMock(ViewEngineContext.class); Configuration config = EasyMock.createMock(Configuration.class); expect(config.getProperty(eq(ViewEngine.VIEW_FOLDER))).andReturn(null); expect(ctx.getConfiguration()).andReturn(config); expect(ctx.getView()).andReturn("index.jsp"); expect(ctx.getView()).andReturn("/somewhere/else/index.jsp"); replay(ctx, config); assertThat(viewEngineBase.resolveView(ctx), is("/WEB-INF/views/index.jsp")); assertThat(viewEngineBase.resolveView(ctx), is("/somewhere/else/index.jsp")); verify(ctx, config); }
@Test public void resolveViewCustomFolder() { ViewEngineContext ctx = EasyMock.createMock(ViewEngineContext.class); Configuration config = EasyMock.createMock(Configuration.class); expect(config.getProperty(eq(ViewEngine.VIEW_FOLDER))).andReturn("/somewhere/else"); expect(ctx.getConfiguration()).andReturn(config); expect(ctx.getView()).andReturn("index.jsp"); replay(ctx, config); assertThat(viewEngineBase.resolveView(ctx), is("/somewhere/else/index.jsp")); verify(ctx, config); }