Search in sources :

Example 6 with JUnit4Mockery

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

the class MockFactory method mockComponentContext.

public static ComponentContext mockComponentContext() {
    Mockery context = new JUnit4Mockery();
    final BundleContext bc = context.mock(BundleContext.class);
    context.checking(new Expectations() {

        {
            allowing(bc).registerService(with(any(String.class)), with(any(Object.class)), with(any(Dictionary.class)));
            will(VoidAction.INSTANCE);
            allowing(bc).getProperty(with(any(String.class)));
            will(new ReturnValueAction("foo"));
        }
    });
    final ComponentContext cc = context.mock(ComponentContext.class);
    context.checking(new Expectations() {

        {
            allowing(cc).getProperties();
            will(returnValue(new Properties()));
            allowing(cc).getBundleContext();
            will(returnValue(bc));
        }
    });
    return cc;
}
Also used : Expectations(org.jmock.Expectations) Dictionary(java.util.Dictionary) ReturnValueAction(org.jmock.lib.action.ReturnValueAction) JUnit4Mockery(org.jmock.integration.junit4.JUnit4Mockery) ComponentContext(org.osgi.service.component.ComponentContext) Properties(java.util.Properties) JUnit4Mockery(org.jmock.integration.junit4.JUnit4Mockery) Mockery(org.jmock.Mockery) BundleContext(org.osgi.framework.BundleContext)

Example 7 with JUnit4Mockery

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

the class VirtualInstance method startJetty.

public synchronized void startJetty() throws Throwable {
    if (jettyServer != null) {
        return;
    }
    servletContext = new ServletContextHandler(ServletContextHandler.NO_SECURITY);
    servletContext.setContextPath("/");
    TopologyConnectorServlet servlet = new TopologyConnectorServlet();
    PrivateAccessor.setField(servlet, "config", config);
    PrivateAccessor.setField(servlet, "clusterViewService", clusterViewService);
    PrivateAccessor.setField(servlet, "announcementRegistry", announcementRegistry);
    Mockery context = new JUnit4Mockery();
    final HttpService httpService = context.mock(HttpService.class);
    context.checking(new Expectations() {

        {
            allowing(httpService).registerServlet(with(any(String.class)), with(any(Servlet.class)), with(any(Dictionary.class)), with(any(HttpContext.class)));
        }
    });
    PrivateAccessor.setField(servlet, "httpService", httpService);
    ComponentContext cc = null;
    PrivateAccessor.invoke(servlet, "activate", new Class[] { ComponentContext.class }, new Object[] { cc });
    ServletHolder holder = new ServletHolder(servlet);
    servletContext.addServlet(holder, "/system/console/topology/*");
    jettyServer = new Server();
    jettyServer.setHandler(servletContext);
    Connector connector = new SelectChannelConnector();
    jettyServer.setConnectors(new Connector[] { connector });
    jettyServer.start();
}
Also used : Expectations(org.jmock.Expectations) Dictionary(java.util.Dictionary) SelectChannelConnector(org.eclipse.jetty.server.nio.SelectChannelConnector) Connector(org.eclipse.jetty.server.Connector) ComponentContext(org.osgi.service.component.ComponentContext) Server(org.eclipse.jetty.server.Server) TopologyConnectorServlet(org.apache.sling.discovery.base.connectors.ping.TopologyConnectorServlet) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) HttpContext(org.osgi.service.http.HttpContext) Mockery(org.jmock.Mockery) JUnit4Mockery(org.jmock.integration.junit4.JUnit4Mockery) JUnit4Mockery(org.jmock.integration.junit4.JUnit4Mockery) SelectChannelConnector(org.eclipse.jetty.server.nio.SelectChannelConnector) HttpService(org.osgi.service.http.HttpService) TopologyConnectorServlet(org.apache.sling.discovery.base.connectors.ping.TopologyConnectorServlet) Servlet(javax.servlet.Servlet) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler)

Example 8 with JUnit4Mockery

use of org.jmock.integration.junit4.JUnit4Mockery in project gradle by gradle.

the class FavoritesIntegrationTest method setUp.

