Search in sources :

Example 1 with MockHandlerImpl

use of org.mockito.internal.handler.MockHandlerImpl 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 MockHandlerImpl

use of org.mockito.internal.handler.MockHandlerImpl in project mockito by mockito.

the class InlineByteBuddyMockMakerTest method should_throw_exception_redefining_array.

@Test
@SuppressWarnings("unchecked")
public void should_throw_exception_redefining_array() {
    int[] array = new int[5];
    MockCreationSettings<? extends int[]> settings = settingsFor(array.getClass());
    try {
        mockMaker.createMock(settings, new MockHandlerImpl(settings));
        fail("Expected a MockitoException");
    } catch (MockitoException e) {
        assertThat(e).hasMessageContaining("Arrays cannot be mocked");
    }
}
Also used : MockitoException(org.mockito.exceptions.base.MockitoException) MockHandlerImpl(org.mockito.internal.handler.MockHandlerImpl) Test(org.junit.Test)

Example 3 with MockHandlerImpl

use of org.mockito.internal.handler.MockHandlerImpl in project mockito by mockito.

the class InlineByteBuddyMockMakerTest method should_throw_exception_redefining_unmodifiable_class.

@Test
@SuppressWarnings("unchecked")
public void should_throw_exception_redefining_unmodifiable_class() {
    MockCreationSettings settings = settingsFor(int.class);
    try {
        mockMaker.createMock(settings, new MockHandlerImpl(settings));
        fail("Expected a MockitoException");
    } catch (MockitoException e) {
        e.printStackTrace();
        assertThat(e).hasMessageContaining("Could not modify all classes");
    }
}
Also used : MockCreationSettings(org.mockito.mock.MockCreationSettings) MockitoException(org.mockito.exceptions.base.MockitoException) MockHandlerImpl(org.mockito.internal.handler.MockHandlerImpl) Test(org.junit.Test)

Example 4 with MockHandlerImpl

use of org.mockito.internal.handler.MockHandlerImpl 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 MockHandlerImpl

use of org.mockito.internal.handler.MockHandlerImpl in project mockito by mockito.

the class InlineDelegateByteBuddyMockMakerTest method should_throw_exception_redefining_unmodifiable_class.

@Test
@SuppressWarnings("unchecked")
public void should_throw_exception_redefining_unmodifiable_class() {
    MockCreationSettings settings = settingsFor(int.class);
    try {
        mockMaker.createMock(settings, new MockHandlerImpl(settings));
        fail("Expected a MockitoException");
    } catch (MockitoException e) {
        e.printStackTrace();
        assertThat(e).hasMessageContaining("Could not modify all classes");
    }
}
Also used : MockCreationSettings(org.mockito.mock.MockCreationSettings) MockitoException(org.mockito.exceptions.base.MockitoException) MockHandlerImpl(org.mockito.internal.handler.MockHandlerImpl) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)10 MockHandlerImpl (org.mockito.internal.handler.MockHandlerImpl)10 MockitoException (org.mockito.exceptions.base.MockitoException)5 ByteBuddy (net.bytebuddy.ByteBuddy)4 MockCreationSettings (org.mockito.mock.MockCreationSettings)3 Callable (java.util.concurrent.Callable)2 MockHandler (org.mockito.invocation.MockHandler)2 IOException (java.io.IOException)1 java.util (java.util)1 Pattern (java.util.regex.Pattern)1 Collectors (java.util.stream.Collectors)1 ClassFileVersion (net.bytebuddy.ClassFileVersion)1 JAVA_V11 (net.bytebuddy.ClassFileVersion.JAVA_V11)1 JAVA_V8 (net.bytebuddy.ClassFileVersion.JAVA_V8)1 Visibility (net.bytebuddy.description.modifier.Visibility)1 TypeDescription (net.bytebuddy.description.type.TypeDescription)1 FixedValue (net.bytebuddy.implementation.FixedValue)1 StubMethod (net.bytebuddy.implementation.StubMethod)1 ElementMatchers.named (net.bytebuddy.matcher.ElementMatchers.named)1 JavaConstant (net.bytebuddy.utility.JavaConstant)1