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;
}
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();
}
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);
}
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);
}
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);
}
});
}
}
Aggregations