TabLayoutPanel parentPanel = new TabLayoutPanel(10, Unit.CM);
view.setContext(parentPanel, 1);
view.setInitializationEventHandler(initHandler);
view.setSelectedEventHandler(selectedHandler);
SelectionHandler handler = new SelectionHandler(view);
handler.onBeforeSelection(2);
assertFalse(view.isInitialized());
assertEquals(0, initHandler.calls);
assertEquals(0, selectedHandler.calls);
handler.onBeforeSelection(1);
assertTrue(view.isInitialized());
assertEquals(1, initHandler.calls);
assertEquals(UnifiedEventType.INIT_EVENT, initHandler.lastType);
assertEquals(1, selectedHandler.calls);
assertEquals(UnifiedEventType.SELECTED_EVENT, selectedHandler.lastType);
handler.disable();
handler.onBeforeSelection(1);
assertTrue(view.isInitialized());
assertEquals(1, initHandler.calls);
assertEquals(UnifiedEventType.INIT_EVENT, initHandler.lastType);
assertEquals(1, selectedHandler.calls);
assertEquals(UnifiedEventType.SELECTED_EVENT, selectedHandler.lastType);
handler.enable();
handler.onBeforeSelection(1);
assertTrue(view.isInitialized());
assertEquals(1, initHandler.calls);
assertEquals(UnifiedEventType.INIT_EVENT, initHandler.lastType);
assertEquals(2, selectedHandler.calls);
assertEquals(UnifiedEventType.SELECTED_EVENT, selectedHandler.lastType);
handler.onBeforeSelection(1);
assertTrue(view.isInitialized());
assertEquals(1, initHandler.calls);
assertEquals(UnifiedEventType.INIT_EVENT, initHandler.lastType);
assertEquals(3, selectedHandler.calls);
assertEquals(UnifiedEventType.SELECTED_EVENT, selectedHandler.lastType);