*/
public void testGetMenuBufferConsistent() throws Exception {
final MenuBufferLocator locator = createMenuBufferLocator();
MenuModelBuilder builder = new ConcreteMenuModelBuilder();
Menu menu;
builder.startMenu();
// Make the menu automatic allocate and ensure that the pane is
// incompletely specified to ensure automatic iteration allocation
builder.setElementDetails("menu", null,
StylesBuilder.getCompleteStyles(
"mcs-menu-item-iterator-allocation: automatic"));
builder.setPane(new FormatReference("pane",
new NDimensionalIndex(
new int[]{1, 2, 0},
2)));
createMenuItem(builder, "item1");
builder.startMenu();
createMenuItem(builder, "item2.1");
createMenuItem(builder, "item2.2");
builder.endMenu();
menu = builder.endMenu();
final Map buffers = new HashMap();
MenuModelVisitor setupMapVisitor = new AbstractMenuModelHandler() {
// javadoc inherited
protected boolean handle(MenuItem item) {
buffers.put(item, locator.getMenuBuffer(item));
return false;
}
// javadoc inherited
protected boolean handle(MenuItemGroup group) {
buffers.put(group, locator.getMenuBuffer(group));
return true;
}
// javadoc inherited
protected boolean handle(Menu menu) {
buffers.put(menu, locator.getMenuBuffer(menu));
return true;
}
};
setupMapVisitor.visit(menu);
MenuModelVisitor checkVisitor = new AbstractMenuModelHandler() {
// javadoc inherited
protected boolean handle(MenuItem item) {
assertSame("item's buffer not as",
buffers.get(item),
locator.getMenuBuffer(item));
return true;
}
// javadoc inherited
protected boolean handle(MenuItemGroup group) {
assertSame("group's buffer not as",
buffers.get(group),
locator.getMenuBuffer(group));
return true;
}
// javadoc inherited
protected boolean handle(Menu menu) {
assertSame("menu's buffer not as",
buffers.get(menu),
locator.getMenuBuffer(menu));
return false;
}
};
checkVisitor.visit(menu);
assertSame("menu and first child should share same buffer",
buffers.get(menu),
buffers.get(menu.get(0)));
assertNotSame("menu and second child should not share same buffer",
buffers.get(menu),
buffers.get(menu.get(1)));
assertSame("sub-menu and its first child should share same buffer",
buffers.get(menu.get(1)),
buffers.get(((Menu)menu.get(1)).get(0)));
assertSame("sub-menu and its second child should share same buffer",
buffers.get(menu.get(1)),
buffers.get(((Menu)menu.get(1)).get(1)));
}