Search in sources :

Example 1 with MockHandler

use of org.mockito.invocation.MockHandler in project mockito by mockito.

the class AbstractByteBuddyMockMakerTest method should_reset_mock_and_set_new_handler.

@Test
public void should_reset_mock_and_set_new_handler() throws Throwable {
    MockCreationSettings<SampleClass> settings = settingsWithSuperCall(SampleClass.class);
    SampleClass proxy = mockMaker.createMock(settings, new MockHandlerImpl<SampleClass>(settings));
    MockHandler handler = new MockHandlerImpl<SampleClass>(settings);
    mockMaker.resetMock(proxy, handler, settings);
    assertThat(mockMaker.getHandler(proxy)).isSameAs(handler);
}
Also used : InternalMockHandler(org.mockito.internal.InternalMockHandler) MockHandler(org.mockito.invocation.MockHandler) MockHandlerImpl(org.mockito.internal.handler.MockHandlerImpl) Test(org.junit.Test)

Example 2 with MockHandler

use of org.mockito.invocation.MockHandler in project mockito by mockito.

the class MockUtil method resetMock.

public static <T> void resetMock(T mock) {
    InternalMockHandler oldHandler = (InternalMockHandler) getMockHandler(mock);
    MockCreationSettings settings = oldHandler.getMockSettings();
    MockHandler newHandler = createMockHandler(settings);
    mockMaker.resetMock(mock, newHandler, settings);
}
Also used : MockCreationSettings(org.mockito.mock.MockCreationSettings) MockHandlerFactory.createMockHandler(org.mockito.internal.handler.MockHandlerFactory.createMockHandler) InternalMockHandler(org.mockito.internal.InternalMockHandler) MockHandler(org.mockito.invocation.MockHandler) InternalMockHandler(org.mockito.internal.InternalMockHandler)

Example 3 with MockHandler

use of org.mockito.invocation.MockHandler in project powermock by powermock.

the class MockitoMethodInvocationControl method verifyNoMoreInteractions.

public void verifyNoMoreInteractions() {
    try {
        final MockHandler mockHandler = methodInterceptorFilter.getHandler();
        if (mockHandler instanceof MockHandler) {
            InvocationContainer invocationContainer = Whitebox.invokeMethod(mockHandler, "getInvocationContainer");
            VerificationDataImpl data = new VerificationDataImpl(invocationContainer, null);
            VerificationModeFactory.noMoreInteractions().verify(data);
        } else {
            throw new RuntimeException("Cannot perform verifyNoMoreInteractions because of unknown mockhandler type " + mockHandler.getClass());
        }
    } catch (MockitoAssertionError e) {
        InvocationControlAssertionError.updateErrorMessageForVerifyNoMoreInteractions(e);
        throw e;
    } catch (Exception e) {
        throw new RuntimeException("PowerMock internal error", e);
    }
}
Also used : VerificationDataImpl(org.mockito.internal.verification.VerificationDataImpl) MockitoAssertionError(org.mockito.exceptions.base.MockitoAssertionError) InternalMockHandler(org.mockito.internal.InternalMockHandler) MockHandler(org.mockito.invocation.MockHandler) InvocationContainer(org.mockito.internal.stubbing.InvocationContainer) NotAMockException(org.mockito.exceptions.misusing.NotAMockException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 4 with MockHandler

use of org.mockito.invocation.MockHandler in project mockito by mockito.

the class AbstractMockMakerTest method should_reset_mock_and_set_new_handler.

@Test
public void should_reset_mock_and_set_new_handler() throws Throwable {
    MockCreationSettings<C> settings = settingsWithSuperCall(target);
    C proxy = mockMaker.createMock(settings, new MockHandlerImpl<C>(settings));
    MockHandler handler = new MockHandlerImpl<C>(settings);
    mockMaker.resetMock(proxy, handler, settings);
    assertThat(mockMaker.getHandler(proxy)).isSameAs(handler);
}
Also used : MockHandler(org.mockito.invocation.MockHandler) MockHandlerImpl(org.mockito.internal.handler.MockHandlerImpl) Test(org.junit.Test)

Example 5 with MockHandler

use of org.mockito.invocation.MockHandler in project mockito by mockito.

the class AbstractMockMakerTest method should_mocks_have_different_interceptors.

@Test
public void should_mocks_have_different_interceptors() throws Exception {
    C mockOne = mockMaker.createMock(settingsFor(target), dummyHandler());
    C mockTwo = mockMaker.createMock(settingsFor(target), dummyHandler());
    MockHandler handlerOne = mockMaker.getHandler(mockOne);
    MockHandler handlerTwo = mockMaker.getHandler(mockTwo);
    assertThat(handlerOne).isNotSameAs(handlerTwo);
}
Also used : MockHandler(org.mockito.invocation.MockHandler) Test(org.junit.Test)

Aggregations

MockHandler (org.mockito.invocation.MockHandler)14 Test (org.junit.Test)5 InternalMockHandler (org.mockito.internal.InternalMockHandler)5 MockHandlerFactory.createMockHandler (org.mockito.internal.handler.MockHandlerFactory.createMockHandler)4 MockitoAssertionError (org.mockito.exceptions.base.MockitoAssertionError)3 NotAMockException (org.mockito.exceptions.misusing.NotAMockException)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 MockingDetails (org.mockito.MockingDetails)2 MockHandlerImpl (org.mockito.internal.handler.MockHandlerImpl)2 MockingProgress (org.mockito.internal.progress.MockingProgress)2 MockAwareVerificationMode (org.mockito.internal.verification.MockAwareVerificationMode)2 MockCreationSettings (org.mockito.mock.MockCreationSettings)2 VerificationMode (org.mockito.verification.VerificationMode)2 List (java.util.List)1 MockitoException (org.mockito.exceptions.base.MockitoException)1 AbstractMockMakerTest (org.mockito.internal.creation.AbstractMockMakerTest)1 DelegatingMethod (org.mockito.internal.creation.DelegatingMethod)1 LocationImpl (org.mockito.internal.debugging.LocationImpl)1 InvocationImpl (org.mockito.internal.invocation.InvocationImpl)1 CleanTraceRealMethod (org.mockito.internal.invocation.realmethod.CleanTraceRealMethod)1