@Before
public void setUp() throws Exception {
    context = new JUnit4Mockery();
    Task subsubCompileTask = TestUtility.createTask(context, "compile", "compile description");
    Task subsubLibTask = TestUtility.createTask(context, "lib", "lib description");
    Task subsubDocTask = TestUtility.createTask(context, "doc", "doc description");
    Project subsubProject = TestUtility.createMockProject(context, "mysubsubproject", "filepath3", 2, null, new Task[] { subsubCompileTask, subsubLibTask, subsubDocTask }, null);
    Task subCompileTask1 = TestUtility.createTask(context, "compile", "compile description");
    Task subLibTask1 = TestUtility.createTask(context, "lib", "lib description");
    Task subDocTask1 = TestUtility.createTask(context, "doc", "doc description");
    Project subProject1 = TestUtility.createMockProject(context, "mysubproject1", "filepath2a", 1, new Project[] { subsubProject }, new Task[] { subCompileTask1, subLibTask1, subDocTask1 }, null);
    Task subCompileTask2 = TestUtility.createTask(context, "compile", "compile description");
    Task subLibTask2 = TestUtility.createTask(context, "lib", "lib description");
    Task subDocTask2 = TestUtility.createTask(context, "doc", "doc description");
    Project subProject2 = TestUtility.createMockProject(context, "mysubproject2", "filepath2b", 1, null, new Task[] { subCompileTask2, subLibTask2, subDocTask2 }, null);
    Project rootProject = TestUtility.createMockProject(context, "myrootproject", "filepath1", 0, new Project[] { subProject1, subProject2 }, null, null);
    buildInformation = new BuildInformation(rootProject);
    //now get the converted objects to simplify our matching
    myRootProject = buildInformation.getProjectFromFullPath("myrootproject");
    Assert.assertNotNull(myRootProject);
    mySubProject1 = buildInformation.getProjectFromFullPath("myrootproject:mysubproject1");
    Assert.assertNotNull(mySubProject1);
    mySubProject1Comple = buildInformation.getTaskFromFullPath("myrootproject:mysubproject1:compile");
    Assert.assertNotNull(mySubProject1Comple);
    mySubProject1Lib = buildInformation.getTaskFromFullPath("myrootproject:mysubproject1:lib");
    Assert.assertNotNull(mySubProject1Lib);
    mySubProject1Doc = buildInformation.getTaskFromFullPath("myrootproject:mysubproject1:doc");
    Assert.assertNotNull(mySubProject1Doc);
    mySubSubProject = buildInformation.getProjectFromFullPath("myrootproject:mysubproject1:mysubsubproject");
    Assert.assertNotNull(mySubSubProject);
    mySubSubProjectCompile = buildInformation.getTaskFromFullPath("myrootproject:mysubproject1:mysubsubproject:compile");
    Assert.assertNotNull(mySubSubProjectCompile);
    mySubSubProjectLib = buildInformation.getTaskFromFullPath("myrootproject:mysubproject1:mysubsubproject:lib");
    Assert.assertNotNull(mySubSubProjectLib);
    mySubSubProjectDoc = buildInformation.getTaskFromFullPath("myrootproject:mysubproject1:mysubsubproject:doc");
    Assert.assertNotNull(mySubSubProjectDoc);
    mySubProject2 = buildInformation.getProjectFromFullPath("myrootproject:mysubproject2");
    Assert.assertNotNull(mySubProject2);
    mySubProject2Compile = buildInformation.getTaskFromFullPath("myrootproject:mysubproject2:compile");
    Assert.assertNotNull(mySubProject2Compile);
    mySubProject2Lib = buildInformation.getTaskFromFullPath("myrootproject:mysubproject2:lib");
    Assert.assertNotNull(mySubProject2Lib);
    mySubProject2doc = buildInformation.getTaskFromFullPath("myrootproject:mysubproject2:doc");
    Assert.assertNotNull(mySubProject2doc);
}
Also used : Project(org.gradle.api.Project) JUnit4Mockery(org.jmock.integration.junit4.JUnit4Mockery) FavoriteTask(org.gradle.gradleplugin.foundation.favorites.FavoriteTask) Task(org.gradle.api.Task) BuildInformation(org.gradle.foundation.BuildInformation) Before(org.junit.Before)

Example 9 with JUnit4Mockery

use of org.jmock.integration.junit4.JUnit4Mockery in project gradle by gradle.

