Search in sources :

Example 1 with MockAdapterFactory

use of org.apache.sling.adapter.mock.MockAdapterFactory in project sling by apache.

the class AdapterManagerTest method createComponentContext.

/**
     * Helper method to create a mock component context
     */
protected ComponentContext createComponentContext() throws Exception {
    final BundleContext bundleCtx = this.context.mock(BundleContext.class);
    final Filter filter = this.context.mock(Filter.class);
    final ComponentContext ctx = this.context.mock(ComponentContext.class);
    this.context.checking(new Expectations() {

        {
            allowing(ctx).locateService(with(any(String.class)), with(any(ServiceReference.class)));
            will(returnValue(new MockAdapterFactory()));
            allowing(ctx).getBundleContext();
            will(returnValue(bundleCtx));
            allowing(bundleCtx).createFilter(with(any(String.class)));
            will(returnValue(filter));
            allowing(bundleCtx).addServiceListener(with(any(ServiceListener.class)), with(any(String.class)));
            allowing(bundleCtx).getServiceReferences(with(any(String.class)), with(any(String.class)));
            will(returnValue(null));
            allowing(bundleCtx).removeServiceListener(with(any(ServiceListener.class)));
            allowing(bundleCtx).registerService(with(Adaption.class), with(AdaptionImpl.INSTANCE), with(any(Dictionary.class)));
            will(returnValue(null));
        }
    });
    return ctx;
}
Also used : Expectations(org.jmock.Expectations) Dictionary(java.util.Dictionary) ServiceListener(org.osgi.framework.ServiceListener) ComponentContext(org.osgi.service.component.ComponentContext) Filter(org.osgi.framework.Filter) MockAdapterFactory(org.apache.sling.adapter.mock.MockAdapterFactory) BundleContext(org.osgi.framework.BundleContext) ServiceReference(org.osgi.framework.ServiceReference)

Aggregations

Dictionary (java.util.Dictionary)1 MockAdapterFactory (org.apache.sling.adapter.mock.MockAdapterFactory)1 Expectations (org.jmock.Expectations)1 BundleContext (org.osgi.framework.BundleContext)1 Filter (org.osgi.framework.Filter)1 ServiceListener (org.osgi.framework.ServiceListener)1 ServiceReference (org.osgi.framework.ServiceReference)1 ComponentContext (org.osgi.service.component.ComponentContext)1