public final void dispatchRequestAndRedirectOnPost() throws IOException {
final HttpServletRequest request = createMock(HttpServletRequest.class);
PageBook pageBook = createMock(PageBook.class);
PageBook.Page page = createMock(PageBook.Page.class);
Renderable widget = createMock(Renderable.class);
final Respond respond = createMock(Respond.class);
RequestBinder binder = createMock(RequestBinder.class);
Object pageOb = new Object();
expect(request.getRequestURI())
.andReturn("/thing")
.anyTimes();
expect(request.getContextPath())
.andReturn("")
.anyTimes();
expect(request.getParameterMap())
.andReturn(new HashMap())
.anyTimes();
expect(pageBook.get("/thing"))
.andReturn(page);
binder.bind(request, pageOb);
expectLastCall().once();
expect(page.isHeadless())
.andReturn(false);
expect(page.instantiate())
.andReturn(pageOb);
expect(request.getMethod())
.andReturn("POST");
respond.redirect(REDIRECTED_POST);
//noinspection unchecked
expect(page.doMethod(matches("post"), eq(pageOb), eq("/thing"), isA(HttpServletRequest.class)))
.andReturn(REDIRECTED_POST);
// widget.render(pageOb, respond);
// expectLastCall().once();
replay(request, page, pageBook, widget, respond, binder);
Respond out = new WidgetRoutingDispatcher(pageBook, binder, new Provider<Respond>() {
public Respond get() {
return respond;
}
}, createNiceMock(ResourcesService.class), flashCacheProvider,
createNiceMock(HeadlessRenderer.class)).dispatch(request, response);