assertSame(tv2, container.getComponent(0));
assertEquals(1, container.getComponentCount());
}
public void testBlockNavigation() {
IMocksControl control = EasyMock.createControl();
NavigationStateManager manager = control
.createMock(NavigationStateManager.class);
ViewDisplay display = control.createMock(ViewDisplay.class);
ViewProvider provider = control.createMock(ViewProvider.class);
View view1 = control.createMock(View.class);
View view2 = control.createMock(View.class);
ViewChangeTestListener listener1 = new ViewChangeTestListener();
ViewChangeTestListener listener2 = new ViewChangeTestListener();
Navigator navigator = createNavigator(manager, display);
// prepare mocks: what to expect
// first listener blocks first view change
EasyMock.expect(provider.getViewName("test1")).andReturn("test1");
EasyMock.expect(provider.getView("test1")).andReturn(view1);
EasyMock.expect(manager.getState()).andReturn("");
ViewChangeEvent event1 = new ViewChangeEvent(navigator, null, view1,
"test1", "");
listener1.addExpectedIsViewChangeAllowed(event1, false);
// second listener blocks second view change
EasyMock.expect(provider.getViewName("test1/test")).andReturn("test1");
EasyMock.expect(provider.getView("test1")).andReturn(view1);
EasyMock.expect(manager.getState()).andReturn("");
ViewChangeEvent event2 = new ViewChangeEvent(navigator, null, view1,
"test1", "test");
listener1.addExpectedIsViewChangeAllowed(event2, true);
listener2.addExpectedIsViewChangeAllowed(event2, false);
// both listeners allow view change
EasyMock.expect(provider.getViewName("test1/bar")).andReturn("test1");
EasyMock.expect(provider.getView("test1")).andReturn(view1);
EasyMock.expect(manager.getState()).andReturn("");
ViewChangeEvent event3 = new ViewChangeEvent(navigator, null, view1,
"test1", "bar");
listener1.addExpectedIsViewChangeAllowed(event3, true);
listener2.addExpectedIsViewChangeAllowed(event3, true);
view1.enter(EasyMock.isA(ViewChangeEvent.class));
display.showView(view1);
manager.setState("test1/bar");
listener1.addExpectedNavigatorViewChange(event3);
listener2.addExpectedNavigatorViewChange(event3);
// both listeners allow view change from non-null view
EasyMock.expect(provider.getViewName("test2")).andReturn("test2");
EasyMock.expect(provider.getView("test2")).andReturn(view2);
EasyMock.expect(manager.getState()).andReturn("view1");
ViewChangeEvent event4 = new ViewChangeEvent(navigator, view1, view2,
"test2", "");
listener1.addExpectedIsViewChangeAllowed(event4, true);
listener2.addExpectedIsViewChangeAllowed(event4, true);
view2.enter(EasyMock.isA(ViewChangeEvent.class));
display.showView(view2);
manager.setState("test2");
listener1.addExpectedNavigatorViewChange(event4);
listener2.addExpectedNavigatorViewChange(event4);
control.replay();
// test navigator
navigator.addProvider(provider);
navigator.addViewChangeListener(listener1);
navigator.addViewChangeListener(listener2);