Deprecate @MockBean and @SpyBean

- Deprecate Deprecate @MockBean and @SpyBean in favor of Spring
  Framework 6.2's @MockitoBean and @MockitoSpy
- Migrate usages of @MockBean and @SpyBean to @MockitoBean and
  @MockitoSpy

Signed-off-by: Jakob Wanger <jakobwanger@gmail.com>

See gh-39864
This commit is contained in:
Jakob Wanger
2024-03-10 19:42:45 -04:00
committed by Andy Wilkinson
parent acdaa6dc35
commit 24763940a0
38 changed files with 87 additions and 33 deletions

View File

@@ -26,9 +26,9 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase;
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.boot.test.web.client.TestRestTemplate;
import org.springframework.http.HttpStatus;
import org.springframework.test.bean.override.mockito.MockitoBean;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.BDDMockito.given;
@@ -48,7 +48,7 @@ class SampleTestApplicationWebIntegrationTests {
@Autowired
private TestRestTemplate restTemplate;
@MockBean
@MockitoBean
private VehicleDetailsService vehicleDetailsService;
@BeforeEach

View File

@@ -24,11 +24,12 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.context.ApplicationContext;
import org.springframework.http.MediaType;
import org.springframework.test.bean.override.mockito.MockitoBean;
import org.springframework.test.web.servlet.assertj.MockMvcTester;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.BDDMockito.given;
@@ -48,7 +49,7 @@ class UserVehicleControllerApplicationTests {
@Autowired
private ApplicationContext applicationContext;
@MockBean
@MockitoBean
private UserVehicleService userVehicleService;
@Test

View File

@@ -23,7 +23,7 @@ import smoketest.test.service.VehicleDetails;
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.test.bean.override.mockito.MockitoBean;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.BDDMockito.given;
@@ -39,7 +39,7 @@ class UserVehicleControllerHtmlUnitTests {
@Autowired
private WebClient webClient;
@MockBean
@MockitoBean
private UserVehicleService userVehicleService;
@Test

View File

@@ -24,7 +24,7 @@ import smoketest.test.service.VehicleDetails;
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.test.bean.override.mockito.MockitoBean;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.BDDMockito.given;
@@ -40,7 +40,7 @@ class UserVehicleControllerSeleniumTests {
@Autowired
private WebDriver webDriver;
@MockBean
@MockitoBean
private UserVehicleService userVehicleService;
@Test

View File

@@ -25,10 +25,10 @@ import smoketest.test.service.VehicleIdentificationNumberNotFoundException;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
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.ApplicationContext;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.test.bean.override.mockito.MockitoBean;
import org.springframework.test.web.servlet.assertj.MockMvcTester;
import static org.assertj.core.api.Assertions.assertThat;
@@ -51,7 +51,7 @@ class UserVehicleControllerTests {
@Autowired
private ApplicationContext applicationContext;
@MockBean
@MockitoBean
private UserVehicleService userVehicleService;
@Test

View File

@@ -29,9 +29,9 @@ import smoketest.webservices.service.HumanResourceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.webservices.server.WebServiceServerTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.boot.test.system.CapturedOutput;
import org.springframework.boot.test.system.OutputCaptureExtension;
import org.springframework.test.bean.override.mockito.MockitoBean;
import org.springframework.ws.test.server.MockWebServiceClient;
import org.springframework.ws.test.server.RequestCreators;
import org.springframework.ws.test.server.ResponseMatchers;
@@ -48,7 +48,7 @@ import static org.mockito.BDDMockito.then;
@ExtendWith(OutputCaptureExtension.class)
class WebServiceServerTestSampleWsApplicationTests {
@MockBean
@MockitoBean
HumanResourceService service;
@Autowired