Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion buildSrc/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ new File(projectDir.parentFile, "gradle.properties").withInputStream {
}
}
versions["jackson"] = "2.15.3"
versions["springFramework"] = "6.0.12"
versions["springFramework"] = "6.2.0-SNAPSHOT"
ext.set("versions", versions)
if (versions.springFramework.contains("-")) {
repositories {
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ junitJupiterVersion=5.10.2
kotlinVersion=1.9.22
mavenVersion=3.9.4
nativeBuildToolsVersion=0.10.1
springFrameworkVersion=6.1.4
springFrameworkVersion=6.2.0-SNAPSHOT
tomcatVersion=10.1.19

kotlin.stdlib.default.dependency=false
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ dependencies {
testImplementation("org.springframework.restdocs:spring-restdocs-webtestclient")
testImplementation("org.springframework.security:spring-security-test")
testImplementation("org.yaml:snakeyaml")
testImplementation("org.springframework:spring-test")

testRuntimeOnly("jakarta.management.j2ee:jakarta.management.j2ee-api")
testRuntimeOnly("jakarta.transaction:jakarta.transaction-api")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@
import org.springframework.boot.actuate.audit.AuditEvent;
import org.springframework.boot.actuate.audit.AuditEventRepository;
import org.springframework.boot.actuate.audit.AuditEventsEndpoint;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.test.bean.override.mockito.MockitoBean;

import static org.mockito.ArgumentMatchers.any;
import static org.mockito.BDDMockito.given;
Expand All @@ -49,7 +49,7 @@
*/
class AuditEventsEndpointDocumentationTests extends MockMvcEndpointDocumentationTests {

@MockBean
@MockitoBean
private AuditEventRepository repository;

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import org.springframework.context.annotation.Import;
import org.springframework.http.HttpHeaders;
import org.springframework.restdocs.payload.JsonFieldType;
import org.springframework.test.bean.override.mockito.MockitoBean;

import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock;
Expand All @@ -57,7 +58,7 @@
*/
class HttpExchangesEndpointDocumentationTests extends MockMvcEndpointDocumentationTests {

@MockBean
@MockitoBean
private HttpExchangeRepository repository;

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.springframework.restdocs.mockmvc.MockMvcRestDocumentation;
import org.springframework.restdocs.payload.FieldDescriptor;
import org.springframework.restdocs.payload.JsonFieldType;
import org.springframework.test.bean.override.mockito.MockitoBean;

import static org.mockito.BDDMockito.given;
import static org.mockito.BDDMockito.then;
Expand All @@ -63,7 +64,7 @@ class LoggersEndpointDocumentationTests extends MockMvcEndpointDocumentationTest
.type(JsonFieldType.STRING)
.optional(), fieldWithPath("members").description("Loggers that are part of this group"));

@MockBean
@MockitoBean
private LoggingSystem loggingSystem;

@Autowired
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ class QuartzEndpointDocumentationTests extends MockMvcEndpointDocumentationTests
.type(JsonFieldType.OBJECT)
.description("Job data map keyed by name, if any.") };

@MockBean
@MockitoBean
private Scheduler scheduler;

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.springframework.session.FindByIndexNameSessionRepository;
import org.springframework.session.MapSession;
import org.springframework.session.Session;
import org.springframework.test.bean.override.mockito.MockitoBean;
import org.springframework.test.context.TestPropertySource;

import static org.mockito.BDDMockito.given;
Expand Down Expand Up @@ -73,7 +74,7 @@ class SessionsEndpointDocumentationTests extends MockMvcEndpointDocumentationTes
.description("Maximum permitted period of inactivity, in seconds, before the session will expire."),
fieldWithPath("expired").description("Whether the session has expired."));

@MockBean
@MockitoBean
private FindByIndexNameSessionRepository<Session> sessionRepository;

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ JUnit 5 enables a test class to be instantiated once and reused for all of the c
This makes it possible to use `@BeforeAll` and `@AfterAll` annotations on non-static methods, which is a good fit for Kotlin.

To mock Kotlin classes, https://mockk.io/[MockK] is recommended.
If you need the `MockK` equivalent of the Mockito specific <<features#features.testing.spring-boot-applications.mocking-beans,`@MockBean` and `@SpyBean` annotations>>, you can use https://github.com/Ninja-Squad/springmockk[SpringMockK] which provides similar `@MockkBean` and `@SpykBean` annotations.
If you need the `MockK` equivalent of the Mockito specific <<features#features.testing.spring-boot-applications.mocking-beans,`@MockitoBean` and `@MockitoSpyBean` annotations>>, you can use https://github.com/Ninja-Squad/springmockk[SpringMockK] which provides similar `@MockkBean` and `@SpykBean` annotations.



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@

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.http.MediaType;
import org.springframework.test.bean.override.mockito.MockitoBean;
import org.springframework.test.web.servlet.MockMvc;

import static org.mockito.BDDMockito.given;
Expand All @@ -35,7 +35,7 @@ class MyControllerTests {
@Autowired
private MockMvc mvc;

@MockBean
@MockitoBean
private UserVehicleService userVehicleService;

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

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;
Expand All @@ -33,7 +33,7 @@ class MyHtmlUnitTests {
@Autowired
private WebClient webClient;

@MockBean
@MockitoBean
private UserVehicleService userVehicleService;

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.reactive.WebFluxTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.http.MediaType;
import org.springframework.test.bean.override.mockito.MockitoBean;
import org.springframework.test.web.reactive.server.WebTestClient;

import static org.mockito.BDDMockito.given;
Expand All @@ -32,7 +32,7 @@ class MyControllerTests {
@Autowired
private WebTestClient webClient;

@MockBean
@MockitoBean
private UserVehicleService userVehicleService;

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@ import org.junit.jupiter.api.Test
import org.mockito.BDDMockito.given
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.http.MediaType
import org.springframework.test.bean.override.mockito.MockitoBean
import org.springframework.test.web.servlet.MockMvc
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders
import org.springframework.test.web.servlet.result.MockMvcResultMatchers

@WebMvcTest(UserVehicleController::class)
class MyControllerTests(@Autowired val mvc: MockMvc) {

@MockBean
@MockitoBean
lateinit var userVehicleService: UserVehicleService

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ import org.junit.jupiter.api.Test
import org.mockito.BDDMockito.given
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

@WebMvcTest(UserVehicleController::class)
class MyHtmlUnitTests(@Autowired val webClient: WebClient) {

@MockBean
@MockitoBean
lateinit var userVehicleService: UserVehicleService

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ import org.junit.jupiter.api.Test
import org.mockito.BDDMockito.given
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.test.autoconfigure.web.reactive.WebFluxTest
import org.springframework.boot.test.mock.mockito.MockBean
import org.springframework.http.MediaType
import org.springframework.test.bean.override.mockito.MockitoBean
import org.springframework.test.web.reactive.server.WebTestClient
import org.springframework.test.web.reactive.server.expectBody

@WebFluxTest(UserVehicleController::class)
class MyControllerTests(@Autowired val webClient: WebTestClient) {

@MockBean
@MockitoBean
lateinit var userVehicleService: UserVehicleService

@Test
Expand Down
1 change: 1 addition & 0 deletions spring-boot-project/spring-boot-test/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ dependencies {
testImplementation("org.spockframework:spock-core")
testImplementation("org.springframework:spring-webmvc")
testImplementation("org.springframework:spring-core-test")
testImplementation("org.springframework:spring-test")
testImplementation("org.testng:testng")

testRuntimeOnly("org.junit.vintage:junit-vintage-engine")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
*
* @author Phillip Webb
* @see DefinitionsParser
* @deprecated since 3.4.0. See {@link SpyBean} and {@link MockBean} for more details.
*/
@Deprecated(since = "3.4.0")
abstract class Definition {

private static final int MULTIPLIER = 31;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@
*
* @author Phillip Webb
* @author Stephane Nicoll
* @deprecated since 3.4.0. See {@link SpyBean} and {@link MockBean} for more details.
*/

@Deprecated(since = "3.4.0")
class DefinitionsParser {

private final Set<Definition> definitions;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,14 @@
* @author Phillip Webb
* @since 1.4.0
* @see MockitoPostProcessor
* @deprecated since 3.4.0 in favor of
* {@link org.springframework.test.bean.override.mockito.MockitoBean}
*/
@Target({ ElementType.TYPE, ElementType.FIELD })
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Repeatable(MockBeans.class)
@Deprecated(since = "3.4.0")
public @interface MockBean {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,13 @@
*
* @author Phillip Webb
* @since 1.4.0
* @deprecated since 3.4.0 in favor of
* {@link org.springframework.test.bean.override.mockito.MockitoBean}
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
@Documented
@Deprecated(since = "3.4.0")
public @interface MockBeans {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@
* A complete definition that can be used to create a Mockito mock.
*
* @author Phillip Webb
* @deprecated since 3.4.0. See {@link MockBean} for more details.
*/
@Deprecated(since = "3.4.0")
class MockDefinition extends Definition {

private static final int MULTIPLIER = 31;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@
* @author Phillip Webb
* @since 1.4.0
* @see ResetMocksTestExecutionListener
* @deprecated since 3.4.0 in favor of
* {@link org.springframework.test.bean.override.mockito.MockReset}
*/

@Deprecated(since = "3.4.0")
public enum MockReset {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@
* Beans created using Mockito.
*
* @author Andy Wilkinson
* @deprecated since 3.4.0. See {@link MockBean} for more details.
*/
@Deprecated(since = "3.4.0")
class MockitoBeans implements Iterable<Object> {

private final List<Object> beans = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@
* A {@link ContextCustomizer} to add Mockito support.
*
* @author Phillip Webb
* @deprecated since 3.4.0 in favor of
* {@link org.springframework.test.bean.override.BeanOverrideContextCustomizerFactory}
*/
@Deprecated(since = "3.4.0")
class MockitoContextCustomizer implements ContextCustomizer {

private final Set<Definition> definitions;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@
* A {@link ContextCustomizerFactory} to add Mockito support.
*
* @author Phillip Webb
* @deprecated since 3.4.0 in favor of
* {@link org.springframework.test.bean.override.BeanOverrideContextCustomizerFactory}
*/
@Deprecated(since = "3.4.0")
class MockitoContextCustomizerFactory implements ContextCustomizerFactory {

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,10 @@
* @author Stephane Nicoll
* @author Andreas Neiser
* @since 1.4.0
* @deprecated since 3.4.0 in favor of
* {@link org.springframework.test.bean.override.BeanOverrideBeanPostProcessor}
*/
@Deprecated(since = "3.4.0")
public class MockitoPostProcessor implements InstantiationAwareBeanPostProcessor, BeanClassLoaderAware,
BeanFactoryAware, BeanFactoryPostProcessor, Ordered {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,11 @@
* @author Moritz Halbritter
* @since 1.4.2
* @see ResetMocksTestExecutionListener
* @deprecated since 3.4.0 in favor of
* {@link org.springframework.test.bean.override.mockito.MockitoTestExecutionListener}
*/

@Deprecated(since = "3.4.0")
public class MockitoTestExecutionListener extends AbstractTestExecutionListener {

private static final String MOCKS_ATTRIBUTE_NAME = MockitoTestExecutionListener.class.getName() + ".mocks";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@
* @author Phillip Webb
* @author Stephane Nicoll
* @see Definition
* @deprecated since 3.4.0. See {@link SpyBean} and {@link MockBean} for more details.
*/

@Deprecated(since = "3.4.0")
class QualifierDefinition {

private final Field field;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@
* @author Phillip Webb
* @since 1.4.0
* @see MockitoTestExecutionListener
* @deprecated since 3.4.0 in favor of
* {@link org.springframework.test.bean.override.mockito.MockitoResetTestExecutionListener}
*/
@Deprecated(since = "3.4.0")
public class ResetMocksTestExecutionListener extends AbstractTestExecutionListener {

private static final boolean MOCKITO_IS_PRESENT = ClassUtils.isPresent("org.mockito.MockSettings",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,10 @@
* @author Phillip Webb
* @since 1.4.0
* @see MockitoPostProcessor
* @deprecated since 3.4.0 in favor of
* {@link org.springframework.test.bean.override.mockito.MockitoSpyBean}
*/
@Deprecated(since = "3.4.0")
@Target({ ElementType.TYPE, ElementType.FIELD })
@Retention(RetentionPolicy.RUNTIME)
@Documented
Expand Down
Loading