将 mockito 与 Java 11 一起使用时未找到序列化程序

No serializer found while using mockito with Java 11

我使用 mockito 为我的控制器和服务创建了一个测试。虽然我使用 java 8 一切正常,但是在迁移到 Java 11 之后,我遇到了这个错误。也许有人可以帮我解决这个测试?

public class ConfigurationControllerTest {

    @Mock
    private ConfigurationService configurationService;

    @InjectMocks
    private ConfigurationController controller;

    private MockMvc mockMvc;

    @Before
    public void setUp() {
        MockitoAnnotations.initMocks(this);
        mockMvc = MockMvcBuilders
                .standaloneSetup(controller)
                .build();
    }

    @Test
    public void find() throws Exception {
        //given
        final ConfigurationsDto configDto = mock(ConfigurationsDto.class);
        given(configurationService.find(any())).willReturn(Arrays.asList(configDto));


        //when and then
        mockMvc
                .perform(get("/config/1.0.0/")
                        .accept(MediaType.APPLICATION_JSON))
                .andExpect(status().isOk());
    }
}

在 运行 之后,我收到了 https 状态 500 和错误:

[main] ERROR app.controllers.global.AdviceController - No serializer found for class org.mockito.internal.debugging.LocationImpl and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS) (through reference chain: java.util.Collections$SingletonList[0]->app.dtos.ConfigurationsDto$MockitoMock4475338["mockitoInterceptor"]->org.mockito.internal.creation.bytebuddy.MockMethodInterceptor["mockHandler"]->org.mockito.internal.handler.InvocationNotifierHandler["invocationContainer"]->org.mockito.internal.stubbing.InvocationContainerImpl["invocationForStubbing"]->org.mockito.internal.invocation.InvocationMatcher["invocation"]->org.mockito.internal.invocation.InterceptedInvocation["location"])

当然,我在pom中添加了需要的依赖:

<dependency>
    <groupId>org.mockito</groupId>
    <artifactId>mockito-core</artifactId>
    <version>2.23.4</version>
</dependency>

我使用真实对象而不是模拟 dto 修复此测试