Search in sources :

Example 11 with JUnit4Mockery

use of org.jmock.integration.junit4.JUnit4Mockery in project intellij-community by JetBrains.

the class TabPostFormatProcessorTest method setUp.

@Before
public void setUp() {
    myMockery = new JUnit4Mockery() {

        {
            setImposteriser(ClassImposteriser.INSTANCE);
        }
    };
    myDocument = myMockery.mock(Document.class);
}
Also used : JUnit4Mockery(org.jmock.integration.junit4.JUnit4Mockery) Document(com.intellij.openapi.editor.Document) Before(org.junit.Before)

Example 12 with JUnit4Mockery

use of org.jmock.integration.junit4.JUnit4Mockery in project intellij-community by JetBrains.

the class PathMacroManagerTest method setupApplication.

@Before
public final void setupApplication() throws Exception {
    context = new JUnit4Mockery();
    context.setImposteriser(ClassImposteriser.INSTANCE);
    myApplication = context.mock(ApplicationEx.class, "application");
    context.checking(new Expectations() {

        {
            allowing(myApplication).isUnitTestMode();
            will(returnValue(false));
            allowing(myApplication).getName();
            will(returnValue("IDEA"));
            // some tests leave invokeLater()'s after them
            allowing(myApplication).invokeLater(with(any(Runnable.class)), with(any(ModalityState.class)));
            allowing(myApplication).runReadAction(with(any(Runnable.class)));
            will(new Action() {

                @Override
                public void describeTo(final Description description) {
                    description.appendText("runs runnable");
                }

                @Override
                @Nullable
                public Object invoke(final Invocation invocation) throws Throwable {
                    ((Runnable) invocation.getParameter(0)).run();
                    return null;
                }
            });
        }
    });
    final ExtensionsArea area = Extensions.getRootArea();
    final String epName = PathMacrosCollector.MACRO_FILTER_EXTENSION_POINT_NAME.getName();
    if (!area.hasExtensionPoint(epName)) {
        area.registerExtensionPoint(epName, "com.intellij.openapi.application.PathMacroFilter");
        Disposer.register(myRootDisposable, new Disposable() {

            @Override
            public void dispose() {
                area.unregisterExtensionPoint(epName);
            }
        });
    }
}
Also used : Expectations(org.jmock.Expectations) Disposable(com.intellij.openapi.Disposable) ExtensionsArea(com.intellij.openapi.extensions.ExtensionsArea) JUnit4Mockery(org.jmock.integration.junit4.JUnit4Mockery) Action(org.jmock.api.Action) Description(org.hamcrest.Description) ApplicationEx(com.intellij.openapi.application.ex.ApplicationEx) Invocation(org.jmock.api.Invocation) ModalityState(com.intellij.openapi.application.ModalityState) Before(org.junit.Before)

Example 13 with JUnit4Mockery

use of org.jmock.integration.junit4.JUnit4Mockery in project sling by apache.

the class RepositoryTestHelper method mockResourceResolverFactory.

public static ResourceResolverFactory mockResourceResolverFactory(final SlingRepository repositoryOrNull) throws Exception {
    Mockery context = new JUnit4Mockery() {

        {
            // @see http://www.jmock.org/threading-synchroniser.html
            setThreadingPolicy(new Synchroniser());
        }
    };
    final ResourceResolverFactory resourceResolverFactory = context.mock(ResourceResolverFactory.class);
    // final ResourceResolver resourceResolver = new MockResourceResolver();
    // final ResourceResolver resourceResolver = new
    // MockedResourceResolver();
    context.checking(new Expectations() {

        {
            allowing(resourceResolverFactory).getServiceResourceResolver(null);
            will(new Action() {

                @Override
                public Object invoke(Invocation invocation) throws Throwable {
                    return new MockedResourceResolver(repositoryOrNull);
                }

                @Override
                public void describeTo(Description arg0) {
                    arg0.appendText("whateva - im going to create a new mockedresourceresolver");
                }
            });
        }
    });
    return resourceResolverFactory;
}
Also used : Expectations(org.jmock.Expectations) JUnit4Mockery(org.jmock.integration.junit4.JUnit4Mockery) Action(org.jmock.api.Action) ResourceResolverFactory(org.apache.sling.api.resource.ResourceResolverFactory) Description(org.hamcrest.Description) Invocation(org.jmock.api.Invocation) Synchroniser(org.jmock.lib.concurrent.Synchroniser) Mockery(org.jmock.Mockery) JUnit4Mockery(org.jmock.integration.junit4.JUnit4Mockery)

Aggregations

JUnit4Mockery (org.jmock.integration.junit4.JUnit4Mockery)13 Expectations (org.jmock.Expectations)7 Before (org.junit.Before)7 Mockery (org.jmock.Mockery)4 Project (org.gradle.api.Project)3 Task (org.gradle.api.Task)3 Dictionary (java.util.Dictionary)2 FavoriteTask (org.gradle.gradleplugin.foundation.favorites.FavoriteTask)2 Description (org.hamcrest.Description)2 Action (org.jmock.api.Action)2 Invocation (org.jmock.api.Invocation)2 ComponentContext (org.osgi.service.component.ComponentContext)2 Disposable (com.intellij.openapi.Disposable)1 ModalityState (com.intellij.openapi.application.ModalityState)1 ApplicationEx (com.intellij.openapi.application.ex.ApplicationEx)1 Document (com.intellij.openapi.editor.Document)1 ExtensionsArea (com.intellij.openapi.extensions.ExtensionsArea)1 Project (com.intellij.openapi.project.Project)1 ExtensionLoader (com.weibo.api.motan.core.extension.ExtensionLoader)1 RegistryFactory (com.weibo.api.motan.registry.RegistryFactory)1