" }",
"}");
dialog.refresh();
DialogButton_Info button = dialog.getDialogButtons().get(0);
// set mock for DesignPageSite
IDesignPageSite pageSite;
Capture<Integer> openSourcePosition = new Capture<Integer>();
{
pageSite = EasyMock.createStrictMock(IDesignPageSite.class);
DesignPageSite.Helper.setSite(dialog, pageSite);
pageSite.openSourcePosition(org.easymock.EasyMock.capture(openSourcePosition));
EasyMock.replay(pageSite);
}
// open
button.open();
waitEventLoop(0);
assertEditor(
"// filler filler filler",
"public class Test extends Dialog {",
" public Test() {",
" }",
" protected void onButtonPressed(Button button) {",
" if (button == getButtonBar().getItemByItemId(OK)) {",
" // TODO",
" }",
" super.onButtonPressed(button);",
" }",
"}");
EasyMock.verify(pageSite);
// check captured position
{
assertTrue(openSourcePosition.hasCaptured());
int position = openSourcePosition.getValue();
assertThat(position).isPositive();
assertThat(m_lastEditor.getSource().substring(position)).startsWith(
"if (button == getButtonBar().getItemByItemId(OK)) {");
}
// open it again, same position expected
{
String expectedsource = m_lastEditor.getSource();
// reset mock
{
EasyMock.reset(pageSite);
pageSite.openSourcePosition(openSourcePosition.getValue());
EasyMock.replay(pageSite);
}
// open
button.open();
assertEquals(expectedsource, m_lastEditor.getSource());