Examples of IAnswer


Examples of org.easymock.IAnswer

        FieldTranslator translator = mockFieldTranslator();
        NullFieldStrategy nullFieldStrategy = mockNullFieldStrategy();

        final String clientValue = "abracadabra";

        IAnswer answer = new IAnswer()
        {
            @SuppressWarnings({"unchecked"})
            public Object answer() throws Throwable
            {
                Object[] args = EasyMock.getCurrentArguments();
View Full Code Here

Examples of org.easymock.IAnswer

    {
        Object value = new Object();
        ComponentResources resources = mockComponentResources();
        FieldTranslator translator = mockFieldTranslator();

        IAnswer answer = new IAnswer()
        {
            @SuppressWarnings({"unchecked"})
            public Object answer() throws Throwable
            {
                Object[] args = EasyMock.getCurrentArguments();
View Full Code Here

Examples of org.easymock.IAnswer

    @SuppressWarnings("unchecked")
    protected final void train_renderInformalParameters(ComponentResources resources,
            final MarkupWriter writer, final String... informals)
    {
        resources.renderInformalParameters(writer);
        IAnswer answer = new IAnswer()
        {
            public Object answer() throws Throwable
            {
                writer.attributes(informals);
View Full Code Here

Examples of org.easymock.IAnswer

        final Hashtable<String, Object> expectedProxyProps = new Hashtable<String, Object>(serviceProps);
        expectedProxyProps.put(GuardProxyCatalog.PROXY_SERVICE_KEY, Boolean.TRUE);
        EasyMock.expect(providerBC.registerService(
                EasyMock.isA(String[].class),
                EasyMock.anyObject(),
                EasyMock.isA(Dictionary.class))).andAnswer(new IAnswer() {
            @Override
            public ServiceRegistration answer() throws Throwable {
                Dictionary<String,Object> props = (Dictionary<String, Object>) EasyMock.getCurrentArguments()[2];
                ServiceRegistration reg = EasyMock.createMock(ServiceRegistration.class);
                ServiceReference sr = mockServiceReference(props);
View Full Code Here

Examples of org.easymock.IAnswer

        BundleContext providerBC = EasyMock.createNiceMock(BundleContext.class);
        EasyMock.expect(providerBC.registerService(
                EasyMock.aryEq(new String [] {TestServiceAPI.class.getName(), TestServiceAPI2.class.getName()}),
                EasyMock.anyObject(),
                EasyMock.anyObject(Dictionary.class))).andAnswer(new IAnswer() {
            @Override
            public Object answer() throws Throwable {
                final Dictionary props = (Dictionary) EasyMock.getCurrentArguments()[2];
                assertEquals(Boolean.TRUE, props.get(GuardProxyCatalog.PROXY_SERVICE_KEY));
View Full Code Here

Examples of org.easymock.IAnswer

        BundleContext providerBC = EasyMock.createNiceMock(BundleContext.class);
        EasyMock.expect(providerBC.registerService(
                EasyMock.aryEq(new String [] {TestServiceAPI.class.getName()}),
                EasyMock.anyObject(),
                EasyMock.anyObject(Dictionary.class))).andAnswer(new IAnswer() {
            @Override
            public Object answer() throws Throwable {
                final Dictionary props = (Dictionary) EasyMock.getCurrentArguments()[2];
                assertEquals(Boolean.TRUE, props.get(GuardProxyCatalog.PROXY_SERVICE_KEY));
View Full Code Here

Examples of org.easymock.IAnswer

        BundleContext providerBC = EasyMock.createMock(BundleContext.class);
        EasyMock.expect(providerBC.registerService(
                EasyMock.isA(String[].class),
                EasyMock.anyObject(),
                EasyMock.isA(Dictionary.class))).andAnswer(new IAnswer() {
            @Override
            public ServiceRegistration answer() throws Throwable {
                Dictionary<String,Object> props = (Dictionary<String, Object>) EasyMock.getCurrentArguments()[2];
                ServiceRegistration reg = EasyMock.createMock(ServiceRegistration.class);
                ServiceReference sr = mockServiceReference(props);
View Full Code Here

Examples of org.easymock.IAnswer

        expectedProxyProps.put(GuardProxyCatalog.PROXY_SERVICE_KEY, Boolean.TRUE);
        // This will check that the right proxy is being registered.
        EasyMock.expect(providerBC.registerService(
                EasyMock.isA(String[].class),
                EasyMock.anyObject(),
                EasyMock.isA(Dictionary.class))).andAnswer(new IAnswer() {
            @Override
            public ServiceRegistration answer() throws Throwable {
                if (!runningUnderCoverage) {
                    // Some of these checks don't work when running under coverage
                    assertArrayEquals(new String [] {proxyRegClass.getName()},
View Full Code Here

Examples of org.easymock.IAnswer

        expectedProxyProps.put(GuardProxyCatalog.PROXY_SERVICE_KEY, Boolean.TRUE);
        // This will check that the right proxy is being registered.
        EasyMock.expect(providerBC.registerService(
                EasyMock.isA(String[].class),
                EasyMock.anyObject(),
                EasyMock.isA(Dictionary.class))).andAnswer(new IAnswer() {
            @Override
            public ServiceRegistration answer() throws Throwable {
                if (!runningUnderCoverage) {
                    // Some of these checks don't work when running under coverage
                    assertArrayEquals(proxyRegClsMap.keySet().toArray(new String [] {}),
                            (String []) EasyMock.getCurrentArguments()[0]);

                    Object svc = EasyMock.getCurrentArguments()[1];
                    assertTrue(svc instanceof ServiceFactory);
                }

                Dictionary<String,Object> props = (Dictionary<String, Object>) EasyMock.getCurrentArguments()[2];
                for (String key : expectedProxyProps.keySet()) {
                    if (GuardProxyCatalog.SERVICE_GUARD_ROLES_PROPERTY.equals(key)) {
                        assertTrue("The roles property should have been overwritten",
                                !Arrays.asList("everyone").equals(props.get(key)));
                    } else {
                        assertEquals(expectedProxyProps.get(key), props.get(key));
                    }
                }

                ServiceRegistration reg = EasyMock.createMock(ServiceRegistration.class);
                ServiceReference sr = mockServiceReference(props);
                EasyMock.expect(reg.getReference()).andReturn(sr).anyTimes();
                reg.unregister();
                EasyMock.expectLastCall().once();
                EasyMock.replay(reg);

                serviceMap.put(sr, EasyMock.getCurrentArguments()[1]);

                return reg;
            }
        }).once();
        EasyMock.expect(providerBC.getService(EasyMock.isA(ServiceReference.class))).andAnswer(new IAnswer<Object>() {
            @Override
            public Object answer() throws Throwable {
                return serviceMap.get(EasyMock.getCurrentArguments()[0]);
            }
        }).anyTimes();
        EasyMock.replay(providerBC);

        // In some cases the proxy-creating code is looking for a classloader (e.g. when run through
        // a coverage tool such as EclEmma). This will satisfy that.
        BundleWiring bw = EasyMock.createMock(BundleWiring.class);
        EasyMock.expect(bw.getClassLoader()).andReturn(getClass().getClassLoader()).anyTimes();
        EasyMock.replay(bw);

        // The mock bundle that provides the original service (and also the proxy is registered with this)
        Bundle providerBundle = EasyMock.createNiceMock(Bundle.class);
        EasyMock.expect(providerBundle.getBundleContext()).andReturn(providerBC).anyTimes();
        EasyMock.expect(providerBundle.adapt(BundleWiring.class)).andReturn(bw).anyTimes();
        EasyMock.replay(providerBundle);

        ServiceReference sr = mockServiceReference(providerBundle, serviceProps);

        // The mock bundle context for the client bundle
        BundleContext clientBC = EasyMock.createMock(BundleContext.class);
        EasyMock.expect(clientBC.getService(sr)).andReturn(testService).anyTimes();
        EasyMock.replay(clientBC);

        // The mock bundle that consumes the service
        Bundle clientBundle = EasyMock.createNiceMock(Bundle.class);
        EasyMock.expect(clientBundle.getBundleId()).andReturn(2999L).anyTimes();
        EasyMock.expect(clientBundle.getBundleContext()).andReturn(clientBC).anyTimes();
        EasyMock.expect(clientBundle.loadClass(EasyMock.isA(String.class))).andAnswer(new IAnswer() {
            @Override
            public Class answer() throws Throwable {
                return objClsMap.get(EasyMock.getCurrentArguments()[0]);
            }
        }).anyTimes();
View Full Code Here

Examples of org.easymock.IAnswer

        ObjectLocator locator = mockObjectLocator();

        train_get(source, ApplicationStateManagerImpl.DEFAULT_STRATEGY, strategy);


        IAnswer answer = new IAnswer()
        {
            public Object answer() throws Throwable
            {
                ApplicationStateCreator creator = (ApplicationStateCreator) EasyMock
                        .getCurrentArguments()[1];
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.