From 12ce1188f7bbcef5819ff8b5f64f6f4df45d508b Mon Sep 17 00:00:00 2001 From: Silvestre Zabala Date: Fri, 17 Jan 2025 17:14:32 +0100 Subject: [PATCH] chore(scheduler): Replace deprectated Mockito annotations # Issue ``` Warning: /__w/app-autoscaler-release/app-autoscaler-release/src/scheduler/src/test/java/org/cloudfoundry/autoscaler/scheduler/service/ScheduleManagerTest.java:[94,4] org.springframework.boot.test.mock.mockito.SpyBean in org.springframework.boot.test.mock.mockito has been deprecated and marked for removal ``` # Fix Run [Replace `@MockBean` and `@SpyBean` ](https://docs.openrewrite.org/recipes/java/boot3/replacemockbeanandspybean) OpenRewrite recipe: ``` $ mvn -U org.openrewrite.maven:rewrite-maven-plugin:run -Drewrite.recipeArtifactCoordinates=org.openrewrite.recipe:rewrite-spring:RELEASE -Drewrite.exportDatatables=true -Drewrite.activeRecipes=org.openrewrite.java.spring.boot3.ReplaceMockBeanAndSpyBean ``` --- .../dao/ActiveScheduleDaoImplFailureTest.java | 4 ++-- .../quartz/AppScalingScheduleJobTest.java | 10 +++++----- .../rest/ScheduleRestControllerTest.java | 6 +++--- .../rest/ScheduleSyncRestControllerTest.java | 6 +++--- .../service/ScheduleJobManagerTest.java | 6 +++--- .../scheduler/service/ScheduleManagerTest.java | 16 ++++++++-------- 6 files changed, 24 insertions(+), 24 deletions(-) diff --git a/src/scheduler/src/test/java/org/cloudfoundry/autoscaler/scheduler/dao/ActiveScheduleDaoImplFailureTest.java b/src/scheduler/src/test/java/org/cloudfoundry/autoscaler/scheduler/dao/ActiveScheduleDaoImplFailureTest.java index d3eb3a8ee7..b8a479ed0a 100644 --- a/src/scheduler/src/test/java/org/cloudfoundry/autoscaler/scheduler/dao/ActiveScheduleDaoImplFailureTest.java +++ b/src/scheduler/src/test/java/org/cloudfoundry/autoscaler/scheduler/dao/ActiveScheduleDaoImplFailureTest.java @@ -15,7 +15,7 @@ import org.mockito.Mockito; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.mock.mockito.SpyBean; +import org.springframework.test.context.bean.override.mockito.MockitoSpyBean; import org.springframework.test.context.junit4.SpringRunner; @RunWith(SpringRunner.class) @@ -24,7 +24,7 @@ public class ActiveScheduleDaoImplFailureTest { @Autowired private ActiveScheduleDao activeScheduleDao; - @SpyBean private DataSource dataSource; + @MockitoSpyBean private DataSource dataSource; @Autowired TestDataDbUtil testDataDbUtil; diff --git a/src/scheduler/src/test/java/org/cloudfoundry/autoscaler/scheduler/quartz/AppScalingScheduleJobTest.java b/src/scheduler/src/test/java/org/cloudfoundry/autoscaler/scheduler/quartz/AppScalingScheduleJobTest.java index d4a965693d..22d9bd3d62 100644 --- a/src/scheduler/src/test/java/org/cloudfoundry/autoscaler/scheduler/quartz/AppScalingScheduleJobTest.java +++ b/src/scheduler/src/test/java/org/cloudfoundry/autoscaler/scheduler/quartz/AppScalingScheduleJobTest.java @@ -47,10 +47,10 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.mock.mockito.MockBean; -import org.springframework.boot.test.mock.mockito.SpyBean; import org.springframework.context.ApplicationContext; import org.springframework.http.HttpEntity; +import org.springframework.test.context.bean.override.mockito.MockitoBean; +import org.springframework.test.context.bean.override.mockito.MockitoSpyBean; import org.springframework.test.context.junit4.SpringRunner; import org.springframework.web.client.ResourceAccessException; import org.springframework.web.client.RestOperations; @@ -62,9 +62,9 @@ public class AppScalingScheduleJobTest { private static EmbeddedTomcatUtil embeddedTomcatUtil; @Autowired private MessageBundleResourceHelper messageBundleResourceHelper; private Scheduler memScheduler; - @MockBean private Scheduler scheduler; - @MockBean private ActiveScheduleDao activeScheduleDao; - @SpyBean private RestOperations restOperations; + @MockitoBean private Scheduler scheduler; + @MockitoBean private ActiveScheduleDao activeScheduleDao; + @MockitoSpyBean private RestOperations restOperations; @Autowired private TestDataDbUtil testDataDbUtil; @Autowired private ApplicationContext applicationContext; diff --git a/src/scheduler/src/test/java/org/cloudfoundry/autoscaler/scheduler/rest/ScheduleRestControllerTest.java b/src/scheduler/src/test/java/org/cloudfoundry/autoscaler/scheduler/rest/ScheduleRestControllerTest.java index 6251de0c51..bc4fc1881b 100644 --- a/src/scheduler/src/test/java/org/cloudfoundry/autoscaler/scheduler/rest/ScheduleRestControllerTest.java +++ b/src/scheduler/src/test/java/org/cloudfoundry/autoscaler/scheduler/rest/ScheduleRestControllerTest.java @@ -38,10 +38,10 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; -import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.http.MediaType; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.annotation.DirtiesContext.ClassMode; +import org.springframework.test.context.bean.override.mockito.MockitoBean; import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.ResultActions; @@ -54,9 +54,9 @@ @DirtiesContext(classMode = ClassMode.BEFORE_CLASS) public class ScheduleRestControllerTest { - @MockBean private Scheduler scheduler; + @MockitoBean private Scheduler scheduler; - @MockBean private ActiveScheduleDao activeScheduleDao; + @MockitoBean private ActiveScheduleDao activeScheduleDao; @Autowired private SpecificDateScheduleDao specificDateScheduleDao; diff --git a/src/scheduler/src/test/java/org/cloudfoundry/autoscaler/scheduler/rest/ScheduleSyncRestControllerTest.java b/src/scheduler/src/test/java/org/cloudfoundry/autoscaler/scheduler/rest/ScheduleSyncRestControllerTest.java index 14806e4f00..61d2ac06aa 100644 --- a/src/scheduler/src/test/java/org/cloudfoundry/autoscaler/scheduler/rest/ScheduleSyncRestControllerTest.java +++ b/src/scheduler/src/test/java/org/cloudfoundry/autoscaler/scheduler/rest/ScheduleSyncRestControllerTest.java @@ -21,9 +21,9 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; -import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.annotation.DirtiesContext.ClassMode; +import org.springframework.test.context.bean.override.mockito.MockitoBean; import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.ResultActions; @@ -35,9 +35,9 @@ @DirtiesContext(classMode = ClassMode.BEFORE_CLASS) public class ScheduleSyncRestControllerTest { - @MockBean private Scheduler scheduler; + @MockitoBean private Scheduler scheduler; - @MockBean private ActiveScheduleDao activeScheduleDao; + @MockitoBean private ActiveScheduleDao activeScheduleDao; @Autowired private TestDataDbUtil testDataDbUtil; diff --git a/src/scheduler/src/test/java/org/cloudfoundry/autoscaler/scheduler/service/ScheduleJobManagerTest.java b/src/scheduler/src/test/java/org/cloudfoundry/autoscaler/scheduler/service/ScheduleJobManagerTest.java index 72358fa67e..e7ce0a6164 100644 --- a/src/scheduler/src/test/java/org/cloudfoundry/autoscaler/scheduler/service/ScheduleJobManagerTest.java +++ b/src/scheduler/src/test/java/org/cloudfoundry/autoscaler/scheduler/service/ScheduleJobManagerTest.java @@ -55,16 +55,16 @@ import org.quartz.TriggerKey; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.test.context.bean.override.mockito.MockitoBean; import org.springframework.test.context.junit4.SpringRunner; @RunWith(SpringRunner.class) @SpringBootTest public class ScheduleJobManagerTest { - @MockBean private Scheduler scheduler; + @MockitoBean private Scheduler scheduler; - @MockBean private ActiveScheduleDao activeScheduleDao; + @MockitoBean private ActiveScheduleDao activeScheduleDao; @Autowired private ScheduleJobManager scheduleJobManager; diff --git a/src/scheduler/src/test/java/org/cloudfoundry/autoscaler/scheduler/service/ScheduleManagerTest.java b/src/scheduler/src/test/java/org/cloudfoundry/autoscaler/scheduler/service/ScheduleManagerTest.java index eef163249f..9988017009 100644 --- a/src/scheduler/src/test/java/org/cloudfoundry/autoscaler/scheduler/service/ScheduleManagerTest.java +++ b/src/scheduler/src/test/java/org/cloudfoundry/autoscaler/scheduler/service/ScheduleManagerTest.java @@ -58,10 +58,10 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.mock.mockito.MockBean; -import org.springframework.boot.test.mock.mockito.SpyBean; import org.springframework.http.HttpMethod; import org.springframework.http.HttpStatus; +import org.springframework.test.context.bean.override.mockito.MockitoBean; +import org.springframework.test.context.bean.override.mockito.MockitoSpyBean; import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.web.client.ExpectedCount; import org.springframework.test.web.client.MockRestServiceServer; @@ -75,15 +75,15 @@ public class ScheduleManagerTest { @Autowired private ScheduleManager scheduleManager; - @MockBean private PolicyJsonDao policyJsonDao; + @MockitoBean private PolicyJsonDao policyJsonDao; - @MockBean private SpecificDateScheduleDao specificDateScheduleDao; + @MockitoBean private SpecificDateScheduleDao specificDateScheduleDao; - @MockBean private RecurringScheduleDao recurringScheduleDao; + @MockitoBean private RecurringScheduleDao recurringScheduleDao; - @MockBean private ActiveScheduleDao activeScheduleDao; + @MockitoBean private ActiveScheduleDao activeScheduleDao; - @MockBean private ScheduleJobManager scheduleJobManager; + @MockitoBean private ScheduleJobManager scheduleJobManager; @Autowired private MessageBundleResourceHelper messageBundleResourceHelper; @@ -91,7 +91,7 @@ public class ScheduleManagerTest { @Autowired private TestDataDbUtil testDataDbUtil; - @SpyBean private RestOperations restOperations; + @MockitoSpyBean private RestOperations restOperations; @Value("${autoscaler.scalingengine.url}") private String scalingEngineUrl;