Package org.easymock

Examples of org.easymock.IMocksControl


   public <T> T createMock(Class<T> mockClass) {
      return createMock(null, mockClass);
   }

   public <T> T createMock(String name, Class<T> mockClass) {
      IMocksControl control = null;
      if (mockClass.isInterface()) {
         // an interface
         control = EasyMock.createControl();
      } else {
         // a class
         control = org.easymock.classextension.EasyMock.createControl();
      }
     
      mockControls.add(control);
      if (name != null) {
        return control.createMock(name, mockClass);
      } else {
        return control.createMock(mockClass);
      }
   }
View Full Code Here



    protected void setUp() throws Exception
    {
        super.setUp();
        IMocksControl ctrl = EasyMock.createControl();
        ctrl.makeThreadSafe(true);
        mockBundleContext = ctrl.createMock(BundleContext.class);
        mockBundle = EasyMock.createNiceMock(Bundle.class);
        props.put( DirectoryWatcher.DIR, new File( "target/load" ).getAbsolutePath() );

        // Might get called, but most of the time it doesn't matter whether they do or don't.
        EasyMock.expect(mockBundleContext.getProperty(DirectoryWatcher.LOG_DEFAULT))
View Full Code Here

        initCalled = refreshCalled = fragmentChangeCalled = browserWindowResizeCalled = false;
    }

    @Test
    public void testListenersCalled() {
        IMocksControl control = EasyMock.createNiceControl();

        VaadinRequest initRequest = control.createMock(VaadinRequest.class);
        EasyMock.expect(initRequest.getParameter("v-loc")).andReturn(
                "http://example.com/#foo");
        EasyMock.expect(initRequest.getParameter("v-cw")).andReturn("100");
        EasyMock.expect(initRequest.getParameter("v-ch")).andReturn("100");

        VaadinRequest reinitRequest = control.createMock(VaadinRequest.class);
        EasyMock.expect(reinitRequest.getParameter("v-loc")).andReturn(
                "http://example.com/#bar");
        EasyMock.expect(reinitRequest.getParameter("v-cw")).andReturn("200");
        EasyMock.expect(reinitRequest.getParameter("v-ch")).andReturn("200");

        control.replay();

        UI ui = new TestUI();
        ui.doInit(initRequest, 0, "");

        Assert.assertTrue(initCalled);
View Full Code Here

            ViewDisplay display) {
        return new Navigator(createMockUI(), manager, display);
    }

    public void testBasicNavigation() {
        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);

        // prepare mocks: what to expect
        manager.setNavigator(EasyMock.anyObject(Navigator.class));

        EasyMock.expect(provider.getViewName("test1")).andReturn("test1");
        EasyMock.expect(provider.getView("test1")).andReturn(view1);
        EasyMock.expect(manager.getState()).andReturn("");
        view1.enter(eventParametersEqual(""));
        display.showView(view1);
        manager.setState("test1");
        EasyMock.expect(manager.getState()).andReturn("test1");

        EasyMock.expect(provider.getViewName("test2/")).andReturn("test2");
        EasyMock.expect(provider.getView("test2")).andReturn(view2);
        EasyMock.expect(manager.getState()).andReturn("test1");
        view2.enter(eventParametersEqual(""));
        display.showView(view2);
        manager.setState("test2");
        EasyMock.expect(manager.getState()).andReturn("test2");

        EasyMock.expect(provider.getViewName("test1/params"))
                .andReturn("test1");
        EasyMock.expect(provider.getView("test1")).andReturn(view1);
        EasyMock.expect(manager.getState()).andReturn("test2");
        view1.enter(eventParametersEqual("params"));
        display.showView(view1);
        manager.setState("test1/params");
        EasyMock.expect(manager.getState()).andReturn("test1/params");

        control.replay();

        // create and test navigator
        Navigator navigator = createNavigator(manager, display);
        navigator.addProvider(provider);
