Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

InlineByteBuddyMockMaker is freezing with static inner mock field #1774

Open
EvgeniGordeev opened this issue Sep 5, 2019 · 0 comments
Open

Comments

@EvgeniGordeev
Copy link

EvgeniGordeev commented Sep 5, 2019

A SpringBoot test like this is freezing when InlineByteBuddyMockMaker is trying to initialize a mock defined in a static field of an inner class. The execution gets stuck on ByteBuddyAgent.install() in static initialization block of InlineByteBuddyMockMaker. NB: The default ByteBuddyMockMaker works just fine.

The full example is at https://github.com/EvgeniGordeev/mockito-bytebuddy-freeze

Environment: Mockito v2.23.4, OpenJDK 8/11

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.NONE;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.test.context.junit4.SpringRunner;

@SpringBootTest(
    classes = {
        FreezingTest.MockBeans.class},
    webEnvironment = NONE)
@RunWith(SpringRunner.class)
public class FreezingTest {

    @MockBean
    private FreezingTest freezingTest;

    @Test
    public void testFreeze() {
        // Success
        assertThat(freezingTest).isNotNull();
    }

    @Configuration
    static class MockBeans {

        static FreezingTest freezingTestMock = mock(FreezingTest.class);

        @Bean
        public FreezingTest freezingTestMockBean() {
            return freezingTestMock;
        }
    }

}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant