Closed
Description
Hi,
after upgrading to spring boot 3.2.0, some unit tests failed with the error:
16:10:11.695 [main] INFO org.springframework.mock.web.MockServletContext -- Initializing Spring TestDispatcherServlet ''
16:10:11.695 [main] INFO org.springframework.test.web.servlet.TestDispatcherServlet -- Initializing Servlet ''
16:10:11.695 [main] INFO org.springframework.test.web.servlet.TestDispatcherServlet -- Completed initialization in 0 ms
16:10:11.701 [main] WARN org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver -- Resolved [org.springframework.http.converter.HttpMessageNotWritableException: Could not write JSON: (was java.lang.UnsupportedOperationException)]
java.lang.AssertionError: Status expected:<200> but was:<500>
Expected :200
Actual :500
Here is the test:
@Test
void findAll() throws Exception {
doReturn(Page.empty()).when(activityLogService).findAll(any(Predicate.class),any(Pageable.class),any());
mockMvc.perform(get("/api/v1/activity-logs"))
.andExpect(status().isOk())
.andReturn();
}
If I replace
doReturn(Page.empty()).when(activityLogService).findAll(any(Predicate.class),any(Pageable.class),any());
with
doReturn(Page.empty(PageRequest.of(1, 10, Sort.by("id")))).when(activityLogService).findAll(any(Predicate.class),any(Pageable.class),any());
the error is gone.
It seems Page.empty()
is not serializable while Page.empty(PageRequest.of(1, 10, Sort.by("id")))
is.
Is it a regression or did I miss something ?