import java.io.Serializable;
+import com.vaadin.navigator.ViewChangeListener.ViewChangeEvent;
import com.vaadin.ui.Component;
/**
/**
* This view is navigated to.
*
- * This method is always called before the view is shown on screen. If there
- * is any additional id to data what should be shown in the view, it is also
- * optionally passed as parameter.
+ * This method is always called before the view is shown on screen.
+ * {@link ViewChangeEvent#getParameters() event.getParameters()} may contain
+ * extra parameters relevant to the view.
+ *
+ * @param event
+ * ViewChangeEvent representing the view change that is
+ * occurring. {@link ViewChangeEvent#getNewView()
+ * event.getNewView()} returns <code>this</code>.
*
- * @param parameters
- * parameters to the view or empty string if none given. This is
- * the string that appears e.g. in URI after "viewname/"
*/
- public void navigateTo(String parameters);
+ public void enter(ViewChangeEvent event);
}
\ No newline at end of file
import junit.framework.TestCase;
import org.easymock.EasyMock;
+import org.easymock.IArgumentMatcher;
import org.easymock.IMocksControl;
import com.vaadin.navigator.NavigationStateManager;
}
}
+ public static ViewChangeEvent eventParametersEqual(final String expected) {
+ EasyMock.reportMatcher(new IArgumentMatcher() {
+ @Override
+ public void appendTo(StringBuffer buffer) {
+ buffer.append("paramsIs(\"" + expected + "\")");
+ }
+
+ @Override
+ public boolean matches(Object actual) {
+ return actual instanceof ViewChangeEvent
+ && expected.equals(((ViewChangeEvent) actual)
+ .getParameters());
+ }
+ });
+ return null;
+ }
+
public void testBasicNavigation() {
IMocksControl control = EasyMock.createControl();
NavigationStateManager manager = control
EasyMock.expect(provider.getViewName("test1")).andReturn("test1");
EasyMock.expect(provider.getView("test1")).andReturn(view1);
EasyMock.expect(manager.getState()).andReturn("");
- view1.navigateTo("");
+ view1.enter(eventParametersEqual(""));
display.showView(view1);
manager.setState("test1");
EasyMock.expect(provider.getViewName("test2/")).andReturn("test2");
EasyMock.expect(provider.getView("test2")).andReturn(view2);
EasyMock.expect(manager.getState()).andReturn("view1");
- view2.navigateTo("");
+ view2.enter(eventParametersEqual(""));
display.showView(view2);
manager.setState("test2");
.andReturn("test1");
EasyMock.expect(provider.getView("test1")).andReturn(view1);
EasyMock.expect(manager.getState()).andReturn("view2");
- view1.navigateTo("params");
+ view1.enter(eventParametersEqual("params"));
display.showView(view1);
manager.setState("test1/params");
EasyMock.expect(provider.getViewName("test2")).andReturn("test2");
EasyMock.expect(provider.getView("test2")).andReturn(view2);
EasyMock.expect(manager.getState()).andReturn("view1");
- view2.navigateTo("");
+ view2.enter(eventParametersEqual(""));
display.showView(view2);
manager.setState("test2");
EasyMock.expect(provider.getViewName("")).andReturn("test1");
EasyMock.expect(provider.getView("test1")).andReturn(view1);
EasyMock.expect(manager.getState()).andReturn("");
- view1.navigateTo("");
+ view1.enter(eventParametersEqual(""));
display.showView(view1);
manager.setState("test1");
.andReturn("test1");
EasyMock.expect(provider.getView("test1")).andReturn(view1);
EasyMock.expect(manager.getState()).andReturn("view2");
- view1.navigateTo("params");
+ view1.enter(eventParametersEqual("params"));
display.showView(view1);
manager.setState("test1/params");
"test1", "");
listener.addExpectedIsViewChangeAllowed(event1, true);
EasyMock.expect(manager.getState()).andReturn("");
- view1.navigateTo("");
+ view1.enter(eventParametersEqual(""));
display.showView(view1);
manager.setState("test1");
listener.addExpectedNavigatorViewChange(event1);
"test2", "");
listener.addExpectedIsViewChangeAllowed(event2, true);
EasyMock.expect(manager.getState()).andReturn("view1");
- view2.navigateTo("");
+ view2.enter(eventParametersEqual(""));
display.showView(view2);
manager.setState("test2");
listener.addExpectedNavigatorViewChange(event2);
"test1", "bar");
listener1.addExpectedIsViewChangeAllowed(event3, true);
listener2.addExpectedIsViewChangeAllowed(event3, true);
- view1.navigateTo("bar");
+ view1.enter(EasyMock.isA(ViewChangeEvent.class));
display.showView(view1);
manager.setState("test1/bar");
listener1.addExpectedNavigatorViewChange(event3);
"test2", "");
listener1.addExpectedIsViewChangeAllowed(event4, true);
listener2.addExpectedIsViewChangeAllowed(event4, true);
- view2.navigateTo("");
+ view2.enter(EasyMock.isA(ViewChangeEvent.class));
display.showView(view2);
manager.setState("test2");
listener1.addExpectedNavigatorViewChange(event4);