Package org.mockito.internal

Examples of org.mockito.internal.InternalMockHandler


        if (isSpy) {
            settings.defaultAnswer(Mockito.CALLS_REAL_METHODS);
        }

        settings.setMockName(new MockNameImpl(mockName));
        InternalMockHandler mockHandler = new MockHandlerFactory().create(settings);
        MethodInterceptorFilter filter = new PowerMockMethodInterceptorFilter(
                mockHandler, settings);
        final T mock = (T) ClassImposterizer.INSTANCE.imposterise(filter, type);
        final MockitoMethodInvocationControl invocationControl = new MockitoMethodInvocationControl(filter,
                isSpy && delegator == null ? new Object() : delegator, mock, methods);
View Full Code Here


* A MockMaker that uses cglib to generate mocks on a JVM.
*/
public final class CglibMockMaker implements MockMaker {

    public <T> T createMock(MockCreationSettings<T> settings, MockHandler handler) {
        InternalMockHandler mockitoHandler = cast(handler);
        return ClassImposterizer.INSTANCE.imposterise(
                new MethodInterceptorFilter(mockitoHandler, settings), settings.getTypeToMock(), settings.getExtraInterfaces());
    }
View Full Code Here

* by Szczepan Faber, created at: 5/21/12
*/
public class MockHandlerFactory {

    public InternalMockHandler create(MockCreationSettings settings) {
        InternalMockHandler handler = new MockHandlerImpl(settings);
        InternalMockHandler nullResultGuardian = new NullResultGuardian(handler);
        InternalMockHandler notifier = new InvocationNotifierHandler(nullResultGuardian, settings);

        return notifier;
    }
View Full Code Here

        return mock;
    }

    public <T> void resetMock(T mock) {
        InternalMockHandler oldHandler = (InternalMockHandler) getMockHandler(mock);
        MockCreationSettings settings = oldHandler.getMockSettings();
        MockHandler newHandler = new MockHandlerFactory().create(settings);

        mockMaker.resetMock(mock, newHandler, settings);
    }
View Full Code Here

* A MockMaker that uses cglib to generate mocks on a JVM.
*/
public final class CglibMockMaker implements MockMaker {

    public <T> T createMock(MockCreationSettings<T> settings, MockHandler handler) {
        InternalMockHandler mockitoHandler = cast(handler);
        new AcrossJVMSerializationFeature().enableSerializationAcrossJVM(settings);
        return new ClassImposterizer(new InstantiatorProvider().getInstantiator(settings)).imposterise(
                new MethodInterceptorFilter(mockitoHandler, settings), settings.getTypeToMock(), settings.getExtraInterfaces());
    }
View Full Code Here

        return mock;
    }

    public <T> void resetMock(T mock) {
        InternalMockHandler oldHandler = (InternalMockHandler) getMockHandler(mock);
        MockCreationSettings settings = oldHandler.getMockSettings();
        MockHandler newHandler = new MockHandlerFactory().create(settings);

        mockMaker.resetMock(mock, newHandler, settings);
    }
View Full Code Here

    @Test
    //see issue 331
    public void handle_result_must_not_be_null_for_primitives() throws Throwable {
        //given:
        MockCreationSettings settings = (MockCreationSettings) new MockSettingsImpl().defaultAnswer(new Returns(null));
        InternalMockHandler handler = new MockHandlerFactory().create(settings);

        mock.intReturningMethod();
        Invocation invocation = super.getLastInvocation();

        //when:
        Object result = handler.handle(invocation);

        //then null value is not a valid result for a primitive
        assertNotNull(result);
        assertEquals(0, result);
    }
View Full Code Here

    @Test
    //see issue 331
    public void valid_handle_result_is_permitted() throws Throwable {
        //given:
        MockCreationSettings settings = (MockCreationSettings) new MockSettingsImpl().defaultAnswer(new Returns(123));
        InternalMockHandler handler = new MockHandlerFactory().create(settings);

        mock.intReturningMethod();
        Invocation invocation = super.getLastInvocation();

        //when:
        Object result = handler.handle(invocation);

        //then
        assertEquals(123, result);
    }
View Full Code Here

        }

        settings.setMockName(new MockNameImpl(mockName));
        settings.setTypeToMock(type);

        InternalMockHandler mockHandler = new MockHandlerFactory().create(settings);
        MethodInterceptorFilter filter = new PowerMockMethodInterceptorFilter(mockHandler, settings);
        final T mock = (T) ClassImposterizer.INSTANCE.imposterise(filter, type);
        final MockitoMethodInvocationControl invocationControl = new MockitoMethodInvocationControl(filter,
                isSpy && delegator == null ? new Object() : delegator, mock, methods);
View Full Code Here

TOP

Related Classes of org.mockito.internal.InternalMockHandler

Copyright © 2018 www.massapicom. 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.