//forName expects pageName to be in all-lower case (it's an optimization)
pageName = pageName.toLowerCase();
final PageBook pageBook = createMock(PageBook.class);
final PageBook.Page page = createMock(PageBook.Page.class);
final Respond respond = RespondersForTesting.newRespond();
final Renderable widget = createMock(Renderable.class);
expect(pageBook.forName(pageName))
.andReturn(page);
//mypage does?
final MyEmbeddedPage myEmbeddedPage = new MyEmbeddedPage();
expect(page.instantiate())
.andReturn(myEmbeddedPage);
expect(page.doMethod(isA(String.class), anyObject(), isA(String.class),
isA(HttpServletRequest.class)))
.andReturn(null);
expect(page.widget())
.andReturn(widget);
widget.render(eq(myEmbeddedPage), isA(Respond.class));
replay(pageBook, page, widget);
final MvelEvaluator evaluator = new MvelEvaluator();
final WidgetChain widgetChain = new ProceedingWidgetChain();
final WidgetChain targetWidgetChain = new ProceedingWidgetChain();
//noinspection unchecked
targetWidgetChain.addWidget(new XmlWidget(new TerminalWidgetChain(), "p", createMock(EvaluatorCompiler.class), Collections.EMPTY_MAP));
widgetChain.addWidget(new ShowIfWidget(targetWidgetChain, "true", evaluator));
final EmbedWidget embedWidget = new EmbedWidget(Collections.<String, ArgumentWidget>emptyMap(), expression, evaluator, pageBook, pageName);
embedWidget.init(new EmbeddedRespondFactory(RespondersForTesting.newRespond()), HtmlTemplateCompilerTest.mockRequestProviderForContext());
embedWidget
.render(new MyParentPage(passOn), respond);
//assert bindings
assert myEmbeddedPage.isSet() : "variable not passed on to embedded page";
assert passOn.equals(myEmbeddedPage.getMessage()) : "variable not set on embedded page";
//the render was ok
final String resp = respond.toString();
assert "".equals(resp) : "widget not embedded correctly : " + resp;
verify(pageBook, page, widget);
}