Search in sources :

Example 1 with JUnit4Mockery

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

the class FilterTest method setUp.

protected void setUp() throws Exception {
    JUnit4Mockery 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");
    assertNotNull(myRootProject);
    mySubProject1 = buildInformation.getProjectFromFullPath("myrootproject:mysubproject1");
    assertNotNull(mySubProject1);
    mySubProject1Comple = buildInformation.getTaskFromFullPath("myrootproject:mysubproject1:compile");
    assertNotNull(mySubProject1Comple);
    mySubProject1Lib = buildInformation.getTaskFromFullPath("myrootproject:mysubproject1:lib");
    assertNotNull(mySubProject1Lib);
    mySubProject1Doc = buildInformation.getTaskFromFullPath("myrootproject:mysubproject1:doc");
    assertNotNull(mySubProject1Doc);
    mySubSubProject = buildInformation.getProjectFromFullPath("myrootproject:mysubproject1:mysubsubproject");
    assertNotNull(mySubSubProject);
    mySubSubProjectCompile = buildInformation.getTaskFromFullPath("myrootproject:mysubproject1:mysubsubproject:compile");
    assertNotNull(mySubSubProjectCompile);
    mySubSubProjectLib = buildInformation.getTaskFromFullPath("myrootproject:mysubproject1:mysubsubproject:lib");
    assertNotNull(mySubSubProjectLib);
    mySubSubProjectDoc = buildInformation.getTaskFromFullPath("myrootproject:mysubproject1:mysubsubproject:doc");
    assertNotNull(mySubSubProjectDoc);
    mySubProject2 = buildInformation.getProjectFromFullPath("myrootproject:mysubproject2");
    assertNotNull(mySubProject2);
    mySubProject2Compile = buildInformation.getTaskFromFullPath("myrootproject:mysubproject2:compile");
    assertNotNull(mySubProject2Compile);
    mySubProject2Lib = buildInformation.getTaskFromFullPath("myrootproject:mysubproject2:lib");
    assertNotNull(mySubProject2Lib);
    mySubProject2doc = buildInformation.getTaskFromFullPath("myrootproject:mysubproject2:doc");
    assertNotNull(mySubProject2doc);
}
Also used : Project(org.gradle.api.Project) JUnit4Mockery(org.jmock.integration.junit4.JUnit4Mockery) Task(org.gradle.api.Task)

Example 2 with JUnit4Mockery

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

the class MockFactory method mockSlingSettingsService.

public static SlingSettingsService mockSlingSettingsService(final String slingId) {
    Mockery context = new JUnit4Mockery();
    final SlingSettingsService settingsService = context.mock(SlingSettingsService.class);
    context.checking(new Expectations() {

        {
            allowing(settingsService).getSlingId();
            will(returnValue(slingId));
            allowing(settingsService).getSlingHomePath();
            will(returnValue("/n/a"));
        }
    });
    return settingsService;
}
Also used : Expectations(org.jmock.Expectations) JUnit4Mockery(org.jmock.integration.junit4.JUnit4Mockery) JUnit4Mockery(org.jmock.integration.junit4.JUnit4Mockery) Mockery(org.jmock.Mockery) SlingSettingsService(org.apache.sling.settings.SlingSettingsService)

Example 3 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 4 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 5 with JUnit4Mockery

use of org.jmock.integration.junit4.JUnit4Mockery in project motan by weibocom.

the class MockServiceConfig method setUp.

@Before
@Override
public void setUp() throws Exception {
    mockery = new JUnit4Mockery() {

        {
            setImposteriser(ClassImposteriser.INSTANCE);
        }
    };
    InetAddress address = NetUtils.getLocalAddress();
    if (address != null) {
        localAddress = address.getHostAddress();
    }
}
Also used : JUnit4Mockery(org.jmock.integration.junit4.JUnit4Mockery) InetAddress(java.net.InetAddress) 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