Skip to content

Commit

Permalink
MODCAMUNDA-26: Fix problems after upgrading to work with spring-boot …
Browse files Browse the repository at this point in the history
…3.4.

Replace `@MockBean` and `@SpyBean`.
  - `@MockitoBean` and `MockitoSpyBean` are the replacemenets to the deprecated or removed `@MockBean` and `@SpyBean`.

Address failing bean problems.
  - The `ObjectMapper` bean is provided because the `@MockitoSpyBean` no longer instantiates when there is no bean found in the way that no available or deprecated `@SpyBean` does.
  - see: spring-projects/spring-framework#33935
  • Loading branch information
kaladay committed Feb 10, 2025
1 parent 4e66fe7 commit 6cabe28
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,11 @@
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.test.context.bean.override.mockito.MockitoBean;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.MvcResult;
import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder;
Expand All @@ -79,10 +81,10 @@ class WorkflowControllerTest {
@Autowired
private WorkflowController workflowController;

@MockBean
@MockitoBean
private CamundaApiService camundaApiService;

@MockBean
@MockitoBean
private TenantProperties tenantProperties;

@BeforeEach
Expand Down
25 changes: 18 additions & 7 deletions src/test/java/org/folio/rest/camunda/kafka/EventConsumerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.doReturn;

import java.util.HashMap;
import java.util.stream.Stream;

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.util.HashMap;
import java.util.stream.Stream;
import org.camunda.bpm.engine.RuntimeService;
import org.camunda.bpm.engine.runtime.MessageCorrelationBuilder;
import org.camunda.bpm.engine.runtime.ProcessInstance;
Expand All @@ -24,18 +23,20 @@
import org.mockito.MockedStatic;
import org.mockito.Mockito;
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.boot.test.mock.mockito.SpyBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.test.context.bean.override.mockito.MockitoBean;
import org.springframework.test.context.bean.override.mockito.MockitoSpyBean;
import org.springframework.test.context.junit.jupiter.SpringExtension;

@ExtendWith(SpringExtension.class)
@ExtendWith(MockitoExtension.class)
class EventConsumerTest {

@SpyBean
@MockitoSpyBean
private ObjectMapper objectMapper;

@MockBean
@MockitoBean
private RuntimeService runtimeService;

@Mock
Expand All @@ -47,6 +48,16 @@ class EventConsumerTest {
@InjectMocks
private EventConsumer eventConsumer;

// Provide a bean for `@MockitoSpyBean` above to work without requiring a full spring boot runner.
@Configuration
static class Config {

@Bean
ObjectMapper objectMapper() {
return new ObjectMapper();
}
}

@ParameterizedTest
@MethodSource("eventStream")
@SuppressWarnings("unchecked")
Expand Down

0 comments on commit 6cabe28

Please sign in to comment.