View Full Code Here

        navigator.navigateTo("test1/params");
        assertEquals("test1/params", navigator.getState());
    }

    public void testMainView() {
        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);

        // prepare mocks: what to expect
        manager.setNavigator(EasyMock.anyObject(Navigator.class));

        EasyMock.expect(provider.getViewName("test2")).andReturn("test2");
        EasyMock.expect(provider.getView("test2")).andReturn(view2);
        EasyMock.expect(manager.getState()).andReturn("view1");
        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.enter(eventParametersEqual(""));
        display.showView(view1);
        manager.setState("test1");

        EasyMock.expect(provider.getViewName("test1/params"))
                .andReturn("test1");
        EasyMock.expect(provider.getView("test1")).andReturn(view1);
        EasyMock.expect(manager.getState()).andReturn("test2");
        view1.enter(eventParametersEqual("params"));
        display.showView(view1);
        manager.setState("test1/params");

        control.replay();

        // create and test navigator
        Navigator navigator = createNavigator(manager, display);
        navigator.addProvider(provider);
View Full Code Here

        navigator.navigateTo("");
        navigator.navigateTo("test1/params");
    }

    public void testListeners() {
        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 listener = new ViewChangeTestListener();

        // create navigator to test
        Navigator navigator = createNavigator(manager, display);

        // prepare mocks: what to expect
        EasyMock.expect(provider.getViewName("test1")).andReturn("test1");
        EasyMock.expect(provider.getView("test1")).andReturn(view1);
        ViewChangeEvent event1 = new ViewChangeEvent(navigator, null, view1,
                "test1", "");
        listener.addExpectedIsViewChangeAllowed(event1, true);
        EasyMock.expect(manager.getState()).andReturn("");
        view1.enter(eventParametersEqual(""));
        display.showView(view1);
        manager.setState("test1");
        listener.addExpectedNavigatorViewChange(event1);

        EasyMock.expect(provider.getViewName("test2")).andReturn("test2");
        EasyMock.expect(provider.getView("test2")).andReturn(view2);
        ViewChangeEvent event2 = new ViewChangeEvent(navigator, view1, view2,
                "test2", "");
        listener.addExpectedIsViewChangeAllowed(event2, true);
        EasyMock.expect(manager.getState()).andReturn("test1");
        view2.enter(eventParametersEqual(""));
        display.showView(view2);
        manager.setState("test2");
        listener.addExpectedNavigatorViewChange(event2);

        control.replay();

        // test navigator
        navigator.addProvider(provider);
        navigator.addViewChangeListener(listener);
View Full Code Here

    VaadinSession session;
    UI ui;

    @Before
    public void setUp() {
        IMocksControl control = EasyMock.createNiceControl();

        request = control.createMock(VaadinRequest.class);
        response = control.createMock(VaadinResponse.class);
        VaadinService service = control.createMock(VaadinService.class);

        EasyMock.expect(request.getPathInfo())
                .andReturn("/APP/connector/0/1/2");

        control.replay();

        session = new MockVaadinSession(service);

        ui = new UI() {
            @Override
View Full Code Here

        assertEquals("Incorrect fragment value", "test", manager.getState());
    }

    public void testListener() {
        // create mocks
        IMocksControl control = EasyMock.createControl();
        Navigator navigator = control.createMock(Navigator.class);
        Page page = control.createMock(Page.class);

        UriFragmentManager manager = new UriFragmentManager(page);
        manager.setNavigator(navigator);

        EasyMock.expect(page.getUriFragment()).andReturn("!test");
        navigator.navigateTo("test");
        control.replay();

        UriFragmentChangedEvent event = new UriFragmentChangedEvent(page,
                "oldtest");
        manager.uriFragmentChanged(event);
    }
View Full Code Here

        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);
View Full Code Here

        navigator.setErrorProvider(errorProvider);
        navigator.navigateTo("doesnotexist2");
    }

    public void testShowViewEnterOrder() {
        IMocksControl control = EasyMock.createStrictControl();

        View view = control.createMock(View.class);
        ViewDisplay display = control.createMock(ViewDisplay.class);

        display.showView(view);
        view.enter(EasyMock.anyObject(ViewChangeEvent.class));

        control.replay();

        NavigationStateManager manager = EasyMock
                .createNiceMock(NavigationStateManager.class);
        EasyMock.replay(manager);
View Full Code Here

TOP

Related Classes of org.easymock.IMocksControl

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.