the class FavoritesTest method setUp.

@Before
public void setUp() throws Exception {
    context = new JUnit4Mockery();
    Task subsubCompileTask = TestUtility.createTask(context, "compile", "compile description");
    Task subsubLibTask = TestUtility.createTask(context, "lib", "lib description");
    Task subsubDocTask = TestUtility.createTask(context, "doc", "doc description");
    Project subsubProject = TestUtility.createMockProject(context, "mysubsubproject", "filepath3", 2, null, new Task[] { subsubCompileTask, subsubLibTask, subsubDocTask }, null);
    Task subCompileTask1 = TestUtility.createTask(context, "compile", "compile description");
    Task subLibTask1 = TestUtility.createTask(context, "lib", "lib description");
    Task subDocTask1 = TestUtility.createTask(context, "doc", "doc description");
    Project subProject1 = TestUtility.createMockProject(context, "mysubproject1", "filepath2a", 1, new Project[] { subsubProject }, new Task[] { subCompileTask1, subLibTask1, subDocTask1 }, null);
    Task subCompileTask2 = TestUtility.createTask(context, "compile", "compile description");
    Task subLibTask2 = TestUtility.createTask(context, "lib", "lib description");
    Task subDocTask2 = TestUtility.createTask(context, "doc", "doc description");
    Project subProject2 = TestUtility.createMockProject(context, "mysubproject2", "filepath2b", 1, null, new Task[] { subCompileTask2, subLibTask2, subDocTask2 }, null);
    Project rootProject = TestUtility.createMockProject(context, "myrootproject", "filepath1", 0, new Project[] { subProject1, subProject2 }, null, null);
    buildInformation = new BuildInformation(rootProject);
    //now get the converted objects to simplify our matching
    myRootProject = buildInformation.getProjectFromFullPath("myrootproject");
    Assert.assertNotNull(myRootProject);
    mySubProject1 = buildInformation.getProjectFromFullPath("myrootproject:mysubproject1");
    Assert.assertNotNull(mySubProject1);
    mySubProject1Comple = buildInformation.getTaskFromFullPath("myrootproject:mysubproject1:compile");
    Assert.assertNotNull(mySubProject1Comple);
    mySubProject1Lib = buildInformation.getTaskFromFullPath("myrootproject:mysubproject1:lib");
    Assert.assertNotNull(mySubProject1Lib);
    mySubProject1Doc = buildInformation.getTaskFromFullPath("myrootproject:mysubproject1:doc");
    Assert.assertNotNull(mySubProject1Doc);
    mySubSubProject = buildInformation.getProjectFromFullPath("myrootproject:mysubproject1:mysubsubproject");
    Assert.assertNotNull(mySubSubProject);
    mySubSubProjectCompile = buildInformation.getTaskFromFullPath("myrootproject:mysubproject1:mysubsubproject:compile");
    Assert.assertNotNull(mySubSubProjectCompile);
    mySubSubProjectLib = buildInformation.getTaskFromFullPath("myrootproject:mysubproject1:mysubsubproject:lib");
    Assert.assertNotNull(mySubSubProjectLib);
    mySubSubProjectDoc = buildInformation.getTaskFromFullPath("myrootproject:mysubproject1:mysubsubproject:doc");
    Assert.assertNotNull(mySubSubProjectDoc);
    mySubProject2 = buildInformation.getProjectFromFullPath("myrootproject:mysubproject2");
    Assert.assertNotNull(mySubProject2);
    mySubProject2Compile = buildInformation.getTaskFromFullPath("myrootproject:mysubproject2:compile");
    Assert.assertNotNull(mySubProject2Compile);
    mySubProject2Lib = buildInformation.getTaskFromFullPath("myrootproject:mysubproject2:lib");
    Assert.assertNotNull(mySubProject2Lib);
    mySubProject2doc = buildInformation.getTaskFromFullPath("myrootproject:mysubproject2:doc");
    Assert.assertNotNull(mySubProject2doc);
}
Also used : Project(org.gradle.api.Project) JUnit4Mockery(org.jmock.integration.junit4.JUnit4Mockery) Task(org.gradle.api.Task) FavoriteTask(org.gradle.gradleplugin.foundation.favorites.FavoriteTask) Before(org.junit.Before)

Example 10 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)

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