Search in sources :

Example 1 with Mock

use of org.jmock.Mock in project intellij-plugins by JetBrains.

the class JabberTransportTest method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    myFacade = new MockJabberFacade();
    myUIMock = mock(JabberUI.class);
    myUserModel = new UserModelImpl(getBroadcaster());
    disposeOnTearDown(myUserModel);
    Mock dispatcherMock = mock(AsyncMessageDispatcher.class);
    myIDEFacade = new MockIDEFacade();
    dispatcherMock.stubs().method("getIdeFacade").will(returnValue(myIDEFacade));
    myTransport = new JabberTransport((JabberUI) myUIMock.proxy(), myFacade, myUserModel, (AsyncMessageDispatcher) dispatcherMock.proxy(), null);
    disposeOnTearDown(myTransport);
    myProjectContainer = Pico.getInstance().makeChildContainer();
}
Also used : MockIDEFacade(jetbrains.communicator.mock.MockIDEFacade) AsyncMessageDispatcher(jetbrains.communicator.core.dispatcher.AsyncMessageDispatcher) MockJabberFacade(jetbrains.communicator.jabber.register.MockJabberFacade) JabberUI(jetbrains.communicator.jabber.JabberUI) UserModelImpl(jetbrains.communicator.core.impl.users.UserModelImpl) Mock(org.jmock.Mock)

Example 2 with Mock

use of org.jmock.Mock in project intellij-plugins by JetBrains.

the class JabberUserFinderTest method testAskForRegister_AnswerYes.

public void testAskForRegister_AnswerYes() throws Exception {
    Mock facadeMock = mock(IDEFacade.class);
    final String[] params = new String[2];
    myUserFinder = new JabberUserFinderImpl((IDEFacade) facadeMock.proxy(), myUserModel) {

        @Override
        protected void doRegister(final String jabberUserId, final String currentProjectId) {
            params[0] = jabberUserId;
            params[1] = currentProjectId;
        }
    };
    set_project(facadeMock, "id1", true);
    myUserFinder.registerForProject("kir@fff");
    assertEquals("kir@fff", params[0]);
    assertEquals("id1", params[1]);
    params[0] = params[1] = null;
    set_project(facadeMock, "id1", false);
    myUserFinder.registerForProject("kir@fff");
    assertNull("No questions expected now - same user and project", params[0]);
    set_project(facadeMock, "id1", true);
    myUserFinder.registerForProject("kir@fff1");
    assertEquals("Another user, expect question", "kir@fff1", params[0]);
    params[0] = params[1] = null;
    set_project(facadeMock, "id2", true);
    myUserFinder.registerForProject("kir@fff1");
    assertEquals("Another project, expect question", "kir@fff1", params[0]);
}
Also used : Mock(org.jmock.Mock) MockIDEFacade(jetbrains.communicator.mock.MockIDEFacade) IDEFacade(jetbrains.communicator.ide.IDEFacade)

Example 3 with Mock

use of org.jmock.Mock in project intellij-plugins by JetBrains.

the class JabberUserFinderTest method testAskForRegister_AnswerNo.

public void testAskForRegister_AnswerNo() throws Exception {
    Mock facadeMock = mock(IDEFacade.class);
    final String[] params = new String[2];
    myUserFinder = new JabberUserFinderImpl((IDEFacade) facadeMock.proxy(), myUserModel) {

        @Override
        protected void doRegister(final String jabberUserId, final String currentProjectId) {
            params[0] = jabberUserId;
            params[1] = currentProjectId;
        }
    };
    facadeMock.expects(atLeastOnce()).method("getCacheDir").will(returnValue(myFacade.getCacheDir()));
    facadeMock.expects(once()).method("getCurrentProjectId").will(returnValue("id1"));
    facadeMock.expects(once()).method("askQuestion").will(returnValue(false));
    myUserFinder.registerForProject("kir@fff");
    assertNull(params[0]);
}
Also used : Mock(org.jmock.Mock) MockIDEFacade(jetbrains.communicator.mock.MockIDEFacade) IDEFacade(jetbrains.communicator.ide.IDEFacade)

Example 4 with Mock

use of org.jmock.Mock in project intellij-plugins by JetBrains.

the class UserMonitorThreadTest method testProgressIndicatorInvocations.

public void testProgressIndicatorInvocations() throws Exception {
    expectSetOneOnlineUser();
    Mock mockProgressIndicator = mock(ProgressIndicator.class);
    mockProgressIndicator.expects(atLeastOnce()).method("setText").with(eq("Found in local network: 1 user"));
    mockProgressIndicator.expects(atLeastOnce()).method("checkCanceled");
    final double[] lastFraction = new double[] { -1 };
    mockProgressIndicator.expects(atLeastOnce()).method("setFraction").with(new IsGreaterThan(new Comparable() {

        @Override
        public int compareTo(Object o) {
            double v = ((Number) o).doubleValue();
            int result = (int) ((lastFraction[0] - v) * 100);
            lastFraction[0] = v;
            if (result >= 0) {
                System.out.println("result = " + result);
            }
            return result;
        }

        public String toString() {
            return "" + lastFraction[0];
        }
    }));
    myUserMonitorThread.findNow((ProgressIndicator) mockProgressIndicator.proxy());
    assertEquals("Should end at 100%", 1, lastFraction[0], 0.01);
}
Also used : IsGreaterThan(org.jmock.core.constraint.IsGreaterThan) Mock(org.jmock.Mock)

Example 5 with Mock

use of org.jmock.Mock in project intellij-plugins by JetBrains.

the class JabberTransport_ConnectionTest method createJabberUIMock.

private Mock createJabberUIMock() {
    Mock mockUI = mock(JabberUI.class);
    mockUI.stubs().method("connectAndLogin").will(new ReturnStub(Boolean.TRUE) {

        @Override
        public Object invoke(Invocation invocation) throws Throwable {
            myFacade.connect();
            return super.invoke(invocation);
        }
    });
    return mockUI;
}
Also used : Invocation(org.jmock.core.Invocation) ReturnStub(org.jmock.core.stub.ReturnStub) Mock(org.jmock.Mock)

Aggregations

Mock (org.jmock.Mock)49 DocumentReference (org.xwiki.model.reference.DocumentReference)18 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)17 Invocation (org.jmock.core.Invocation)10 XWikiContext (com.xpn.xwiki.XWikiContext)9 CustomStub (org.jmock.core.stub.CustomStub)9 XWikiAttachment (com.xpn.xwiki.doc.XWikiAttachment)6 BaseObject (com.xpn.xwiki.objects.BaseObject)6 Date (java.util.Date)5 MockIDEFacade (jetbrains.communicator.mock.MockIDEFacade)4 Document (com.xpn.xwiki.api.Document)3 XWikiStoreInterface (com.xpn.xwiki.store.XWikiStoreInterface)3 File (java.io.File)3 HashMap (java.util.HashMap)3 IDEFacade (jetbrains.communicator.ide.IDEFacade)3 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)3 XWiki (com.xpn.xwiki.XWiki)2 XWikiConfig (com.xpn.xwiki.XWikiConfig)2 XWikiHibernateStore (com.xpn.xwiki.store.XWikiHibernateStore)2 XWikiHibernateVersioningStore (com.xpn.xwiki.store.XWikiHibernateVersioningStore)2