From 5c1f93d9a67352cb0a2bb1efb7309ae5d3542434 Mon Sep 17 00:00:00 2001 From: Sam Brannen Date: Fri, 16 Aug 2019 14:34:45 +0200 Subject: [PATCH] Migrate spring-test test suite from JUnit 4 to JUnit Jupiter This commit migrates the spring-test test suite from JUnit 4 to JUnit Jupiter where applicable. Tests specific to our JUnit 4 and TestNG support remain written using those frameworks. In addition, some tests are still written in JUnit 4 if they extend a test class that should not be migrated to JUnit Jupiter. See gh-23451 --- .../reactive/MockServerHttpRequestTests.java | 9 +- .../reactive/MockServerHttpResponseTests.java | 7 +- .../mock/web/MockCookieTests.java | 21 +- .../mock/web/MockFilterChainTests.java | 24 +- .../mock/web/MockHttpServletRequestTests.java | 124 ++++----- .../web/MockHttpServletResponseTests.java | 70 ++--- .../mock/web/MockHttpSessionTests.java | 38 +-- .../MockMultipartHttpServletRequestTests.java | 8 +- .../mock/web/MockPageContextTests.java | 8 +- .../mock/web/MockServletContextTests.java | 34 +-- .../annotation/ProfileValueUtilsTests.java | 16 +- .../test/context/BootstrapUtilsTests.java | 22 +- .../ContextHierarchyDirtiesContextTests.java | 42 +-- .../MergedContextConfigurationTests.java | 74 ++--- .../context/TestContextConcurrencyTests.java | 11 +- ...ntextManagerSuppressedExceptionsTests.java | 10 +- .../test/context/TestContextManagerTests.java | 8 +- .../context/TestExecutionListenersTests.java | 38 +-- .../ClassLevelDirtiesContextTestNGTests.java | 23 +- .../cache/ClassLevelDirtiesContextTests.java | 37 +-- .../test/context/cache/ContextCacheTests.java | 30 +-- .../context/cache/ContextCacheUtilsTests.java | 28 +- .../context/cache/LruContextCacheTests.java | 22 +- .../cache/MethodLevelDirtiesContextTests.java | 54 ++-- ... => SpringExtensionContextCacheTests.java} | 47 ++-- .../ActiveProfilesInterfaceTests.java | 12 +- .../BootstrapWithInterfaceTests.java | 12 +- .../ContextConfigurationInterfaceTests.java | 12 +- .../ContextHierarchyInterfaceTests.java | 12 +- .../DirtiesContextInterfaceTests.java | 20 +- .../interfaces/SqlConfigInterfaceTests.java | 29 +- .../TestPropertySourceInterfaceTests.java | 13 +- .../WebAppConfigurationInterfaceTests.java | 12 +- ...PropertiesFileTestPropertySourceTests.java | 12 +- ...sFileDetectionTestPropertySourceTests.java | 12 +- ...PropertiesFileTestPropertySourceTests.java | 12 +- ...sFileDetectionTestPropertySourceTests.java | 7 +- ...PropertiesFileTestPropertySourceTests.java | 2 +- ...ropertiesFilesTestPropertySourceTests.java | 12 +- ...inedPropertiesTestPropertySourceTests.java | 14 +- ...inedPropertiesTestPropertySourceTests.java | 8 +- ...ropertiesFilesTestPropertySourceTests.java | 6 +- ...PropertiesFileTestPropertySourceTests.java | 24 +- .../env/TestPropertySourceTestSuite.java | 2 +- ...ractRepeatableTestPropertySourceTests.java | 6 +- ...ectionRepeatedTestPropertySourceTests.java | 6 +- ...sFilesRepeatedTestPropertySourceTests.java | 6 +- ...pertyAndInheritedInlinedPropertyTests.java | 6 +- ...edPropertyAndMetaInlinedPropertyTests.java | 6 +- ...opertyAndMetaMetaInlinedPropertyTests.java | 6 +- ...nheritedAndMetaInlinedPropertiesTests.java | 6 +- ...verridesInheritedInlinedPropertyTests.java | 6 +- ...ertyOverridesMetaInlinedPropertyTests.java | 6 +- ...pertiesFileAndMetaPropertiesFileTests.java | 6 +- ...OverridesMetaMetaInlinedPropertyTests.java | 6 +- .../RepeatedTestPropertySourceTests.java | 6 +- ...sFilesRepeatedTestPropertySourceTests.java | 6 +- ...PropertiesFileTestPropertySourceTests.java | 2 +- .../context/event/CustomTestEventTests.java | 12 +- ...TestExecutionListenerIntegrationTests.java | 12 +- ...tPublishingTestExecutionListenerTests.java | 52 ++-- .../expression/ExpressionUsageTests.java | 15 +- .../AbsolutePathGroovySpringContextTests.java | 2 +- ...riptDetectionGroovySpringContextTests.java | 19 +- ...XmlSupersedesGroovySpringContextTests.java | 15 +- .../groovy/GroovyControlGroupTests.java | 6 +- .../groovy/GroovySpringContextTests.java | 22 +- .../MixedXmlAndGroovySpringContextTests.java | 20 +- .../RelativePathGroovySpringContextTests.java | 2 +- .../meta/MetaHierarchyLevelOneTests.java | 12 +- .../meta/MetaHierarchyLevelTwoTests.java | 10 +- ...ierarchyWithMergedConfigLevelOneTests.java | 18 +- ...ierarchyWithMergedConfigLevelTwoTests.java | 14 +- ...rchyWithOverriddenConfigLevelTwoTests.java | 16 +- ...rtiesContextWithContextHierarchyTests.java | 135 +++++----- ...sWithSingleLevelContextHierarchyTests.java | 14 +- ...textHierarchyAndMixedConfigTypesTests.java | 16 +- ...lassWithTwoLevelContextHierarchyTests.java | 18 +- ...reContextConfigurationInSubclassTests.java | 16 +- ...ContextConfigurationInSuperclassTests.java | 16 +- ...eWithSingleLevelContextHierarchyTests.java | 16 +- ...reContextConfigurationInSubclassTests.java | 16 +- ...ContextConfigurationInSuperclassTests.java | 16 +- ...textHierarchyAndMixedConfigTypesTests.java | 12 +- ...oWithSingleLevelContextHierarchyTests.java | 16 +- .../web/ControllerIntegrationTests.java | 16 +- .../web/DispatcherWacRootWacEarTests.java | 14 +- .../context/hierarchies/web/EarTests.java | 14 +- .../hierarchies/web/RootWacEarTests.java | 14 +- .../jdbc/AbstractTransactionalTests.java | 55 ++++ .../ComposedAnnotationSqlScriptsTests.java | 14 +- .../CustomScriptSyntaxSqlScriptsTests.java | 13 +- .../jdbc/DataSourceOnlySqlScriptsTests.java | 37 ++- ...DefaultScriptDetectionSqlScriptsTests.java | 19 +- .../context/jdbc/EmptyDatabaseConfig.java | 6 +- ...obalCustomScriptSyntaxSqlScriptsTests.java | 13 +- .../InferredDataSourceSqlScriptsTests.java | 43 ++- ...ataSourceTransactionalSqlScriptsTests.java | 27 +- ...solatedTransactionModeSqlScriptsTests.java | 21 +- .../context/jdbc/MergedSqlConfigTests.java | 42 +-- .../jdbc/MetaAnnotationSqlScriptsTests.java | 18 +- ...AndTransactionManagersSqlScriptsTests.java | 23 +- ...nManagersTransactionalSqlScriptsTests.java | 27 +- .../jdbc/NonTransactionalSqlScriptsTests.java | 28 +- .../jdbc/PopulatedSchemaDatabaseConfig.java | 6 +- ...tedSchemaTransactionalSqlScriptsTests.java | 19 +- .../context/jdbc/PrimaryDataSourceTests.java | 19 +- ...epeatableSqlAnnotationSqlScriptsTests.java | 26 +- .../SqlScriptsTestExecutionListenerTests.java | 14 +- ...ctionalAfterTestMethodSqlScriptsTests.java | 53 ++-- ...ionalInlinedStatementsSqlScriptsTests.java | 44 +-- .../jdbc/TransactionalSqlScriptsTests.java | 44 +-- .../merging/AbstractSqlMergeModeTests.java | 13 +- .../ClassLevelMergeSqlMergeModeTests.java | 10 +- .../ClassLevelOverrideSqlMergeModeTests.java | 10 +- .../context/junit4/SpringJUnit4TestSuite.java | 8 - .../SpringJUnit4ConcurrencyTests.java | 12 - .../ProgrammaticTxMgmtSpringRuleTests.java | 255 +++++++++++++++++- ...ransactionalSqlScriptsSpringRuleTests.java | 8 +- .../support/ActiveProfilesUtilsTests.java | 58 ++-- .../AnnotationConfigContextLoaderTests.java | 18 +- ...notationConfigContextLoaderUtilsTests.java | 12 +- ...strapTestUtilsContextInitializerTests.java | 14 +- .../BootstrapTestUtilsMergedConfigTests.java | 32 +-- ...aderUtilsConfigurationAttributesTests.java | 26 +- ...ntextLoaderUtilsContextHierarchyTests.java | 42 +-- ...ustomizedGenericXmlContextLoaderTests.java | 11 +- .../DelegatingSmartContextLoaderTests.java | 28 +- ...tiesContextTestExecutionListenerTests.java | 42 +-- .../GenericPropertiesContextLoaderTests.java | 10 +- ...mlContextLoaderResourceLocationsTests.java | 35 +-- .../support/GenericXmlContextLoaderTests.java | 10 +- .../support/TestConstructorUtilsTests.java | 22 +- .../support/TestPropertySourceUtilsTests.java | 56 ++-- .../ProgrammaticTxMgmtTestNGTests.java | 14 +- .../PrimaryTransactionManagerTests.java | 28 +- ...ansactionalTestExecutionListenerTests.java | 55 ++-- .../ejb/AbstractEjbTxDaoTests.java | 27 +- .../ejb/CommitForRequiredEjbTxDaoTests.java | 2 +- .../CommitForRequiresNewEjbTxDaoTests.java | 2 +- .../ejb/RollbackForRequiredEjbTxDaoTests.java | 27 +- .../RollbackForRequiresNewEjbTxDaoTests.java | 2 +- .../programmatic/ProgrammaticTxMgmtTests.java | 123 +++++---- .../context/web/AbstractBasicWacTests.java | 4 +- ...AnnotationConfigWebContextLoaderTests.java | 10 +- .../web/GenericXmlWebContextLoaderTests.java | 10 +- .../web/MetaAnnotationConfigWacTests.java | 20 +- .../RequestAndSessionScopedBeansWacTests.java | 28 +- ...xecutionListenerJUnitIntegrationTests.java | 16 +- .../ServletTestExecutionListenerTests.java | 22 +- ...WebAppConfigurationBootstrapWithTests.java | 14 +- .../web/WebContextLoaderTestSuite.java | 42 --- ...ervletServerContainerFactoryBeanTests.java | 16 +- .../test/jdbc/JdbcTestUtilsTests.java | 16 +- .../test/util/AopTestUtilsTests.java | 32 +-- .../util/JsonPathExpectationsHelperTests.java | 104 +++---- .../test/util/MetaAnnotationUtilsTests.java | 74 ++--- ...erriddenMetaAnnotationAttributesTests.java | 16 +- .../test/util/ReflectionTestUtilsTests.java | 105 ++++---- .../test/util/XmlExpectationsHelperTests.java | 15 +- .../DefaultRequestExpectationTests.java | 2 +- .../client/MockRestServiceServerTests.java | 2 +- .../SimpleRequestExpectationManagerTests.java | 2 +- ...orderedRequestExpectationManagerTests.java | 2 +- .../match/ContentRequestMatchersTests.java | 6 +- .../match/JsonPathRequestMatchersTests.java | 2 +- .../match/MockRestRequestMatchersTests.java | 2 +- .../match/XpathRequestMatchersTests.java | 6 +- .../response/ResponseCreatorsTests.java | 2 +- .../MockMvcClientHttpRequestFactoryTests.java | 12 +- .../web/client/samples/SampleAsyncTests.java | 2 +- .../test/web/client/samples/SampleTests.java | 6 +- ...ontentRequestMatchersIntegrationTests.java | 6 +- ...HeaderRequestMatchersIntegrationTests.java | 6 +- ...onPathRequestMatchersIntegrationTests.java | 2 +- ...ontentRequestMatchersIntegrationTests.java | 6 +- .../XpathRequestMatchersIntegrationTests.java | 6 +- .../server/ApplicationContextSpecTests.java | 2 +- .../server/DefaultControllerSpecTests.java | 2 +- .../DefaultRouterFunctionSpecTests.java | 2 +- .../reactive/server/HeaderAssertionTests.java | 2 +- .../server/HttpHandlerConnectorTests.java | 2 +- .../reactive/server/MockServerSpecTests.java | 2 +- .../web/reactive/server/MockServerTests.java | 2 +- .../reactive/server/StatusAssertionTests.java | 2 +- .../server/WiretapConnectorTests.java | 2 +- .../reactive/server/samples/ErrorTests.java | 2 +- .../server/samples/ExchangeMutatorTests.java | 6 +- .../server/samples/HeaderAndCookieTests.java | 2 +- .../server/samples/JsonContentTests.java | 2 +- .../server/samples/ResponseEntityTests.java | 2 +- .../server/samples/XmlContentTests.java | 2 +- .../samples/bind/ApplicationContextTests.java | 6 +- .../server/samples/bind/ControllerTests.java | 6 +- .../server/samples/bind/HttpServerTests.java | 10 +- .../samples/bind/RouterFunctionTests.java | 6 +- .../server/samples/bind/WebFilterTests.java | 2 +- .../web/servlet/DefaultMvcResultTests.java | 2 +- .../test/web/servlet/MockMvcReuseTests.java | 12 +- .../DelegatingWebConnectionTests.java | 18 +- .../htmlunit/HostRequestMatcherTests.java | 2 +- .../htmlunit/HtmlUnitRequestBuilderTests.java | 6 +- .../MockMvcConnectionBuilderSupportTests.java | 12 +- .../MockMvcWebClientBuilderTests.java | 12 +- .../htmlunit/MockMvcWebConnectionTests.java | 2 +- .../htmlunit/MockWebResponseBuilderTests.java | 6 +- .../htmlunit/UrlRegexRequestMatcherTests.java | 2 +- .../MockMvcHtmlUnitDriverBuilderTests.java | 33 +-- .../WebConnectionHtmlUnitDriverTests.java | 26 +- .../MockHttpServletRequestBuilderTests.java | 6 +- ...ltipartHttpServletRequestBuilderTests.java | 2 +- .../result/ContentResultMatchersTests.java | 2 +- .../FlashAttributeResultMatchersTests.java | 2 +- .../result/HeaderResultMatchersTests.java | 2 +- .../result/JsonPathResultMatchersTests.java | 2 +- .../result/MockMvcResultMatchersTests.java | 2 +- .../result/ModelResultMatchersTests.java | 6 +- .../result/PrintingResultHandlerTests.java | 2 +- .../result/StatusResultMatchersTests.java | 2 +- .../result/XpathResultMatchersTests.java | 2 +- .../AsyncControllerJavaConfigTests.java | 12 +- .../samples/context/JavaConfigTests.java | 12 +- .../samples/context/WebAppResourceTests.java | 12 +- .../samples/context/XmlConfigTests.java | 12 +- ...stAttributesRequestContextHolderTests.java | 10 +- .../servlet/samples/spr/EncodedUriTests.java | 12 +- .../servlet/samples/spr/FormContentTests.java | 2 +- .../servlet/samples/spr/HttpOptionsTests.java | 12 +- .../spr/MockMvcBuilderMethodChainTests.java | 8 +- .../spr/RequestContextHolderTests.java | 16 +- .../samples/standalone/AsyncTests.java | 2 +- .../standalone/ExceptionHandlerTests.java | 2 +- .../samples/standalone/FilterTests.java | 2 +- .../standalone/FrameworkExtensionTests.java | 6 +- .../standalone/MultipartControllerTests.java | 2 +- .../standalone/ReactiveReturnTypeTests.java | 2 +- .../samples/standalone/RedirectTests.java | 6 +- .../standalone/RequestParameterTests.java | 2 +- .../samples/standalone/ResponseBodyTests.java | 2 +- .../standalone/ViewResolutionTests.java | 2 +- .../PrintingResultHandlerSmokeTests.java | 8 +- .../resultmatchers/ContentAssertionTests.java | 6 +- .../resultmatchers/CookieAssertionTests.java | 6 +- .../FlashAttributeAssertionTests.java | 6 +- .../resultmatchers/HandlerAssertionTests.java | 2 +- .../resultmatchers/HeaderAssertionTests.java | 6 +- .../JsonPathAssertionTests.java | 6 +- .../resultmatchers/ModelAssertionTests.java | 6 +- .../RequestAttributeAssertionTests.java | 6 +- .../SessionAttributeAssertionTests.java | 6 +- .../resultmatchers/StatusAssertionTests.java | 2 +- .../resultmatchers/UrlAssertionTests.java | 6 +- .../ViewNameAssertionTests.java | 6 +- .../XmlContentAssertionTests.java | 6 +- .../resultmatchers/XpathAssertionTests.java | 6 +- ...ConditionalDelegatingFilterProxyTests.java | 6 +- .../setup/DefaultMockMvcBuilderTests.java | 2 +- .../servlet/setup/SharedHttpSessionTests.java | 2 +- .../setup/StandaloneMockMvcBuilderTests.java | 2 +- .../server/WebTestClientExtensionsTests.kt | 2 +- .../web/servlet/MockMvcExtensionsTests.kt | 2 +- .../StatusResultMatchersExtensionsTests.kt | 2 +- 262 files changed, 2227 insertions(+), 2191 deletions(-) rename spring-test/src/test/java/org/springframework/test/context/cache/{SpringRunnerContextCacheTests.java => SpringExtensionContextCacheTests.java} (66%) create mode 100644 spring-test/src/test/java/org/springframework/test/context/jdbc/AbstractTransactionalTests.java delete mode 100644 spring-test/src/test/java/org/springframework/test/context/web/WebContextLoaderTestSuite.java diff --git a/spring-test/src/test/java/org/springframework/mock/http/server/reactive/MockServerHttpRequestTests.java b/spring-test/src/test/java/org/springframework/mock/http/server/reactive/MockServerHttpRequestTests.java index 3e29bec482..c3a44c23be 100644 --- a/spring-test/src/test/java/org/springframework/mock/http/server/reactive/MockServerHttpRequestTests.java +++ b/spring-test/src/test/java/org/springframework/mock/http/server/reactive/MockServerHttpRequestTests.java @@ -13,11 +13,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.mock.http.server.reactive; import java.util.Arrays; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.http.HttpCookie; import org.springframework.http.HttpHeaders; @@ -28,10 +29,10 @@ import static org.assertj.core.api.Assertions.assertThat; * Unit tests for {@link MockServerHttpRequest}. * @author Rossen Stoyanchev */ -public class MockServerHttpRequestTests { +class MockServerHttpRequestTests { @Test - public void cookieHeaderSet() throws Exception { + void cookieHeaderSet() throws Exception { HttpCookie foo11 = new HttpCookie("foo1", "bar1"); HttpCookie foo12 = new HttpCookie("foo1", "bar2"); HttpCookie foo21 = new HttpCookie("foo2", "baz1"); @@ -46,7 +47,7 @@ public class MockServerHttpRequestTests { } @Test - public void queryParams() throws Exception { + void queryParams() throws Exception { MockServerHttpRequest request = MockServerHttpRequest.get("/foo bar?a=b") .queryParam("name A", "value A1", "value A2") .queryParam("name B", "value B1") diff --git a/spring-test/src/test/java/org/springframework/mock/http/server/reactive/MockServerHttpResponseTests.java b/spring-test/src/test/java/org/springframework/mock/http/server/reactive/MockServerHttpResponseTests.java index 2eb73f8f40..c02c9e5aee 100644 --- a/spring-test/src/test/java/org/springframework/mock/http/server/reactive/MockServerHttpResponseTests.java +++ b/spring-test/src/test/java/org/springframework/mock/http/server/reactive/MockServerHttpResponseTests.java @@ -13,11 +13,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.mock.http.server.reactive; import java.util.Arrays; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.http.HttpHeaders; import org.springframework.http.ResponseCookie; @@ -28,10 +29,10 @@ import static org.assertj.core.api.Assertions.assertThat; * Unit tests for {@link MockServerHttpResponse}. * @author Rossen Stoyanchev */ -public class MockServerHttpResponseTests { +class MockServerHttpResponseTests { @Test - public void cookieHeaderSet() throws Exception { + void cookieHeaderSet() throws Exception { ResponseCookie foo11 = ResponseCookie.from("foo1", "bar1").build(); ResponseCookie foo12 = ResponseCookie.from("foo1", "bar2").build(); diff --git a/spring-test/src/test/java/org/springframework/mock/web/MockCookieTests.java b/spring-test/src/test/java/org/springframework/mock/web/MockCookieTests.java index 5d18b33832..0883956d0a 100644 --- a/spring-test/src/test/java/org/springframework/mock/web/MockCookieTests.java +++ b/spring-test/src/test/java/org/springframework/mock/web/MockCookieTests.java @@ -16,7 +16,7 @@ package org.springframework.mock.web; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; @@ -28,11 +28,10 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException * @author Sam Brannen * @since 5.1 */ -public class MockCookieTests { - +class MockCookieTests { @Test - public void constructCookie() { + void constructCookie() { MockCookie cookie = new MockCookie("SESSION", "123"); assertCookie(cookie, "SESSION", "123"); @@ -45,7 +44,7 @@ public class MockCookieTests { } @Test - public void setSameSite() { + void setSameSite() { MockCookie cookie = new MockCookie("SESSION", "123"); cookie.setSameSite("Strict"); @@ -53,7 +52,7 @@ public class MockCookieTests { } @Test - public void parseHeaderWithoutAttributes() { + void parseHeaderWithoutAttributes() { MockCookie cookie = MockCookie.parse("SESSION=123"); assertCookie(cookie, "SESSION", "123"); @@ -62,7 +61,7 @@ public class MockCookieTests { } @Test - public void parseHeaderWithAttributes() { + void parseHeaderWithAttributes() { MockCookie cookie = MockCookie.parse( "SESSION=123; Domain=example.com; Max-Age=60; Path=/; Secure; HttpOnly; SameSite=Lax"); @@ -81,21 +80,21 @@ public class MockCookieTests { } @Test - public void parseNullHeader() { + void parseNullHeader() { assertThatIllegalArgumentException().isThrownBy(() -> MockCookie.parse(null)) .withMessageContaining("Set-Cookie header must not be null"); } @Test - public void parseInvalidHeader() { + void parseInvalidHeader() { assertThatIllegalArgumentException().isThrownBy(() -> MockCookie.parse("BOOM")) .withMessageContaining("Invalid Set-Cookie header 'BOOM'"); } @Test - public void parseInvalidAttribute() { + void parseInvalidAttribute() { String header = "SESSION=123; Path="; assertThatIllegalArgumentException().isThrownBy(() -> @@ -104,7 +103,7 @@ public class MockCookieTests { } @Test - public void parseHeaderWithAttributesCaseSensitivity() { + void parseHeaderWithAttributesCaseSensitivity() { MockCookie cookie = MockCookie.parse( "SESSION=123; domain=example.com; max-age=60; path=/; secure; httponly; samesite=Lax"); diff --git a/spring-test/src/test/java/org/springframework/mock/web/MockFilterChainTests.java b/spring-test/src/test/java/org/springframework/mock/web/MockFilterChainTests.java index eee25d18ae..493a529ee0 100644 --- a/spring-test/src/test/java/org/springframework/mock/web/MockFilterChainTests.java +++ b/spring-test/src/test/java/org/springframework/mock/web/MockFilterChainTests.java @@ -25,8 +25,8 @@ import javax.servlet.ServletException; import javax.servlet.ServletRequest; import javax.servlet.ServletResponse; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; @@ -39,46 +39,46 @@ import static org.mockito.Mockito.verify; * * @author Rob Winch */ -public class MockFilterChainTests { +class MockFilterChainTests { private ServletRequest request; private ServletResponse response; - @Before - public void setup() { + @BeforeEach + void setup() { this.request = new MockHttpServletRequest(); this.response = new MockHttpServletResponse(); } @Test - public void constructorNullServlet() { + void constructorNullServlet() { assertThatIllegalArgumentException().isThrownBy(() -> new MockFilterChain((Servlet) null)); } @Test - public void constructorNullFilter() { + void constructorNullFilter() { assertThatIllegalArgumentException().isThrownBy(() -> new MockFilterChain(mock(Servlet.class), (Filter) null)); } @Test - public void doFilterNullRequest() throws Exception { + void doFilterNullRequest() throws Exception { MockFilterChain chain = new MockFilterChain(); assertThatIllegalArgumentException().isThrownBy(() -> chain.doFilter(null, this.response)); } @Test - public void doFilterNullResponse() throws Exception { + void doFilterNullResponse() throws Exception { MockFilterChain chain = new MockFilterChain(); assertThatIllegalArgumentException().isThrownBy(() -> chain.doFilter(this.request, null)); } @Test - public void doFilterEmptyChain() throws Exception { + void doFilterEmptyChain() throws Exception { MockFilterChain chain = new MockFilterChain(); chain.doFilter(this.request, this.response); @@ -91,7 +91,7 @@ public class MockFilterChainTests { } @Test - public void doFilterWithServlet() throws Exception { + void doFilterWithServlet() throws Exception { Servlet servlet = mock(Servlet.class); MockFilterChain chain = new MockFilterChain(servlet); chain.doFilter(this.request, this.response); @@ -102,7 +102,7 @@ public class MockFilterChainTests { } @Test - public void doFilterWithServletAndFilters() throws Exception { + void doFilterWithServletAndFilters() throws Exception { Servlet servlet = mock(Servlet.class); MockFilter filter2 = new MockFilter(servlet); diff --git a/spring-test/src/test/java/org/springframework/mock/web/MockHttpServletRequestTests.java b/spring-test/src/test/java/org/springframework/mock/web/MockHttpServletRequestTests.java index d51f361d98..a77bb0b469 100644 --- a/spring-test/src/test/java/org/springframework/mock/web/MockHttpServletRequestTests.java +++ b/spring-test/src/test/java/org/springframework/mock/web/MockHttpServletRequestTests.java @@ -29,7 +29,7 @@ import java.util.Locale; import java.util.Map; import javax.servlet.http.Cookie; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.http.HttpHeaders; import org.springframework.util.FileCopyUtils; @@ -50,7 +50,7 @@ import static org.assertj.core.api.Assertions.assertThatIllegalStateException; * @author Jakub Narloch * @author Av Pinzur */ -public class MockHttpServletRequestTests { +class MockHttpServletRequestTests { private static final String HOST = "Host"; @@ -58,7 +58,7 @@ public class MockHttpServletRequestTests { @Test - public void protocolAndScheme() { + void protocolAndScheme() { assertThat(request.getProtocol()).isEqualTo(MockHttpServletRequest.DEFAULT_PROTOCOL); assertThat(request.getScheme()).isEqualTo(MockHttpServletRequest.DEFAULT_SCHEME); request.setProtocol("HTTP/2.0"); @@ -68,7 +68,7 @@ public class MockHttpServletRequestTests { } @Test - public void setContentAndGetInputStream() throws IOException { + void setContentAndGetInputStream() throws IOException { byte[] bytes = "body".getBytes(Charset.defaultCharset()); request.setContent(bytes); assertThat(request.getContentLength()).isEqualTo(bytes.length); @@ -80,7 +80,7 @@ public class MockHttpServletRequestTests { } @Test - public void setContentAndGetReader() throws IOException { + void setContentAndGetReader() throws IOException { byte[] bytes = "body".getBytes(Charset.defaultCharset()); request.setContent(bytes); assertThat(request.getContentLength()).isEqualTo(bytes.length); @@ -92,7 +92,7 @@ public class MockHttpServletRequestTests { } @Test - public void setContentAndGetContentAsByteArray() { + void setContentAndGetContentAsByteArray() { byte[] bytes = "request body".getBytes(); request.setContent(bytes); assertThat(request.getContentLength()).isEqualTo(bytes.length); @@ -100,14 +100,14 @@ public class MockHttpServletRequestTests { } @Test - public void getContentAsStringWithoutSettingCharacterEncoding() throws IOException { + void getContentAsStringWithoutSettingCharacterEncoding() throws IOException { assertThatIllegalStateException().isThrownBy( request::getContentAsString) .withMessageContaining("Cannot get content as a String for a null character encoding"); } @Test - public void setContentAndGetContentAsStringWithExplicitCharacterEncoding() throws IOException { + void setContentAndGetContentAsStringWithExplicitCharacterEncoding() throws IOException { String palindrome = "ablE was I ere I saw Elba"; byte[] bytes = palindrome.getBytes("UTF-16"); request.setCharacterEncoding("UTF-16"); @@ -117,28 +117,28 @@ public class MockHttpServletRequestTests { } @Test - public void noContent() throws IOException { + void noContent() throws IOException { assertThat(request.getContentLength()).isEqualTo(-1); assertThat(request.getInputStream().read()).isEqualTo(-1); assertThat(request.getContentAsByteArray()).isNull(); } @Test // SPR-16505 - public void getReaderTwice() throws IOException { + void getReaderTwice() throws IOException { byte[] bytes = "body".getBytes(Charset.defaultCharset()); request.setContent(bytes); assertThat(request.getReader()).isSameAs(request.getReader()); } @Test // SPR-16505 - public void getInputStreamTwice() throws IOException { + void getInputStreamTwice() throws IOException { byte[] bytes = "body".getBytes(Charset.defaultCharset()); request.setContent(bytes); assertThat(request.getInputStream()).isSameAs(request.getInputStream()); } @Test // SPR-16499 - public void getReaderAfterGettingInputStream() throws IOException { + void getReaderAfterGettingInputStream() throws IOException { request.getInputStream(); assertThatIllegalStateException().isThrownBy( request::getReader) @@ -146,7 +146,7 @@ public class MockHttpServletRequestTests { } @Test // SPR-16499 - public void getInputStreamAfterGettingReader() throws IOException { + void getInputStreamAfterGettingReader() throws IOException { request.getReader(); assertThatIllegalStateException().isThrownBy( request::getInputStream) @@ -154,7 +154,7 @@ public class MockHttpServletRequestTests { } @Test - public void setContentType() { + void setContentType() { String contentType = "test/plain"; request.setContentType(contentType); assertThat(request.getContentType()).isEqualTo(contentType); @@ -163,7 +163,7 @@ public class MockHttpServletRequestTests { } @Test - public void setContentTypeUTF8() { + void setContentTypeUTF8() { String contentType = "test/plain;charset=UTF-8"; request.setContentType(contentType); assertThat(request.getContentType()).isEqualTo(contentType); @@ -172,7 +172,7 @@ public class MockHttpServletRequestTests { } @Test - public void contentTypeHeader() { + void contentTypeHeader() { String contentType = "test/plain"; request.addHeader(HttpHeaders.CONTENT_TYPE, contentType); assertThat(request.getContentType()).isEqualTo(contentType); @@ -181,7 +181,7 @@ public class MockHttpServletRequestTests { } @Test - public void contentTypeHeaderUTF8() { + void contentTypeHeaderUTF8() { String contentType = "test/plain;charset=UTF-8"; request.addHeader(HttpHeaders.CONTENT_TYPE, contentType); assertThat(request.getContentType()).isEqualTo(contentType); @@ -190,7 +190,7 @@ public class MockHttpServletRequestTests { } @Test // SPR-12677 - public void setContentTypeHeaderWithMoreComplexCharsetSyntax() { + void setContentTypeHeaderWithMoreComplexCharsetSyntax() { String contentType = "test/plain;charset=\"utf-8\";foo=\"charset=bar\";foocharset=bar;foo=bar"; request.addHeader(HttpHeaders.CONTENT_TYPE, contentType); assertThat(request.getContentType()).isEqualTo(contentType); @@ -199,7 +199,7 @@ public class MockHttpServletRequestTests { } @Test - public void setContentTypeThenCharacterEncoding() { + void setContentTypeThenCharacterEncoding() { request.setContentType("test/plain"); request.setCharacterEncoding("UTF-8"); assertThat(request.getContentType()).isEqualTo("test/plain"); @@ -208,7 +208,7 @@ public class MockHttpServletRequestTests { } @Test - public void setCharacterEncodingThenContentType() { + void setCharacterEncodingThenContentType() { request.setCharacterEncoding("UTF-8"); request.setContentType("test/plain"); assertThat(request.getContentType()).isEqualTo("test/plain"); @@ -217,7 +217,7 @@ public class MockHttpServletRequestTests { } @Test - public void httpHeaderNameCasingIsPreserved() { + void httpHeaderNameCasingIsPreserved() { String headerName = "Header1"; request.addHeader(headerName, "value1"); Enumeration requestHeaders = request.getHeaderNames(); @@ -225,7 +225,7 @@ public class MockHttpServletRequestTests { } @Test - public void setMultipleParameters() { + void setMultipleParameters() { request.setParameter("key1", "value1"); request.setParameter("key2", "value2"); Map params = new HashMap<>(2); @@ -243,7 +243,7 @@ public class MockHttpServletRequestTests { } @Test - public void addMultipleParameters() { + void addMultipleParameters() { request.setParameter("key1", "value1"); request.setParameter("key2", "value2"); Map params = new HashMap<>(2); @@ -262,7 +262,7 @@ public class MockHttpServletRequestTests { } @Test - public void removeAllParameters() { + void removeAllParameters() { request.setParameter("key1", "value1"); Map params = new HashMap<>(2); params.put("key2", "value2"); @@ -274,7 +274,7 @@ public class MockHttpServletRequestTests { } @Test - public void cookies() { + void cookies() { Cookie cookie1 = new Cookie("foo", "bar"); Cookie cookie2 = new Cookie("baz", "qux"); request.setCookies(cookie1, cookie2); @@ -299,12 +299,12 @@ public class MockHttpServletRequestTests { } @Test - public void noCookies() { + void noCookies() { assertThat(request.getCookies()).isNull(); } @Test - public void defaultLocale() { + void defaultLocale() { Locale originalDefaultLocale = Locale.getDefault(); try { Locale newDefaultLocale = originalDefaultLocale.equals(Locale.GERMANY) ? Locale.FRANCE : Locale.GERMANY; @@ -320,19 +320,19 @@ public class MockHttpServletRequestTests { } @Test - public void setPreferredLocalesWithNullList() { + void setPreferredLocalesWithNullList() { assertThatIllegalArgumentException().isThrownBy(() -> request.setPreferredLocales(null)); } @Test - public void setPreferredLocalesWithEmptyList() { + void setPreferredLocalesWithEmptyList() { assertThatIllegalArgumentException().isThrownBy(() -> request.setPreferredLocales(new ArrayList<>())); } @Test - public void setPreferredLocales() { + void setPreferredLocales() { List preferredLocales = Arrays.asList(Locale.ITALY, Locale.CHINA); request.setPreferredLocales(preferredLocales); assertEqualEnumerations(Collections.enumeration(preferredLocales), request.getLocales()); @@ -340,7 +340,7 @@ public class MockHttpServletRequestTests { } @Test - public void preferredLocalesFromAcceptLanguageHeader() { + void preferredLocalesFromAcceptLanguageHeader() { String headerValue = "fr-ch, fr;q=0.9, en-*;q=0.8, de;q=0.7, *;q=0.5"; request.addHeader("Accept-Language", headerValue); List actual = Collections.list(request.getLocales()); @@ -350,78 +350,78 @@ public class MockHttpServletRequestTests { } @Test - public void invalidAcceptLanguageHeader() { + void invalidAcceptLanguageHeader() { request.addHeader("Accept-Language", "en_US"); assertThat(request.getLocale()).isEqualTo(Locale.ENGLISH); assertThat(request.getHeader("Accept-Language")).isEqualTo("en_US"); } @Test - public void emptyAcceptLanguageHeader() { + void emptyAcceptLanguageHeader() { request.addHeader("Accept-Language", ""); assertThat(request.getLocale()).isEqualTo(Locale.ENGLISH); assertThat(request.getHeader("Accept-Language")).isEqualTo(""); } @Test - public void getServerNameWithDefaultName() { + void getServerNameWithDefaultName() { assertThat(request.getServerName()).isEqualTo("localhost"); } @Test - public void getServerNameWithCustomName() { + void getServerNameWithCustomName() { request.setServerName("example.com"); assertThat(request.getServerName()).isEqualTo("example.com"); } @Test - public void getServerNameViaHostHeaderWithoutPort() { + void getServerNameViaHostHeaderWithoutPort() { String testServer = "test.server"; request.addHeader(HOST, testServer); assertThat(request.getServerName()).isEqualTo(testServer); } @Test - public void getServerNameViaHostHeaderWithPort() { + void getServerNameViaHostHeaderWithPort() { String testServer = "test.server"; request.addHeader(HOST, testServer + ":8080"); assertThat(request.getServerName()).isEqualTo(testServer); } @Test - public void getServerNameViaHostHeaderAsIpv6AddressWithoutPort() { + void getServerNameViaHostHeaderAsIpv6AddressWithoutPort() { String ipv6Address = "[2001:db8:0:1]"; request.addHeader(HOST, ipv6Address); assertThat(request.getServerName()).isEqualTo("2001:db8:0:1"); } @Test - public void getServerNameViaHostHeaderAsIpv6AddressWithPort() { + void getServerNameViaHostHeaderAsIpv6AddressWithPort() { String ipv6Address = "[2001:db8:0:1]:8081"; request.addHeader(HOST, ipv6Address); assertThat(request.getServerName()).isEqualTo("2001:db8:0:1"); } @Test - public void getServerPortWithDefaultPort() { + void getServerPortWithDefaultPort() { assertThat(request.getServerPort()).isEqualTo(80); } @Test - public void getServerPortWithCustomPort() { + void getServerPortWithCustomPort() { request.setServerPort(8080); assertThat(request.getServerPort()).isEqualTo(8080); } @Test - public void getServerPortViaHostHeaderAsIpv6AddressWithoutPort() { + void getServerPortViaHostHeaderAsIpv6AddressWithoutPort() { String testServer = "[2001:db8:0:1]"; request.addHeader(HOST, testServer); assertThat(request.getServerPort()).isEqualTo(80); } @Test - public void getServerPortViaHostHeaderAsIpv6AddressWithPort() { + void getServerPortViaHostHeaderAsIpv6AddressWithPort() { String testServer = "[2001:db8:0:1]"; int testPort = 9999; request.addHeader(HOST, testServer + ":" + testPort); @@ -429,14 +429,14 @@ public class MockHttpServletRequestTests { } @Test - public void getServerPortViaHostHeaderWithoutPort() { + void getServerPortViaHostHeaderWithoutPort() { String testServer = "test.server"; request.addHeader(HOST, testServer); assertThat(request.getServerPort()).isEqualTo(80); } @Test - public void getServerPortViaHostHeaderWithPort() { + void getServerPortViaHostHeaderWithPort() { String testServer = "test.server"; int testPort = 9999; request.addHeader(HOST, testServer + ":" + testPort); @@ -444,7 +444,7 @@ public class MockHttpServletRequestTests { } @Test - public void getRequestURL() { + void getRequestURL() { request.setServerPort(8080); request.setRequestURI("/path"); assertThat(request.getRequestURL().toString()).isEqualTo("http://localhost:8080/path"); @@ -456,13 +456,13 @@ public class MockHttpServletRequestTests { } @Test - public void getRequestURLWithDefaults() { + void getRequestURLWithDefaults() { StringBuffer requestURL = request.getRequestURL(); assertThat(requestURL.toString()).isEqualTo("http://localhost"); } @Test // SPR-16138 - public void getRequestURLWithHostHeader() { + void getRequestURLWithHostHeader() { String testServer = "test.server"; request.addHeader(HOST, testServer); StringBuffer requestURL = request.getRequestURL(); @@ -470,7 +470,7 @@ public class MockHttpServletRequestTests { } @Test // SPR-16138 - public void getRequestURLWithHostHeaderAndPort() { + void getRequestURLWithHostHeaderAndPort() { String testServer = "test.server:9999"; request.addHeader(HOST, testServer); StringBuffer requestURL = request.getRequestURL(); @@ -478,14 +478,14 @@ public class MockHttpServletRequestTests { } @Test - public void getRequestURLWithNullRequestUri() { + void getRequestURLWithNullRequestUri() { request.setRequestURI(null); StringBuffer requestURL = request.getRequestURL(); assertThat(requestURL.toString()).isEqualTo("http://localhost"); } @Test - public void getRequestURLWithDefaultsAndHttps() { + void getRequestURLWithDefaultsAndHttps() { request.setScheme("https"); request.setServerPort(443); StringBuffer requestURL = request.getRequestURL(); @@ -493,14 +493,14 @@ public class MockHttpServletRequestTests { } @Test - public void getRequestURLWithNegativePort() { + void getRequestURLWithNegativePort() { request.setServerPort(-99); StringBuffer requestURL = request.getRequestURL(); assertThat(requestURL.toString()).isEqualTo("http://localhost"); } @Test - public void isSecureWithHttpSchemeAndSecureFlagIsFalse() { + void isSecureWithHttpSchemeAndSecureFlagIsFalse() { assertThat(request.isSecure()).isFalse(); request.setScheme("http"); request.setSecure(false); @@ -508,7 +508,7 @@ public class MockHttpServletRequestTests { } @Test - public void isSecureWithHttpSchemeAndSecureFlagIsTrue() { + void isSecureWithHttpSchemeAndSecureFlagIsTrue() { assertThat(request.isSecure()).isFalse(); request.setScheme("http"); request.setSecure(true); @@ -516,7 +516,7 @@ public class MockHttpServletRequestTests { } @Test - public void isSecureWithHttpsSchemeAndSecureFlagIsFalse() { + void isSecureWithHttpsSchemeAndSecureFlagIsFalse() { assertThat(request.isSecure()).isFalse(); request.setScheme("https"); request.setSecure(false); @@ -524,7 +524,7 @@ public class MockHttpServletRequestTests { } @Test - public void isSecureWithHttpsSchemeAndSecureFlagIsTrue() { + void isSecureWithHttpsSchemeAndSecureFlagIsTrue() { assertThat(request.isSecure()).isFalse(); request.setScheme("https"); request.setSecure(true); @@ -532,39 +532,39 @@ public class MockHttpServletRequestTests { } @Test - public void httpHeaderDate() { + void httpHeaderDate() { Date date = new Date(); request.addHeader(HttpHeaders.IF_MODIFIED_SINCE, date); assertThat(request.getDateHeader(HttpHeaders.IF_MODIFIED_SINCE)).isEqualTo(date.getTime()); } @Test - public void httpHeaderTimestamp() { + void httpHeaderTimestamp() { long timestamp = new Date().getTime(); request.addHeader(HttpHeaders.IF_MODIFIED_SINCE, timestamp); assertThat(request.getDateHeader(HttpHeaders.IF_MODIFIED_SINCE)).isEqualTo(timestamp); } @Test - public void httpHeaderRfcFormattedDate() { + void httpHeaderRfcFormattedDate() { request.addHeader(HttpHeaders.IF_MODIFIED_SINCE, "Tue, 21 Jul 2015 10:00:00 GMT"); assertThat(request.getDateHeader(HttpHeaders.IF_MODIFIED_SINCE)).isEqualTo(1437472800000L); } @Test - public void httpHeaderFirstVariantFormattedDate() { + void httpHeaderFirstVariantFormattedDate() { request.addHeader(HttpHeaders.IF_MODIFIED_SINCE, "Tue, 21-Jul-15 10:00:00 GMT"); assertThat(request.getDateHeader(HttpHeaders.IF_MODIFIED_SINCE)).isEqualTo(1437472800000L); } @Test - public void httpHeaderSecondVariantFormattedDate() { + void httpHeaderSecondVariantFormattedDate() { request.addHeader(HttpHeaders.IF_MODIFIED_SINCE, "Tue Jul 21 10:00:00 2015"); assertThat(request.getDateHeader(HttpHeaders.IF_MODIFIED_SINCE)).isEqualTo(1437472800000L); } @Test - public void httpHeaderFormattedDateError() { + void httpHeaderFormattedDateError() { request.addHeader(HttpHeaders.IF_MODIFIED_SINCE, "This is not a date"); assertThatIllegalArgumentException().isThrownBy(() -> request.getDateHeader(HttpHeaders.IF_MODIFIED_SINCE)); diff --git a/spring-test/src/test/java/org/springframework/mock/web/MockHttpServletResponseTests.java b/spring-test/src/test/java/org/springframework/mock/web/MockHttpServletResponseTests.java index 9063991058..f1ff821139 100644 --- a/spring-test/src/test/java/org/springframework/mock/web/MockHttpServletResponseTests.java +++ b/spring-test/src/test/java/org/springframework/mock/web/MockHttpServletResponseTests.java @@ -23,7 +23,7 @@ import java.util.Collection; import javax.servlet.http.Cookie; import javax.servlet.http.HttpServletResponse; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.http.HttpHeaders; import org.springframework.web.util.WebUtils; @@ -43,13 +43,13 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException * @author Sebastien Deleuze * @since 19.02.2006 */ -public class MockHttpServletResponseTests { +class MockHttpServletResponseTests { private MockHttpServletResponse response = new MockHttpServletResponse(); @Test - public void setContentType() { + void setContentType() { String contentType = "test/plain"; response.setContentType(contentType); assertThat(response.getContentType()).isEqualTo(contentType); @@ -58,7 +58,7 @@ public class MockHttpServletResponseTests { } @Test - public void setContentTypeUTF8() { + void setContentTypeUTF8() { String contentType = "test/plain;charset=UTF-8"; response.setContentType(contentType); assertThat(response.getCharacterEncoding()).isEqualTo("UTF-8"); @@ -67,7 +67,7 @@ public class MockHttpServletResponseTests { } @Test - public void contentTypeHeader() { + void contentTypeHeader() { String contentType = "test/plain"; response.addHeader("Content-Type", contentType); assertThat(response.getContentType()).isEqualTo(contentType); @@ -82,7 +82,7 @@ public class MockHttpServletResponseTests { } @Test - public void contentTypeHeaderUTF8() { + void contentTypeHeaderUTF8() { String contentType = "test/plain;charset=UTF-8"; response.setHeader("Content-Type", contentType); assertThat(response.getContentType()).isEqualTo(contentType); @@ -97,7 +97,7 @@ public class MockHttpServletResponseTests { } @Test // SPR-12677 - public void contentTypeHeaderWithMoreComplexCharsetSyntax() { + void contentTypeHeaderWithMoreComplexCharsetSyntax() { String contentType = "test/plain;charset=\"utf-8\";foo=\"charset=bar\";foocharset=bar;foo=bar"; response.setHeader("Content-Type", contentType); assertThat(response.getContentType()).isEqualTo(contentType); @@ -112,7 +112,7 @@ public class MockHttpServletResponseTests { } @Test - public void setContentTypeThenCharacterEncoding() { + void setContentTypeThenCharacterEncoding() { response.setContentType("test/plain"); response.setCharacterEncoding("UTF-8"); assertThat(response.getContentType()).isEqualTo("test/plain"); @@ -121,7 +121,7 @@ public class MockHttpServletResponseTests { } @Test - public void setCharacterEncodingThenContentType() { + void setCharacterEncodingThenContentType() { response.setCharacterEncoding("UTF-8"); response.setContentType("test/plain"); assertThat(response.getContentType()).isEqualTo("test/plain"); @@ -130,28 +130,28 @@ public class MockHttpServletResponseTests { } @Test - public void contentLength() { + void contentLength() { response.setContentLength(66); assertThat(response.getContentLength()).isEqualTo(66); assertThat(response.getHeader("Content-Length")).isEqualTo("66"); } @Test - public void contentLengthHeader() { + void contentLengthHeader() { response.addHeader("Content-Length", "66"); assertThat(response.getContentLength()).isEqualTo(66); assertThat(response.getHeader("Content-Length")).isEqualTo("66"); } @Test - public void contentLengthIntHeader() { + void contentLengthIntHeader() { response.addIntHeader("Content-Length", 66); assertThat(response.getContentLength()).isEqualTo(66); assertThat(response.getHeader("Content-Length")).isEqualTo("66"); } @Test - public void httpHeaderNameCasingIsPreserved() throws Exception { + void httpHeaderNameCasingIsPreserved() throws Exception { final String headerName = "Header1"; response.addHeader(headerName, "value1"); Collection responseHeaders = response.getHeaderNames(); @@ -161,7 +161,7 @@ public class MockHttpServletResponseTests { } @Test - public void cookies() { + void cookies() { Cookie cookie = new Cookie("foo", "bar"); cookie.setPath("/path"); cookie.setDomain("example.com"); @@ -177,7 +177,7 @@ public class MockHttpServletResponseTests { } @Test - public void servletOutputStreamCommittedWhenBufferSizeExceeded() throws IOException { + void servletOutputStreamCommittedWhenBufferSizeExceeded() throws IOException { assertThat(response.isCommitted()).isFalse(); response.getOutputStream().write('X'); assertThat(response.isCommitted()).isFalse(); @@ -188,7 +188,7 @@ public class MockHttpServletResponseTests { } @Test - public void servletOutputStreamCommittedOnFlushBuffer() throws IOException { + void servletOutputStreamCommittedOnFlushBuffer() throws IOException { assertThat(response.isCommitted()).isFalse(); response.getOutputStream().write('X'); assertThat(response.isCommitted()).isFalse(); @@ -198,7 +198,7 @@ public class MockHttpServletResponseTests { } @Test - public void servletWriterCommittedWhenBufferSizeExceeded() throws IOException { + void servletWriterCommittedWhenBufferSizeExceeded() throws IOException { assertThat(response.isCommitted()).isFalse(); response.getWriter().write("X"); assertThat(response.isCommitted()).isFalse(); @@ -211,7 +211,7 @@ public class MockHttpServletResponseTests { } @Test - public void servletOutputStreamCommittedOnOutputStreamFlush() throws IOException { + void servletOutputStreamCommittedOnOutputStreamFlush() throws IOException { assertThat(response.isCommitted()).isFalse(); response.getOutputStream().write('X'); assertThat(response.isCommitted()).isFalse(); @@ -221,7 +221,7 @@ public class MockHttpServletResponseTests { } @Test - public void servletWriterCommittedOnWriterFlush() throws IOException { + void servletWriterCommittedOnWriterFlush() throws IOException { assertThat(response.isCommitted()).isFalse(); response.getWriter().write("X"); assertThat(response.isCommitted()).isFalse(); @@ -231,7 +231,7 @@ public class MockHttpServletResponseTests { } @Test // SPR-16683 - public void servletWriterCommittedOnWriterClose() throws IOException { + void servletWriterCommittedOnWriterClose() throws IOException { assertThat(response.isCommitted()).isFalse(); response.getWriter().write("X"); assertThat(response.isCommitted()).isFalse(); @@ -241,32 +241,32 @@ public class MockHttpServletResponseTests { } @Test // gh-23219 - public void contentAsUtf8() throws IOException { + void contentAsUtf8() throws IOException { String content = "Příliš žluťoučký kůň úpěl ďábelské ódy"; response.getOutputStream().write(content.getBytes(StandardCharsets.UTF_8)); assertThat(response.getContentAsString(StandardCharsets.UTF_8)).isEqualTo(content); } @Test - public void servletWriterAutoFlushedForChar() throws IOException { + void servletWriterAutoFlushedForChar() throws IOException { response.getWriter().write('X'); assertThat(response.getContentAsString()).isEqualTo("X"); } @Test - public void servletWriterAutoFlushedForCharArray() throws IOException { + void servletWriterAutoFlushedForCharArray() throws IOException { response.getWriter().write("XY".toCharArray()); assertThat(response.getContentAsString()).isEqualTo("XY"); } @Test - public void servletWriterAutoFlushedForString() throws IOException { + void servletWriterAutoFlushedForString() throws IOException { response.getWriter().write("X"); assertThat(response.getContentAsString()).isEqualTo("X"); } @Test - public void sendRedirect() throws IOException { + void sendRedirect() throws IOException { String redirectUrl = "/redirect"; response.sendRedirect(redirectUrl); assertThat(response.getStatus()).isEqualTo(HttpServletResponse.SC_MOVED_TEMPORARILY); @@ -276,20 +276,20 @@ public class MockHttpServletResponseTests { } @Test - public void locationHeaderUpdatesGetRedirectedUrl() { + void locationHeaderUpdatesGetRedirectedUrl() { String redirectUrl = "/redirect"; response.setHeader("Location", redirectUrl); assertThat(response.getRedirectedUrl()).isEqualTo(redirectUrl); } @Test - public void setDateHeader() { + void setDateHeader() { response.setDateHeader("Last-Modified", 1437472800000L); assertThat(response.getHeader("Last-Modified")).isEqualTo("Tue, 21 Jul 2015 10:00:00 GMT"); } @Test - public void addDateHeader() { + void addDateHeader() { response.addDateHeader("Last-Modified", 1437472800000L); response.addDateHeader("Last-Modified", 1437472801000L); assertThat(response.getHeaders("Last-Modified").get(0)).isEqualTo("Tue, 21 Jul 2015 10:00:00 GMT"); @@ -297,7 +297,7 @@ public class MockHttpServletResponseTests { } @Test - public void getDateHeader() { + void getDateHeader() { long time = 1437472800000L; response.setDateHeader("Last-Modified", time); assertThat(response.getHeader("Last-Modified")).isEqualTo("Tue, 21 Jul 2015 10:00:00 GMT"); @@ -305,7 +305,7 @@ public class MockHttpServletResponseTests { } @Test - public void getInvalidDateHeader() { + void getInvalidDateHeader() { response.setHeader("Last-Modified", "invalid"); assertThat(response.getHeader("Last-Modified")).isEqualTo("invalid"); assertThatIllegalArgumentException().isThrownBy(() -> @@ -313,13 +313,13 @@ public class MockHttpServletResponseTests { } @Test // SPR-16160 - public void getNonExistentDateHeader() { + void getNonExistentDateHeader() { assertThat(response.getHeader("Last-Modified")).isNull(); assertThat(response.getDateHeader("Last-Modified")).isEqualTo(-1); } @Test // SPR-10414 - public void modifyStatusAfterSendError() throws IOException { + void modifyStatusAfterSendError() throws IOException { response.sendError(HttpServletResponse.SC_NOT_FOUND); response.setStatus(HttpServletResponse.SC_OK); assertThat(response.getStatus()).isEqualTo(HttpServletResponse.SC_NOT_FOUND); @@ -327,14 +327,14 @@ public class MockHttpServletResponseTests { @Test // SPR-10414 @SuppressWarnings("deprecation") - public void modifyStatusMessageAfterSendError() throws IOException { + void modifyStatusMessageAfterSendError() throws IOException { response.sendError(HttpServletResponse.SC_NOT_FOUND); response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,"Server Error"); assertThat(response.getStatus()).isEqualTo(HttpServletResponse.SC_NOT_FOUND); } @Test - public void setCookieHeaderValid() { + void setCookieHeaderValid() { response.addHeader(HttpHeaders.SET_COOKIE, "SESSION=123; Path=/; Secure; HttpOnly; SameSite=Lax"); Cookie cookie = response.getCookie("SESSION"); assertThat(cookie).isNotNull(); @@ -349,7 +349,7 @@ public class MockHttpServletResponseTests { } @Test - public void addMockCookie() { + void addMockCookie() { MockCookie mockCookie = new MockCookie("SESSION", "123"); mockCookie.setPath("/"); mockCookie.setDomain("example.com"); diff --git a/spring-test/src/test/java/org/springframework/mock/web/MockHttpSessionTests.java b/spring-test/src/test/java/org/springframework/mock/web/MockHttpSessionTests.java index 54f4f551a0..a3d670a11c 100644 --- a/spring-test/src/test/java/org/springframework/mock/web/MockHttpSessionTests.java +++ b/spring-test/src/test/java/org/springframework/mock/web/MockHttpSessionTests.java @@ -20,7 +20,7 @@ import java.util.concurrent.atomic.AtomicInteger; import javax.servlet.http.HttpSessionBindingEvent; import javax.servlet.http.HttpSessionBindingListener; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatIllegalStateException; @@ -32,104 +32,104 @@ import static org.assertj.core.api.Assertions.assertThatIllegalStateException; * @author Vedran Pavic * @since 3.2 */ -public class MockHttpSessionTests { +class MockHttpSessionTests { private MockHttpSession session = new MockHttpSession(); @Test - public void invalidateOnce() { + void invalidateOnce() { assertThat(session.isInvalid()).isFalse(); session.invalidate(); assertThat(session.isInvalid()).isTrue(); } @Test - public void invalidateTwice() { + void invalidateTwice() { session.invalidate(); assertThatIllegalStateException().isThrownBy( session::invalidate); } @Test - public void getCreationTimeOnInvalidatedSession() { + void getCreationTimeOnInvalidatedSession() { session.invalidate(); assertThatIllegalStateException().isThrownBy( session::getCreationTime); } @Test - public void getLastAccessedTimeOnInvalidatedSession() { + void getLastAccessedTimeOnInvalidatedSession() { session.invalidate(); assertThatIllegalStateException().isThrownBy( session::getLastAccessedTime); } @Test - public void getAttributeOnInvalidatedSession() { + void getAttributeOnInvalidatedSession() { session.invalidate(); assertThatIllegalStateException().isThrownBy(() -> session.getAttribute("foo")); } @Test - public void getAttributeNamesOnInvalidatedSession() { + void getAttributeNamesOnInvalidatedSession() { session.invalidate(); assertThatIllegalStateException().isThrownBy( session::getAttributeNames); } @Test - public void getValueOnInvalidatedSession() { + void getValueOnInvalidatedSession() { session.invalidate(); assertThatIllegalStateException().isThrownBy(() -> session.getValue("foo")); } @Test - public void getValueNamesOnInvalidatedSession() { + void getValueNamesOnInvalidatedSession() { session.invalidate(); assertThatIllegalStateException().isThrownBy( session::getValueNames); } @Test - public void setAttributeOnInvalidatedSession() { + void setAttributeOnInvalidatedSession() { session.invalidate(); assertThatIllegalStateException().isThrownBy(() -> session.setAttribute("name", "value")); } @Test - public void putValueOnInvalidatedSession() { + void putValueOnInvalidatedSession() { session.invalidate(); assertThatIllegalStateException().isThrownBy(() -> session.putValue("name", "value")); } @Test - public void removeAttributeOnInvalidatedSession() { + void removeAttributeOnInvalidatedSession() { session.invalidate(); assertThatIllegalStateException().isThrownBy(() -> session.removeAttribute("name")); } @Test - public void removeValueOnInvalidatedSession() { + void removeValueOnInvalidatedSession() { session.invalidate(); assertThatIllegalStateException().isThrownBy(() -> session.removeValue("name")); } @Test - public void isNewOnInvalidatedSession() { + void isNewOnInvalidatedSession() { session.invalidate(); assertThatIllegalStateException().isThrownBy( session::isNew); } @Test - public void bindingListenerBindListener() { + void bindingListenerBindListener() { String bindingListenerName = "bindingListener"; CountingHttpSessionBindingListener bindingListener = new CountingHttpSessionBindingListener(); @@ -139,7 +139,7 @@ public class MockHttpSessionTests { } @Test - public void bindingListenerBindListenerThenUnbind() { + void bindingListenerBindListenerThenUnbind() { String bindingListenerName = "bindingListener"; CountingHttpSessionBindingListener bindingListener = new CountingHttpSessionBindingListener(); @@ -150,7 +150,7 @@ public class MockHttpSessionTests { } @Test - public void bindingListenerBindSameListenerTwice() { + void bindingListenerBindSameListenerTwice() { String bindingListenerName = "bindingListener"; CountingHttpSessionBindingListener bindingListener = new CountingHttpSessionBindingListener(); @@ -161,7 +161,7 @@ public class MockHttpSessionTests { } @Test - public void bindingListenerBindListenerOverwrite() { + void bindingListenerBindListenerOverwrite() { String bindingListenerName = "bindingListener"; CountingHttpSessionBindingListener bindingListener1 = new CountingHttpSessionBindingListener(); CountingHttpSessionBindingListener bindingListener2 = new CountingHttpSessionBindingListener(); diff --git a/spring-test/src/test/java/org/springframework/mock/web/MockMultipartHttpServletRequestTests.java b/spring-test/src/test/java/org/springframework/mock/web/MockMultipartHttpServletRequestTests.java index fd2f0bcd35..96fc17a33c 100644 --- a/spring-test/src/test/java/org/springframework/mock/web/MockMultipartHttpServletRequestTests.java +++ b/spring-test/src/test/java/org/springframework/mock/web/MockMultipartHttpServletRequestTests.java @@ -25,7 +25,7 @@ import java.util.List; import java.util.Map; import java.util.Set; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.util.FileCopyUtils; import org.springframework.util.ObjectUtils; @@ -37,10 +37,10 @@ import static org.assertj.core.api.Assertions.assertThat; /** * @author Juergen Hoeller */ -public class MockMultipartHttpServletRequestTests { +class MockMultipartHttpServletRequestTests { @Test - public void mockMultipartHttpServletRequestWithByteArray() throws IOException { + void mockMultipartHttpServletRequestWithByteArray() throws IOException { MockMultipartHttpServletRequest request = new MockMultipartHttpServletRequest(); assertThat(request.getFileNames().hasNext()).isFalse(); assertThat(request.getFile("file1")).isNull(); @@ -53,7 +53,7 @@ public class MockMultipartHttpServletRequestTests { } @Test - public void mockMultipartHttpServletRequestWithInputStream() throws IOException { + void mockMultipartHttpServletRequestWithInputStream() throws IOException { MockMultipartHttpServletRequest request = new MockMultipartHttpServletRequest(); request.addFile(new MockMultipartFile("file1", new ByteArrayInputStream("myContent1".getBytes()))); request.addFile(new MockMultipartFile("file2", "myOrigFilename", "text/plain", new ByteArrayInputStream( diff --git a/spring-test/src/test/java/org/springframework/mock/web/MockPageContextTests.java b/spring-test/src/test/java/org/springframework/mock/web/MockPageContextTests.java index 757dac5edd..d902633373 100644 --- a/spring-test/src/test/java/org/springframework/mock/web/MockPageContextTests.java +++ b/spring-test/src/test/java/org/springframework/mock/web/MockPageContextTests.java @@ -18,7 +18,7 @@ package org.springframework.mock.web; import javax.servlet.jsp.PageContext; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; @@ -27,7 +27,7 @@ import static org.assertj.core.api.Assertions.assertThat; * * @author Rick Evans */ -public class MockPageContextTests { +class MockPageContextTests { private final String key = "foo"; @@ -36,7 +36,7 @@ public class MockPageContextTests { private final MockPageContext ctx = new MockPageContext(); @Test - public void setAttributeWithNoScopeUsesPageScope() throws Exception { + void setAttributeWithNoScopeUsesPageScope() throws Exception { ctx.setAttribute(key, value); assertThat(ctx.getAttribute(key, PageContext.PAGE_SCOPE)).isEqualTo(value); assertThat(ctx.getAttribute(key, PageContext.APPLICATION_SCOPE)).isNull(); @@ -45,7 +45,7 @@ public class MockPageContextTests { } @Test - public void removeAttributeWithNoScopeSpecifiedRemovesValueFromAllScopes() throws Exception { + void removeAttributeWithNoScopeSpecifiedRemovesValueFromAllScopes() throws Exception { ctx.setAttribute(key, value, PageContext.APPLICATION_SCOPE); ctx.removeAttribute(key); diff --git a/spring-test/src/test/java/org/springframework/mock/web/MockServletContextTests.java b/spring-test/src/test/java/org/springframework/mock/web/MockServletContextTests.java index 56220127d0..84e90bc286 100644 --- a/spring-test/src/test/java/org/springframework/mock/web/MockServletContextTests.java +++ b/spring-test/src/test/java/org/springframework/mock/web/MockServletContextTests.java @@ -22,7 +22,7 @@ import javax.servlet.FilterRegistration; import javax.servlet.RequestDispatcher; import javax.servlet.ServletRegistration; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.http.MediaType; @@ -34,39 +34,39 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Sam Brannen * @since 19.02.2006 */ -public class MockServletContextTests { +class MockServletContextTests { private final MockServletContext sc = new MockServletContext("org/springframework/mock"); @Test - public void listFiles() { + void listFiles() { Set paths = sc.getResourcePaths("/web"); assertThat(paths).isNotNull(); assertThat(paths.contains("/web/MockServletContextTests.class")).isTrue(); } @Test - public void listSubdirectories() { + void listSubdirectories() { Set paths = sc.getResourcePaths("/"); assertThat(paths).isNotNull(); assertThat(paths.contains("/web/")).isTrue(); } @Test - public void listNonDirectory() { + void listNonDirectory() { Set paths = sc.getResourcePaths("/web/MockServletContextTests.class"); assertThat(paths).isNull(); } @Test - public void listInvalidPath() { + void listInvalidPath() { Set paths = sc.getResourcePaths("/web/invalid"); assertThat(paths).isNull(); } @Test - public void registerContextAndGetContext() { + void registerContextAndGetContext() { MockServletContext sc2 = new MockServletContext(); sc.setContextPath("/"); sc.registerContext("/second", sc2); @@ -75,7 +75,7 @@ public class MockServletContextTests { } @Test - public void getMimeType() { + void getMimeType() { assertThat(sc.getMimeType("test.html")).isEqualTo("text/html"); assertThat(sc.getMimeType("test.gif")).isEqualTo("image/gif"); assertThat(sc.getMimeType("test.foobar")).isNull(); @@ -86,13 +86,13 @@ public class MockServletContextTests { * Testing Spring managed servlet */ @Test - public void getMimeTypeWithCustomConfiguredType() { + void getMimeTypeWithCustomConfiguredType() { sc.addMimeType("enigma", new MediaType("text", "enigma")); assertThat(sc.getMimeType("filename.enigma")).isEqualTo("text/enigma"); } @Test - public void servletVersion() { + void servletVersion() { assertThat(sc.getMajorVersion()).isEqualTo(3); assertThat(sc.getMinorVersion()).isEqualTo(1); assertThat(sc.getEffectiveMajorVersion()).isEqualTo(3); @@ -109,7 +109,7 @@ public class MockServletContextTests { } @Test - public void registerAndUnregisterNamedDispatcher() throws Exception { + void registerAndUnregisterNamedDispatcher() throws Exception { final String name = "test-servlet"; final String url = "/test"; assertThat(sc.getNamedDispatcher(name)).isNull(); @@ -126,7 +126,7 @@ public class MockServletContextTests { } @Test - public void getNamedDispatcherForDefaultServlet() throws Exception { + void getNamedDispatcherForDefaultServlet() throws Exception { final String name = "default"; RequestDispatcher namedDispatcher = sc.getNamedDispatcher(name); assertThat(namedDispatcher).isNotNull(); @@ -137,7 +137,7 @@ public class MockServletContextTests { } @Test - public void setDefaultServletName() throws Exception { + void setDefaultServletName() throws Exception { final String originalDefault = "default"; final String newDefault = "test"; assertThat(sc.getNamedDispatcher(originalDefault)).isNotNull(); @@ -157,7 +157,7 @@ public class MockServletContextTests { * @since 4.1.2 */ @Test - public void getServletRegistration() { + void getServletRegistration() { assertThat(sc.getServletRegistration("servlet")).isNull(); } @@ -165,7 +165,7 @@ public class MockServletContextTests { * @since 4.1.2 */ @Test - public void getServletRegistrations() { + void getServletRegistrations() { Map servletRegistrations = sc.getServletRegistrations(); assertThat(servletRegistrations).isNotNull(); assertThat(servletRegistrations.size()).isEqualTo(0); @@ -175,7 +175,7 @@ public class MockServletContextTests { * @since 4.1.2 */ @Test - public void getFilterRegistration() { + void getFilterRegistration() { assertThat(sc.getFilterRegistration("filter")).isNull(); } @@ -183,7 +183,7 @@ public class MockServletContextTests { * @since 4.1.2 */ @Test - public void getFilterRegistrations() { + void getFilterRegistrations() { Map filterRegistrations = sc.getFilterRegistrations(); assertThat(filterRegistrations).isNotNull(); assertThat(filterRegistrations.size()).isEqualTo(0); diff --git a/spring-test/src/test/java/org/springframework/test/annotation/ProfileValueUtilsTests.java b/spring-test/src/test/java/org/springframework/test/annotation/ProfileValueUtilsTests.java index 0e55bf94e6..2c2700d5e9 100644 --- a/spring-test/src/test/java/org/springframework/test/annotation/ProfileValueUtilsTests.java +++ b/spring-test/src/test/java/org/springframework/test/annotation/ProfileValueUtilsTests.java @@ -20,8 +20,8 @@ import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.reflect.Method; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; @@ -31,7 +31,7 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Sam Brannen * @since 3.0 */ -public class ProfileValueUtilsTests { +class ProfileValueUtilsTests { private static final String NON_ANNOTATED_METHOD = "nonAnnotatedMethod"; private static final String ENABLED_ANNOTATED_METHOD = "enabledAnnotatedMethod"; @@ -41,8 +41,8 @@ public class ProfileValueUtilsTests { private static final String VALUE = "enigma"; - @BeforeClass - public static void setProfileValue() { + @BeforeAll + static void setProfileValue() { System.setProperty(NAME, VALUE); } @@ -81,7 +81,7 @@ public class ProfileValueUtilsTests { // ------------------------------------------------------------------- @Test - public void isTestEnabledInThisEnvironmentForProvidedClass() throws Exception { + void isTestEnabledInThisEnvironmentForProvidedClass() throws Exception { assertClassIsEnabled(NonAnnotated.class); assertClassIsEnabled(EnabledAnnotatedSingleValue.class); assertClassIsEnabled(EnabledAnnotatedMultiValue.class); @@ -97,7 +97,7 @@ public class ProfileValueUtilsTests { } @Test - public void isTestEnabledInThisEnvironmentForProvidedMethodAndClass() throws Exception { + void isTestEnabledInThisEnvironmentForProvidedMethodAndClass() throws Exception { assertMethodIsEnabled(NON_ANNOTATED_METHOD, NonAnnotated.class); assertMethodIsEnabled(NON_ANNOTATED_METHOD, EnabledAnnotatedSingleValue.class); @@ -129,7 +129,7 @@ public class ProfileValueUtilsTests { } @Test - public void isTestEnabledInThisEnvironmentForProvidedProfileValueSourceMethodAndClass() throws Exception { + void isTestEnabledInThisEnvironmentForProvidedProfileValueSourceMethodAndClass() throws Exception { ProfileValueSource profileValueSource = SystemProfileValueSource.getInstance(); diff --git a/spring-test/src/test/java/org/springframework/test/context/BootstrapUtilsTests.java b/spring-test/src/test/java/org/springframework/test/context/BootstrapUtilsTests.java index 132a0ab70e..b2cca6ae2a 100644 --- a/spring-test/src/test/java/org/springframework/test/context/BootstrapUtilsTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/BootstrapUtilsTests.java @@ -19,7 +19,7 @@ package org.springframework.test.context; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.test.context.support.DefaultTestContextBootstrapper; import org.springframework.test.context.web.WebAppConfiguration; @@ -37,12 +37,12 @@ import static org.springframework.test.context.BootstrapUtils.resolveTestContext * @author Phillip Webb * @since 4.2 */ -public class BootstrapUtilsTests { +class BootstrapUtilsTests { private final CacheAwareContextLoaderDelegate delegate = mock(CacheAwareContextLoaderDelegate.class); @Test - public void resolveTestContextBootstrapperWithEmptyBootstrapWithAnnotation() { + void resolveTestContextBootstrapperWithEmptyBootstrapWithAnnotation() { BootstrapContext bootstrapContext = BootstrapTestUtils.buildBootstrapContext(EmptyBootstrapWithAnnotationClass.class, delegate); assertThatIllegalStateException().isThrownBy(() -> resolveTestContextBootstrapper(bootstrapContext)) @@ -50,7 +50,7 @@ public class BootstrapUtilsTests { } @Test - public void resolveTestContextBootstrapperWithDoubleMetaBootstrapWithAnnotations() { + void resolveTestContextBootstrapperWithDoubleMetaBootstrapWithAnnotations() { BootstrapContext bootstrapContext = BootstrapTestUtils.buildBootstrapContext( DoubleMetaAnnotatedBootstrapWithAnnotationClass.class, delegate); assertThatIllegalStateException().isThrownBy(() -> @@ -61,32 +61,32 @@ public class BootstrapUtilsTests { } @Test - public void resolveTestContextBootstrapperForNonAnnotatedClass() { + void resolveTestContextBootstrapperForNonAnnotatedClass() { assertBootstrapper(NonAnnotatedClass.class, DefaultTestContextBootstrapper.class); } @Test - public void resolveTestContextBootstrapperForWebAppConfigurationAnnotatedClass() { + void resolveTestContextBootstrapperForWebAppConfigurationAnnotatedClass() { assertBootstrapper(WebAppConfigurationAnnotatedClass.class, WebTestContextBootstrapper.class); } @Test - public void resolveTestContextBootstrapperWithDirectBootstrapWithAnnotation() { + void resolveTestContextBootstrapperWithDirectBootstrapWithAnnotation() { assertBootstrapper(DirectBootstrapWithAnnotationClass.class, FooBootstrapper.class); } @Test - public void resolveTestContextBootstrapperWithInheritedBootstrapWithAnnotation() { + void resolveTestContextBootstrapperWithInheritedBootstrapWithAnnotation() { assertBootstrapper(InheritedBootstrapWithAnnotationClass.class, FooBootstrapper.class); } @Test - public void resolveTestContextBootstrapperWithMetaBootstrapWithAnnotation() { + void resolveTestContextBootstrapperWithMetaBootstrapWithAnnotation() { assertBootstrapper(MetaAnnotatedBootstrapWithAnnotationClass.class, BarBootstrapper.class); } @Test - public void resolveTestContextBootstrapperWithDuplicatingMetaBootstrapWithAnnotations() { + void resolveTestContextBootstrapperWithDuplicatingMetaBootstrapWithAnnotations() { assertBootstrapper(DuplicateMetaAnnotatedBootstrapWithAnnotationClass.class, FooBootstrapper.class); } @@ -94,7 +94,7 @@ public class BootstrapUtilsTests { * @since 5.1 */ @Test - public void resolveTestContextBootstrapperWithLocalDeclarationThatOverridesMetaBootstrapWithAnnotations() { + void resolveTestContextBootstrapperWithLocalDeclarationThatOverridesMetaBootstrapWithAnnotations() { assertBootstrapper(LocalDeclarationAndMetaAnnotatedBootstrapWithAnnotationClass.class, EnigmaBootstrapper.class); } diff --git a/spring-test/src/test/java/org/springframework/test/context/ContextHierarchyDirtiesContextTests.java b/spring-test/src/test/java/org/springframework/test/context/ContextHierarchyDirtiesContextTests.java index 446da181d3..7ca80b0a46 100644 --- a/spring-test/src/test/java/org/springframework/test/context/ContextHierarchyDirtiesContextTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/ContextHierarchyDirtiesContextTests.java @@ -16,13 +16,13 @@ package org.springframework.test.context; -import org.junit.After; -import org.junit.FixMethodOrder; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.MethodOrderer; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestMethodOrder; import org.junit.runner.JUnitCore; import org.junit.runner.Result; import org.junit.runner.RunWith; -import org.junit.runners.MethodSorters; import org.springframework.beans.BeansException; import org.springframework.context.ApplicationContext; @@ -32,7 +32,7 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.annotation.DirtiesContext.HierarchyMode; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit4.SpringRunner; import static org.assertj.core.api.Assertions.assertThat; @@ -44,8 +44,8 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Tadaya Tsuyukubo * @since 3.2.2 */ -@FixMethodOrder(MethodSorters.NAME_ASCENDING) -public class ContextHierarchyDirtiesContextTests { +@TestMethodOrder(MethodOrderer.Alphanumeric.class) +class ContextHierarchyDirtiesContextTests { private static ApplicationContext context; @@ -56,8 +56,8 @@ public class ContextHierarchyDirtiesContextTests { private static String baz; - @After - public void cleanUp() { + @AfterEach + void cleanUp() { ContextHierarchyDirtiesContextTests.context = null; ContextHierarchyDirtiesContextTests.foo = null; ContextHierarchyDirtiesContextTests.bar = null; @@ -65,22 +65,22 @@ public class ContextHierarchyDirtiesContextTests { } @Test - public void classLevelDirtiesContextWithCurrentLevelHierarchyMode() { + void classLevelDirtiesContextWithCurrentLevelHierarchyMode() { runTestAndVerifyHierarchies(ClassLevelDirtiesContextWithCurrentLevelModeTestCase.class, true, true, false); } @Test - public void classLevelDirtiesContextWithExhaustiveHierarchyMode() { + void classLevelDirtiesContextWithExhaustiveHierarchyMode() { runTestAndVerifyHierarchies(ClassLevelDirtiesContextWithExhaustiveModeTestCase.class, false, false, false); } @Test - public void methodLevelDirtiesContextWithCurrentLevelHierarchyMode() { + void methodLevelDirtiesContextWithCurrentLevelHierarchyMode() { runTestAndVerifyHierarchies(MethodLevelDirtiesContextWithCurrentLevelModeTestCase.class, true, true, false); } @Test - public void methodLevelDirtiesContextWithExhaustiveHierarchyMode() { + void methodLevelDirtiesContextWithExhaustiveHierarchyMode() { runTestAndVerifyHierarchies(MethodLevelDirtiesContextWithExhaustiveModeTestCase.class, false, false, false); } @@ -111,7 +111,7 @@ public class ContextHierarchyDirtiesContextTests { // ------------------------------------------------------------------------- - @RunWith(SpringJUnit4ClassRunner.class) + @RunWith(SpringRunner.class) @ContextHierarchy(@ContextConfiguration(name = "foo")) static abstract class FooTestCase implements ApplicationContextAware { @@ -119,7 +119,7 @@ public class ContextHierarchyDirtiesContextTests { static class Config { @Bean - public String bean() { + String bean() { return "foo"; } } @@ -140,7 +140,7 @@ public class ContextHierarchyDirtiesContextTests { static class Config { @Bean - public String bean() { + String bean() { return "bar"; } } @@ -153,7 +153,7 @@ public class ContextHierarchyDirtiesContextTests { static class Config { @Bean - public String bean() { + String bean() { return "baz"; } } @@ -172,7 +172,7 @@ public class ContextHierarchyDirtiesContextTests { @DirtiesContext public static class ClassLevelDirtiesContextWithExhaustiveModeTestCase extends BazTestCase { - @Test + @org.junit.Test public void test() { } } @@ -186,7 +186,7 @@ public class ContextHierarchyDirtiesContextTests { @DirtiesContext(hierarchyMode = HierarchyMode.CURRENT_LEVEL) public static class ClassLevelDirtiesContextWithCurrentLevelModeTestCase extends BazTestCase { - @Test + @org.junit.Test public void test() { } } @@ -201,7 +201,7 @@ public class ContextHierarchyDirtiesContextTests { */ public static class MethodLevelDirtiesContextWithExhaustiveModeTestCase extends BazTestCase { - @Test + @org.junit.Test @DirtiesContext public void test() { } @@ -215,7 +215,7 @@ public class ContextHierarchyDirtiesContextTests { */ public static class MethodLevelDirtiesContextWithCurrentLevelModeTestCase extends BazTestCase { - @Test + @org.junit.Test @DirtiesContext(hierarchyMode = HierarchyMode.CURRENT_LEVEL) public void test() { } diff --git a/spring-test/src/test/java/org/springframework/test/context/MergedContextConfigurationTests.java b/spring-test/src/test/java/org/springframework/test/context/MergedContextConfigurationTests.java index 90e76ca2ed..85020c7b13 100644 --- a/spring-test/src/test/java/org/springframework/test/context/MergedContextConfigurationTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/MergedContextConfigurationTests.java @@ -20,7 +20,7 @@ import java.util.Collections; import java.util.HashSet; import java.util.Set; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.context.ApplicationContextInitializer; import org.springframework.context.support.GenericApplicationContext; @@ -41,7 +41,7 @@ import static org.mockito.Mockito.mock; * @author Phillip Webb * @since 3.1 */ -public class MergedContextConfigurationTests { +class MergedContextConfigurationTests { private static final String[] EMPTY_STRING_ARRAY = new String[0]; @@ -52,21 +52,21 @@ public class MergedContextConfigurationTests { @Test - public void hashCodeWithNulls() { + void hashCodeWithNulls() { MergedContextConfiguration mergedConfig1 = new MergedContextConfiguration(null, null, null, null, null); MergedContextConfiguration mergedConfig2 = new MergedContextConfiguration(null, null, null, null, null); assertThat(mergedConfig2.hashCode()).isEqualTo(mergedConfig1.hashCode()); } @Test - public void hashCodeWithNullArrays() { + void hashCodeWithNullArrays() { MergedContextConfiguration mergedConfig1 = new MergedContextConfiguration(getClass(), null, null, null, loader); MergedContextConfiguration mergedConfig2 = new MergedContextConfiguration(getClass(), null, null, null, loader); assertThat(mergedConfig2.hashCode()).isEqualTo(mergedConfig1.hashCode()); } @Test - public void hashCodeWithEmptyArrays() { + void hashCodeWithEmptyArrays() { MergedContextConfiguration mergedConfig1 = new MergedContextConfiguration(getClass(), EMPTY_STRING_ARRAY, EMPTY_CLASS_ARRAY, EMPTY_STRING_ARRAY, loader); MergedContextConfiguration mergedConfig2 = new MergedContextConfiguration(getClass(), @@ -75,7 +75,7 @@ public class MergedContextConfigurationTests { } @Test - public void hashCodeWithEmptyArraysAndDifferentLoaders() { + void hashCodeWithEmptyArraysAndDifferentLoaders() { MergedContextConfiguration mergedConfig1 = new MergedContextConfiguration(getClass(), EMPTY_STRING_ARRAY, EMPTY_CLASS_ARRAY, EMPTY_STRING_ARRAY, loader); MergedContextConfiguration mergedConfig2 = new MergedContextConfiguration(getClass(), @@ -84,7 +84,7 @@ public class MergedContextConfigurationTests { } @Test - public void hashCodeWithSameLocations() { + void hashCodeWithSameLocations() { String[] locations = new String[] { "foo", "bar}" }; MergedContextConfiguration mergedConfig1 = new MergedContextConfiguration(getClass(), locations, EMPTY_CLASS_ARRAY, EMPTY_STRING_ARRAY, loader); @@ -94,7 +94,7 @@ public class MergedContextConfigurationTests { } @Test - public void hashCodeWithDifferentLocations() { + void hashCodeWithDifferentLocations() { String[] locations1 = new String[] { "foo", "bar}" }; String[] locations2 = new String[] { "baz", "quux}" }; MergedContextConfiguration mergedConfig1 = new MergedContextConfiguration(getClass(), locations1, @@ -105,7 +105,7 @@ public class MergedContextConfigurationTests { } @Test - public void hashCodeWithSameConfigClasses() { + void hashCodeWithSameConfigClasses() { Class[] classes = new Class[] { String.class, Integer.class }; MergedContextConfiguration mergedConfig1 = new MergedContextConfiguration(getClass(), EMPTY_STRING_ARRAY, classes, EMPTY_STRING_ARRAY, loader); @@ -115,7 +115,7 @@ public class MergedContextConfigurationTests { } @Test - public void hashCodeWithDifferentConfigClasses() { + void hashCodeWithDifferentConfigClasses() { Class[] classes1 = new Class[] { String.class, Integer.class }; Class[] classes2 = new Class[] { Boolean.class, Number.class }; MergedContextConfiguration mergedConfig1 = new MergedContextConfiguration(getClass(), @@ -126,7 +126,7 @@ public class MergedContextConfigurationTests { } @Test - public void hashCodeWithSameProfiles() { + void hashCodeWithSameProfiles() { String[] activeProfiles = new String[] { "catbert", "dogbert" }; MergedContextConfiguration mergedConfig1 = new MergedContextConfiguration(getClass(), EMPTY_STRING_ARRAY, EMPTY_CLASS_ARRAY, activeProfiles, loader); @@ -136,7 +136,7 @@ public class MergedContextConfigurationTests { } @Test - public void hashCodeWithSameProfilesReversed() { + void hashCodeWithSameProfilesReversed() { String[] activeProfiles1 = new String[] { "catbert", "dogbert" }; String[] activeProfiles2 = new String[] { "dogbert", "catbert" }; MergedContextConfiguration mergedConfig1 = new MergedContextConfiguration(getClass(), @@ -147,7 +147,7 @@ public class MergedContextConfigurationTests { } @Test - public void hashCodeWithSameDuplicateProfiles() { + void hashCodeWithSameDuplicateProfiles() { String[] activeProfiles1 = new String[] { "catbert", "dogbert" }; String[] activeProfiles2 = new String[] { "catbert", "dogbert", "catbert", "dogbert", "catbert" }; MergedContextConfiguration mergedConfig1 = new MergedContextConfiguration(getClass(), @@ -158,7 +158,7 @@ public class MergedContextConfigurationTests { } @Test - public void hashCodeWithDifferentProfiles() { + void hashCodeWithDifferentProfiles() { String[] activeProfiles1 = new String[] { "catbert", "dogbert" }; String[] activeProfiles2 = new String[] { "X", "Y" }; MergedContextConfiguration mergedConfig1 = new MergedContextConfiguration(getClass(), @@ -169,7 +169,7 @@ public class MergedContextConfigurationTests { } @Test - public void hashCodeWithSameInitializers() { + void hashCodeWithSameInitializers() { Set>> initializerClasses1 = new HashSet<>(); initializerClasses1.add(FooInitializer.class); @@ -188,7 +188,7 @@ public class MergedContextConfigurationTests { } @Test - public void hashCodeWithDifferentInitializers() { + void hashCodeWithDifferentInitializers() { Set>> initializerClasses1 = new HashSet<>(); initializerClasses1.add(FooInitializer.class); @@ -208,7 +208,7 @@ public class MergedContextConfigurationTests { * @since 3.2.2 */ @Test - public void hashCodeWithSameParent() { + void hashCodeWithSameParent() { MergedContextConfiguration parent = new MergedContextConfiguration(getClass(), new String[] { "foo", "bar}" }, EMPTY_CLASS_ARRAY, EMPTY_STRING_ARRAY, loader); @@ -223,7 +223,7 @@ public class MergedContextConfigurationTests { * @since 3.2.2 */ @Test - public void hashCodeWithDifferentParents() { + void hashCodeWithDifferentParents() { MergedContextConfiguration parent1 = new MergedContextConfiguration(getClass(), new String[] { "foo", "bar}" }, EMPTY_CLASS_ARRAY, EMPTY_STRING_ARRAY, loader); MergedContextConfiguration parent2 = new MergedContextConfiguration(getClass(), new String[] { "baz", "quux" }, @@ -237,7 +237,7 @@ public class MergedContextConfigurationTests { } @Test - public void equalsBasics() { + void equalsBasics() { MergedContextConfiguration mergedConfig = new MergedContextConfiguration(null, null, null, null, null); assertThat(mergedConfig).isEqualTo(mergedConfig); assertThat(mergedConfig).isNotEqualTo(null); @@ -245,21 +245,21 @@ public class MergedContextConfigurationTests { } @Test - public void equalsWithNulls() { + void equalsWithNulls() { MergedContextConfiguration mergedConfig1 = new MergedContextConfiguration(null, null, null, null, null); MergedContextConfiguration mergedConfig2 = new MergedContextConfiguration(null, null, null, null, null); assertThat(mergedConfig2).isEqualTo(mergedConfig1); } @Test - public void equalsWithNullArrays() { + void equalsWithNullArrays() { MergedContextConfiguration mergedConfig1 = new MergedContextConfiguration(getClass(), null, null, null, loader); MergedContextConfiguration mergedConfig2 = new MergedContextConfiguration(getClass(), null, null, null, loader); assertThat(mergedConfig2).isEqualTo(mergedConfig1); } @Test - public void equalsWithEmptyArrays() { + void equalsWithEmptyArrays() { MergedContextConfiguration mergedConfig1 = new MergedContextConfiguration(getClass(), EMPTY_STRING_ARRAY, EMPTY_CLASS_ARRAY, EMPTY_STRING_ARRAY, loader); MergedContextConfiguration mergedConfig2 = new MergedContextConfiguration(getClass(), @@ -268,7 +268,7 @@ public class MergedContextConfigurationTests { } @Test - public void equalsWithEmptyArraysAndDifferentLoaders() { + void equalsWithEmptyArraysAndDifferentLoaders() { MergedContextConfiguration mergedConfig1 = new MergedContextConfiguration(getClass(), EMPTY_STRING_ARRAY, EMPTY_CLASS_ARRAY, EMPTY_STRING_ARRAY, loader); MergedContextConfiguration mergedConfig2 = new MergedContextConfiguration(getClass(), @@ -278,7 +278,7 @@ public class MergedContextConfigurationTests { } @Test - public void equalsWithSameLocations() { + void equalsWithSameLocations() { String[] locations = new String[] { "foo", "bar}" }; MergedContextConfiguration mergedConfig1 = new MergedContextConfiguration(getClass(), locations, EMPTY_CLASS_ARRAY, EMPTY_STRING_ARRAY, loader); @@ -288,7 +288,7 @@ public class MergedContextConfigurationTests { } @Test - public void equalsWithDifferentLocations() { + void equalsWithDifferentLocations() { String[] locations1 = new String[] { "foo", "bar}" }; String[] locations2 = new String[] { "baz", "quux}" }; MergedContextConfiguration mergedConfig1 = new MergedContextConfiguration(getClass(), @@ -300,7 +300,7 @@ public class MergedContextConfigurationTests { } @Test - public void equalsWithSameConfigClasses() { + void equalsWithSameConfigClasses() { Class[] classes = new Class[] { String.class, Integer.class }; MergedContextConfiguration mergedConfig1 = new MergedContextConfiguration(getClass(), EMPTY_STRING_ARRAY, classes, EMPTY_STRING_ARRAY, loader); @@ -310,7 +310,7 @@ public class MergedContextConfigurationTests { } @Test - public void equalsWithDifferentConfigClasses() { + void equalsWithDifferentConfigClasses() { Class[] classes1 = new Class[] { String.class, Integer.class }; Class[] classes2 = new Class[] { Boolean.class, Number.class }; MergedContextConfiguration mergedConfig1 = new MergedContextConfiguration(getClass(), @@ -322,7 +322,7 @@ public class MergedContextConfigurationTests { } @Test - public void equalsWithSameProfiles() { + void equalsWithSameProfiles() { String[] activeProfiles = new String[] { "catbert", "dogbert" }; MergedContextConfiguration mergedConfig1 = new MergedContextConfiguration(getClass(), EMPTY_STRING_ARRAY, EMPTY_CLASS_ARRAY, activeProfiles, loader); @@ -332,7 +332,7 @@ public class MergedContextConfigurationTests { } @Test - public void equalsWithSameProfilesReversed() { + void equalsWithSameProfilesReversed() { String[] activeProfiles1 = new String[] { "catbert", "dogbert" }; String[] activeProfiles2 = new String[] { "dogbert", "catbert" }; MergedContextConfiguration mergedConfig1 = new MergedContextConfiguration(getClass(), @@ -343,7 +343,7 @@ public class MergedContextConfigurationTests { } @Test - public void equalsWithSameDuplicateProfiles() { + void equalsWithSameDuplicateProfiles() { String[] activeProfiles1 = new String[] { "catbert", "dogbert" }; String[] activeProfiles2 = new String[] { "catbert", "dogbert", "catbert", "dogbert", "catbert" }; MergedContextConfiguration mergedConfig1 = new MergedContextConfiguration(getClass(), @@ -354,7 +354,7 @@ public class MergedContextConfigurationTests { } @Test - public void equalsWithDifferentProfiles() { + void equalsWithDifferentProfiles() { String[] activeProfiles1 = new String[] { "catbert", "dogbert" }; String[] activeProfiles2 = new String[] { "X", "Y" }; MergedContextConfiguration mergedConfig1 = new MergedContextConfiguration(getClass(), @@ -366,7 +366,7 @@ public class MergedContextConfigurationTests { } @Test - public void equalsWithSameInitializers() { + void equalsWithSameInitializers() { Set>> initializerClasses1 = new HashSet<>(); initializerClasses1.add(FooInitializer.class); @@ -385,7 +385,7 @@ public class MergedContextConfigurationTests { } @Test - public void equalsWithDifferentInitializers() { + void equalsWithDifferentInitializers() { Set>> initializerClasses1 = new HashSet<>(); initializerClasses1.add(FooInitializer.class); @@ -406,7 +406,7 @@ public class MergedContextConfigurationTests { * @since 4.3 */ @Test - public void equalsWithSameContextCustomizers() { + void equalsWithSameContextCustomizers() { Set customizers = Collections.singleton(mock(ContextCustomizer.class)); MergedContextConfiguration mergedConfig1 = new MergedContextConfiguration(getClass(), EMPTY_STRING_ARRAY, EMPTY_CLASS_ARRAY, null, EMPTY_STRING_ARRAY, null, null, customizers, loader, null, null); @@ -419,7 +419,7 @@ public class MergedContextConfigurationTests { * @since 4.3 */ @Test - public void equalsWithDifferentContextCustomizers() { + void equalsWithDifferentContextCustomizers() { Set customizers1 = Collections.singleton(mock(ContextCustomizer.class)); Set customizers2 = Collections.singleton(mock(ContextCustomizer.class)); @@ -435,7 +435,7 @@ public class MergedContextConfigurationTests { * @since 3.2.2 */ @Test - public void equalsWithSameParent() { + void equalsWithSameParent() { MergedContextConfiguration parent = new MergedContextConfiguration(getClass(), new String[] { "foo", "bar}" }, EMPTY_CLASS_ARRAY, EMPTY_STRING_ARRAY, loader); @@ -451,7 +451,7 @@ public class MergedContextConfigurationTests { * @since 3.2.2 */ @Test - public void equalsWithDifferentParents() { + void equalsWithDifferentParents() { MergedContextConfiguration parent1 = new MergedContextConfiguration(getClass(), new String[] { "foo", "bar}" }, EMPTY_CLASS_ARRAY, EMPTY_STRING_ARRAY, loader); MergedContextConfiguration parent2 = new MergedContextConfiguration(getClass(), new String[] { "baz", "quux" }, diff --git a/spring-test/src/test/java/org/springframework/test/context/TestContextConcurrencyTests.java b/spring-test/src/test/java/org/springframework/test/context/TestContextConcurrencyTests.java index c4b7d5f771..80548d015c 100644 --- a/spring-test/src/test/java/org/springframework/test/context/TestContextConcurrencyTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/TestContextConcurrencyTests.java @@ -22,7 +22,7 @@ import java.util.Set; import java.util.TreeSet; import java.util.stream.IntStream; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static java.util.Arrays.stream; import static java.util.stream.Collectors.toCollection; @@ -41,10 +41,11 @@ import static org.assertj.core.api.Assertions.assertThat; * @since 5.0 * @see org.springframework.test.context.junit4.concurrency.SpringJUnit4ConcurrencyTests */ -public class TestContextConcurrencyTests { +class TestContextConcurrencyTests { - private static Set expectedMethods = stream(TestCase.class.getDeclaredMethods()).map( - Method::getName).collect(toCollection(TreeSet::new)); + private static Set expectedMethods = stream(TestCase.class.getDeclaredMethods()) + .map(Method::getName) + .collect(toCollection(TreeSet::new)); private static final Set actualMethods = Collections.synchronizedSet(new TreeSet<>()); @@ -52,7 +53,7 @@ public class TestContextConcurrencyTests { @Test - public void invokeTestContextManagerFromConcurrentThreads() { + void invokeTestContextManagerFromConcurrentThreads() { TestContextManager tcm = new TestContextManager(TestCase.class); // Run the actual test several times in order to increase the chance of threads diff --git a/spring-test/src/test/java/org/springframework/test/context/TestContextManagerSuppressedExceptionsTests.java b/spring-test/src/test/java/org/springframework/test/context/TestContextManagerSuppressedExceptionsTests.java index 934f7ddee5..6b6396bd13 100644 --- a/spring-test/src/test/java/org/springframework/test/context/TestContextManagerSuppressedExceptionsTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/TestContextManagerSuppressedExceptionsTests.java @@ -18,7 +18,7 @@ package org.springframework.test.context; import java.lang.reflect.Method; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatExceptionOfType; @@ -33,22 +33,22 @@ import static org.assertj.core.api.Assertions.fail; * @since 5.0 * @see Throwable#getSuppressed() */ -public class TestContextManagerSuppressedExceptionsTests { +class TestContextManagerSuppressedExceptionsTests { @Test - public void afterTestExecution() throws Exception { + void afterTestExecution() throws Exception { test("afterTestExecution", FailingAfterTestExecutionTestCase.class, (tcm, c, m) -> tcm.afterTestExecution(this, m, null)); } @Test - public void afterTestMethod() throws Exception { + void afterTestMethod() throws Exception { test("afterTestMethod", FailingAfterTestMethodTestCase.class, (tcm, c, m) -> tcm.afterTestMethod(this, m, null)); } @Test - public void afterTestClass() throws Exception { + void afterTestClass() throws Exception { test("afterTestClass", FailingAfterTestClassTestCase.class, (tcm, c, m) -> tcm.afterTestClass()); } diff --git a/spring-test/src/test/java/org/springframework/test/context/TestContextManagerTests.java b/spring-test/src/test/java/org/springframework/test/context/TestContextManagerTests.java index cfdb2314a5..c61ad4ab8d 100644 --- a/spring-test/src/test/java/org/springframework/test/context/TestContextManagerTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/TestContextManagerTests.java @@ -21,7 +21,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; @@ -33,7 +33,7 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Sam Brannen * @since 2.5 */ -public class TestContextManagerTests { +class TestContextManagerTests { private static final List executionOrder = new ArrayList<>(); @@ -51,7 +51,7 @@ public class TestContextManagerTests { @Test - public void listenerExecutionOrder() throws Exception { + void listenerExecutionOrder() throws Exception { // @formatter:off assertThat(this.testContextManager.getTestExecutionListeners().size()).as("Registered TestExecutionListeners").isEqualTo(3); @@ -121,7 +121,7 @@ public class TestContextManagerTests { private final String name; - public NamedTestExecutionListener(String name) { + NamedTestExecutionListener(String name) { this.name = name; } diff --git a/spring-test/src/test/java/org/springframework/test/context/TestExecutionListenersTests.java b/spring-test/src/test/java/org/springframework/test/context/TestExecutionListenersTests.java index af0a3b14db..768b582351 100644 --- a/spring-test/src/test/java/org/springframework/test/context/TestExecutionListenersTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/TestExecutionListenersTests.java @@ -20,7 +20,7 @@ import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.util.List; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.core.Ordered; import org.springframework.core.annotation.AnnotationConfigurationException; @@ -52,10 +52,10 @@ import static org.springframework.test.context.TestExecutionListeners.MergeMode. * @author Sam Brannen * @since 2.5 */ -public class TestExecutionListenersTests { +class TestExecutionListenersTests { @Test - public void defaultListeners() { + void defaultListeners() { List> expected = asList(ServletTestExecutionListener.class, DirtiesContextBeforeModesTestExecutionListener.class, DependencyInjectionTestExecutionListener.class, DirtiesContextTestExecutionListener.class, TransactionalTestExecutionListener.class, @@ -67,7 +67,7 @@ public class TestExecutionListenersTests { * @since 4.1 */ @Test - public void defaultListenersMergedWithCustomListenerPrepended() { + void defaultListenersMergedWithCustomListenerPrepended() { List> expected = asList(QuuxTestExecutionListener.class, ServletTestExecutionListener.class, DirtiesContextBeforeModesTestExecutionListener.class, DependencyInjectionTestExecutionListener.class, DirtiesContextTestExecutionListener.class, TransactionalTestExecutionListener.class, @@ -79,7 +79,7 @@ public class TestExecutionListenersTests { * @since 4.1 */ @Test - public void defaultListenersMergedWithCustomListenerAppended() { + void defaultListenersMergedWithCustomListenerAppended() { List> expected = asList(ServletTestExecutionListener.class, DirtiesContextBeforeModesTestExecutionListener.class, DependencyInjectionTestExecutionListener.class, DirtiesContextTestExecutionListener.class, TransactionalTestExecutionListener.class, @@ -92,7 +92,7 @@ public class TestExecutionListenersTests { * @since 4.1 */ @Test - public void defaultListenersMergedWithCustomListenerInserted() { + void defaultListenersMergedWithCustomListenerInserted() { List> expected = asList(ServletTestExecutionListener.class, DirtiesContextBeforeModesTestExecutionListener.class, DependencyInjectionTestExecutionListener.class, BarTestExecutionListener.class, DirtiesContextTestExecutionListener.class, @@ -102,12 +102,12 @@ public class TestExecutionListenersTests { } @Test - public void nonInheritedDefaultListeners() { + void nonInheritedDefaultListeners() { assertRegisteredListeners(NonInheritedDefaultListenersTestCase.class, asList(QuuxTestExecutionListener.class)); } @Test - public void inheritedDefaultListeners() { + void inheritedDefaultListeners() { assertRegisteredListeners(InheritedDefaultListenersTestCase.class, asList(QuuxTestExecutionListener.class)); assertRegisteredListeners(SubInheritedDefaultListenersTestCase.class, asList(QuuxTestExecutionListener.class)); assertRegisteredListeners(SubSubInheritedDefaultListenersTestCase.class, @@ -115,58 +115,58 @@ public class TestExecutionListenersTests { } @Test - public void customListeners() { + void customListeners() { assertNumRegisteredListeners(ExplicitListenersTestCase.class, 3); } @Test - public void customListenersDeclaredOnInterface() { + void customListenersDeclaredOnInterface() { assertRegisteredListeners(ExplicitListenersOnTestInterfaceTestCase.class, asList(FooTestExecutionListener.class, BarTestExecutionListener.class)); } @Test - public void nonInheritedListeners() { + void nonInheritedListeners() { assertNumRegisteredListeners(NonInheritedListenersTestCase.class, 1); } @Test - public void inheritedListeners() { + void inheritedListeners() { assertNumRegisteredListeners(InheritedListenersTestCase.class, 4); } @Test - public void customListenersRegisteredViaMetaAnnotation() { + void customListenersRegisteredViaMetaAnnotation() { assertNumRegisteredListeners(MetaTestCase.class, 3); } @Test - public void nonInheritedListenersRegisteredViaMetaAnnotation() { + void nonInheritedListenersRegisteredViaMetaAnnotation() { assertNumRegisteredListeners(MetaNonInheritedListenersTestCase.class, 1); } @Test - public void inheritedListenersRegisteredViaMetaAnnotation() { + void inheritedListenersRegisteredViaMetaAnnotation() { assertNumRegisteredListeners(MetaInheritedListenersTestCase.class, 4); } @Test - public void customListenersRegisteredViaMetaAnnotationWithOverrides() { + void customListenersRegisteredViaMetaAnnotationWithOverrides() { assertNumRegisteredListeners(MetaWithOverridesTestCase.class, 3); } @Test - public void customsListenersRegisteredViaMetaAnnotationWithInheritedListenersWithOverrides() { + void customsListenersRegisteredViaMetaAnnotationWithInheritedListenersWithOverrides() { assertNumRegisteredListeners(MetaInheritedListenersWithOverridesTestCase.class, 5); } @Test - public void customListenersRegisteredViaMetaAnnotationWithNonInheritedListenersWithOverrides() { + void customListenersRegisteredViaMetaAnnotationWithNonInheritedListenersWithOverrides() { assertNumRegisteredListeners(MetaNonInheritedListenersWithOverridesTestCase.class, 8); } @Test - public void listenersAndValueAttributesDeclared() { + void listenersAndValueAttributesDeclared() { assertThatExceptionOfType(AnnotationConfigurationException.class).isThrownBy(() -> new TestContextManager(DuplicateListenersConfigTestCase.class)); } diff --git a/spring-test/src/test/java/org/springframework/test/context/cache/ClassLevelDirtiesContextTestNGTests.java b/spring-test/src/test/java/org/springframework/test/context/cache/ClassLevelDirtiesContextTestNGTests.java index 63983a60af..c9cad8f854 100644 --- a/spring-test/src/test/java/org/springframework/test/context/cache/ClassLevelDirtiesContextTestNGTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/cache/ClassLevelDirtiesContextTestNGTests.java @@ -18,11 +18,9 @@ package org.springframework.test.context.cache; import java.util.concurrent.atomic.AtomicInteger; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import org.testng.ITestNGListener; import org.testng.TestNG; @@ -43,7 +41,7 @@ import static org.springframework.test.context.cache.ContextCacheTestUtils.asser import static org.springframework.test.context.cache.ContextCacheTestUtils.resetContextCache; /** - * JUnit 4 based integration test which verifies correct {@linkplain ContextCache + * JUnit based integration test which verifies correct {@linkplain ContextCache * application context caching} in conjunction with Spring's TestNG support * and {@link DirtiesContext @DirtiesContext} at the class level. * @@ -53,15 +51,14 @@ import static org.springframework.test.context.cache.ContextCacheTestUtils.reset * @author Sam Brannen * @since 4.2 */ -@RunWith(JUnit4.class) -public class ClassLevelDirtiesContextTestNGTests { +class ClassLevelDirtiesContextTestNGTests { private static final AtomicInteger cacheHits = new AtomicInteger(0); private static final AtomicInteger cacheMisses = new AtomicInteger(0); - @BeforeClass - public static void verifyInitialCacheState() { + @BeforeAll + static void verifyInitialCacheState() { resetContextCache(); // Reset static counters in case tests are run multiple times in a test suite -- // for example, via JUnit's @Suite. @@ -71,7 +68,7 @@ public class ClassLevelDirtiesContextTestNGTests { } @Test - public void verifyDirtiesContextBehavior() throws Exception { + void verifyDirtiesContextBehavior() throws Exception { assertBehaviorForCleanTestCase(); @@ -158,8 +155,8 @@ public class ClassLevelDirtiesContextTestNGTests { assertContextCacheStatistics("after clean test class", 1, cacheHits.get(), cacheMisses.incrementAndGet()); } - @AfterClass - public static void verifyFinalCacheState() { + @AfterAll + static void verifyFinalCacheState() { assertContextCacheStatistics("AfterClass", 0, cacheHits.get(), cacheMisses.get()); } diff --git a/spring-test/src/test/java/org/springframework/test/context/cache/ClassLevelDirtiesContextTests.java b/spring-test/src/test/java/org/springframework/test/context/cache/ClassLevelDirtiesContextTests.java index d0f86311f1..cdb78dff2f 100644 --- a/spring-test/src/test/java/org/springframework/test/context/cache/ClassLevelDirtiesContextTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/cache/ClassLevelDirtiesContextTests.java @@ -18,9 +18,9 @@ package org.springframework.test.context.cache; import java.util.concurrent.atomic.AtomicInteger; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; @@ -30,6 +30,7 @@ import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.annotation.DirtiesContext.ClassMode; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.TestExecutionListeners; +import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.context.support.DependencyInjectionTestExecutionListener; import org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener; @@ -41,21 +42,21 @@ import static org.springframework.test.context.cache.ContextCacheTestUtils.reset import static org.springframework.test.context.junit4.JUnitTestingUtils.runTestsAndAssertCounters; /** - * JUnit 4 based integration test which verifies correct {@linkplain ContextCache - * application context caching} in conjunction with the {@link SpringRunner} and + * JUnit based integration test which verifies correct {@linkplain ContextCache + * application context caching} in conjunction with the {@link SpringExtension} and * {@link DirtiesContext @DirtiesContext} at the class level. * * @author Sam Brannen * @since 3.0 */ -public class ClassLevelDirtiesContextTests { +class ClassLevelDirtiesContextTests { private static final AtomicInteger cacheHits = new AtomicInteger(0); private static final AtomicInteger cacheMisses = new AtomicInteger(0); - @BeforeClass - public static void verifyInitialCacheState() { + @BeforeAll + static void verifyInitialCacheState() { resetContextCache(); // Reset static counters in case tests are run multiple times in a test suite -- // for example, via JUnit's @Suite. @@ -65,7 +66,7 @@ public class ClassLevelDirtiesContextTests { } @Test - public void verifyDirtiesContextBehavior() throws Exception { + void verifyDirtiesContextBehavior() throws Exception { assertBehaviorForCleanTestCase(); @@ -139,8 +140,8 @@ public class ClassLevelDirtiesContextTests { assertContextCacheStatistics("after clean test class", 1, cacheHits.get(), cacheMisses.incrementAndGet()); } - @AfterClass - public static void verifyFinalCacheState() { + @AfterAll + static void verifyFinalCacheState() { assertContextCacheStatistics("AfterClass", 0, cacheHits.get(), cacheMisses.get()); } @@ -176,7 +177,7 @@ public class ClassLevelDirtiesContextTests { public static final class CleanTestCase extends BaseTestCase { - @Test + @org.junit.Test public void verifyContextWasAutowired() { assertApplicationContextWasAutowired(); } @@ -186,7 +187,7 @@ public class ClassLevelDirtiesContextTests { @DirtiesContext public static class ClassLevelDirtiesContextWithCleanMethodsAndDefaultModeTestCase extends BaseTestCase { - @Test + @org.junit.Test public void verifyContextWasAutowired() { assertApplicationContextWasAutowired(); } @@ -199,7 +200,7 @@ public class ClassLevelDirtiesContextTests { @DirtiesContext(classMode = ClassMode.AFTER_CLASS) public static class ClassLevelDirtiesContextWithCleanMethodsAndAfterClassModeTestCase extends BaseTestCase { - @Test + @org.junit.Test public void verifyContextWasAutowired() { assertApplicationContextWasAutowired(); } @@ -212,17 +213,17 @@ public class ClassLevelDirtiesContextTests { @DirtiesContext(classMode = ClassMode.AFTER_EACH_TEST_METHOD) public static class ClassLevelDirtiesContextWithAfterEachTestMethodModeTestCase extends BaseTestCase { - @Test + @org.junit.Test public void verifyContextWasAutowired1() { assertApplicationContextWasAutowired(); } - @Test + @org.junit.Test public void verifyContextWasAutowired2() { assertApplicationContextWasAutowired(); } - @Test + @org.junit.Test public void verifyContextWasAutowired3() { assertApplicationContextWasAutowired(); } @@ -235,7 +236,7 @@ public class ClassLevelDirtiesContextTests { @DirtiesContext public static class ClassLevelDirtiesContextWithDirtyMethodsTestCase extends BaseTestCase { - @Test + @org.junit.Test @DirtiesContext public void dirtyContext() { assertApplicationContextWasAutowired(); diff --git a/spring-test/src/test/java/org/springframework/test/context/cache/ContextCacheTests.java b/spring-test/src/test/java/org/springframework/test/context/cache/ContextCacheTests.java index 82b7aa1975..202af4bb4b 100644 --- a/spring-test/src/test/java/org/springframework/test/context/cache/ContextCacheTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/cache/ContextCacheTests.java @@ -16,8 +16,8 @@ package org.springframework.test.context.cache; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.Configuration; @@ -43,15 +43,15 @@ import static org.springframework.test.context.cache.ContextCacheTestUtils.asser * @author Michail Nikolaev * @since 3.1 * @see LruContextCacheTests - * @see SpringRunnerContextCacheTests + * @see SpringExtensionContextCacheTests */ -public class ContextCacheTests { +class ContextCacheTests { private ContextCache contextCache = new DefaultContextCache(); - @Before - public void initialCacheState() { + @BeforeEach + void initialCacheState() { assertContextCacheStatistics(contextCache, "initial state", 0, 0, 0); assertParentContextCount(0); } @@ -76,7 +76,7 @@ public class ContextCacheTests { } @Test - public void verifyCacheKeyIsBasedOnContextLoader() { + void verifyCacheKeyIsBasedOnContextLoader() { loadCtxAndAssertStats(AnnotationConfigContextLoaderTestCase.class, 1, 0, 1); loadCtxAndAssertStats(AnnotationConfigContextLoaderTestCase.class, 1, 1, 1); loadCtxAndAssertStats(CustomAnnotationConfigContextLoaderTestCase.class, 2, 1, 2); @@ -86,7 +86,7 @@ public class ContextCacheTests { } @Test - public void verifyCacheKeyIsBasedOnActiveProfiles() { + void verifyCacheKeyIsBasedOnActiveProfiles() { int size = 0, hit = 0, miss = 0; loadCtxAndAssertStats(FooBarProfilesTestCase.class, ++size, hit, ++miss); loadCtxAndAssertStats(FooBarProfilesTestCase.class, size, ++hit, miss); @@ -99,7 +99,7 @@ public class ContextCacheTests { } @Test - public void verifyCacheBehaviorForContextHierarchies() { + void verifyCacheBehaviorForContextHierarchies() { int size = 0; int hits = 0; int misses = 0; @@ -126,7 +126,7 @@ public class ContextCacheTests { } @Test - public void removeContextHierarchyCacheLevel1() { + void removeContextHierarchyCacheLevel1() { // Load Level 3-A TestContext testContext3a = TestContextTestUtils.buildTestContext( @@ -151,7 +151,7 @@ public class ContextCacheTests { } @Test - public void removeContextHierarchyCacheLevel1WithExhaustiveMode() { + void removeContextHierarchyCacheLevel1WithExhaustiveMode() { // Load Level 3-A TestContext testContext3a = TestContextTestUtils.buildTestContext( @@ -176,7 +176,7 @@ public class ContextCacheTests { } @Test - public void removeContextHierarchyCacheLevel2() { + void removeContextHierarchyCacheLevel2() { // Load Level 3-A TestContext testContext3a = TestContextTestUtils.buildTestContext( @@ -202,7 +202,7 @@ public class ContextCacheTests { } @Test - public void removeContextHierarchyCacheLevel2WithExhaustiveMode() { + void removeContextHierarchyCacheLevel2WithExhaustiveMode() { // Load Level 3-A TestContext testContext3a = TestContextTestUtils.buildTestContext( @@ -226,7 +226,7 @@ public class ContextCacheTests { } @Test - public void removeContextHierarchyCacheLevel3Then2() { + void removeContextHierarchyCacheLevel3Then2() { // Load Level 3-A TestContext testContext3a = TestContextTestUtils.buildTestContext( @@ -255,7 +255,7 @@ public class ContextCacheTests { } @Test - public void removeContextHierarchyCacheLevel3Then2WithExhaustiveMode() { + void removeContextHierarchyCacheLevel3Then2WithExhaustiveMode() { // Load Level 3-A TestContext testContext3a = TestContextTestUtils.buildTestContext( diff --git a/spring-test/src/test/java/org/springframework/test/context/cache/ContextCacheUtilsTests.java b/spring-test/src/test/java/org/springframework/test/context/cache/ContextCacheUtilsTests.java index 257f7710a8..c1eb5448ad 100644 --- a/spring-test/src/test/java/org/springframework/test/context/cache/ContextCacheUtilsTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/cache/ContextCacheUtilsTests.java @@ -16,9 +16,9 @@ package org.springframework.test.context.cache; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.core.SpringProperties; @@ -33,52 +33,52 @@ import static org.springframework.test.context.cache.ContextCacheUtils.retrieveM * @author Sam Brannen * @since 4.3 */ -public class ContextCacheUtilsTests { +class ContextCacheUtilsTests { - @Before - @After - public void clearProperties() { + @BeforeEach + @AfterEach + void clearProperties() { System.clearProperty(MAX_CONTEXT_CACHE_SIZE_PROPERTY_NAME); SpringProperties.setProperty(MAX_CONTEXT_CACHE_SIZE_PROPERTY_NAME, null); } @Test - public void retrieveMaxCacheSizeFromDefault() { + void retrieveMaxCacheSizeFromDefault() { assertDefaultValue(); } @Test - public void retrieveMaxCacheSizeFromBogusSystemProperty() { + void retrieveMaxCacheSizeFromBogusSystemProperty() { System.setProperty(MAX_CONTEXT_CACHE_SIZE_PROPERTY_NAME, "bogus"); assertDefaultValue(); } @Test - public void retrieveMaxCacheSizeFromBogusSpringProperty() { + void retrieveMaxCacheSizeFromBogusSpringProperty() { SpringProperties.setProperty(MAX_CONTEXT_CACHE_SIZE_PROPERTY_NAME, "bogus"); assertDefaultValue(); } @Test - public void retrieveMaxCacheSizeFromDecimalSpringProperty() { + void retrieveMaxCacheSizeFromDecimalSpringProperty() { SpringProperties.setProperty(MAX_CONTEXT_CACHE_SIZE_PROPERTY_NAME, "3.14"); assertDefaultValue(); } @Test - public void retrieveMaxCacheSizeFromSystemProperty() { + void retrieveMaxCacheSizeFromSystemProperty() { System.setProperty(MAX_CONTEXT_CACHE_SIZE_PROPERTY_NAME, "42"); assertThat(retrieveMaxCacheSize()).isEqualTo(42); } @Test - public void retrieveMaxCacheSizeFromSystemPropertyContainingWhitespace() { + void retrieveMaxCacheSizeFromSystemPropertyContainingWhitespace() { System.setProperty(MAX_CONTEXT_CACHE_SIZE_PROPERTY_NAME, "42\t"); assertThat(retrieveMaxCacheSize()).isEqualTo(42); } @Test - public void retrieveMaxCacheSizeFromSpringProperty() { + void retrieveMaxCacheSizeFromSpringProperty() { SpringProperties.setProperty(MAX_CONTEXT_CACHE_SIZE_PROPERTY_NAME, "99"); assertThat(retrieveMaxCacheSize()).isEqualTo(99); } diff --git a/spring-test/src/test/java/org/springframework/test/context/cache/LruContextCacheTests.java b/spring-test/src/test/java/org/springframework/test/context/cache/LruContextCacheTests.java index dd7c3e1858..a34d49c395 100644 --- a/spring-test/src/test/java/org/springframework/test/context/cache/LruContextCacheTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/cache/LruContextCacheTests.java @@ -19,7 +19,7 @@ package org.springframework.test.context.cache; import java.util.List; import java.util.Map; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.context.ApplicationContext; import org.springframework.context.ConfigurableApplicationContext; @@ -42,7 +42,7 @@ import static org.mockito.Mockito.verify; * @since 4.3 * @see ContextCacheTests */ -public class LruContextCacheTests { +class LruContextCacheTests { private static final MergedContextConfiguration abcConfig = config(Abc.class); private static final MergedContextConfiguration fooConfig = config(Foo.class); @@ -57,19 +57,17 @@ public class LruContextCacheTests { @Test - public void maxCacheSizeNegativeOne() { - assertThatIllegalArgumentException().isThrownBy(() -> - new DefaultContextCache(-1)); + void maxCacheSizeNegativeOne() { + assertThatIllegalArgumentException().isThrownBy(() -> new DefaultContextCache(-1)); } @Test - public void maxCacheSizeZero() { - assertThatIllegalArgumentException().isThrownBy(() -> - new DefaultContextCache(0)); + void maxCacheSizeZero() { + assertThatIllegalArgumentException().isThrownBy(() -> new DefaultContextCache(0)); } @Test - public void maxCacheSizeOne() { + void maxCacheSizeOne() { DefaultContextCache cache = new DefaultContextCache(1); assertThat(cache.size()).isEqualTo(0); assertThat(cache.getMaxSize()).isEqualTo(1); @@ -88,7 +86,7 @@ public class LruContextCacheTests { } @Test - public void maxCacheSizeThree() { + void maxCacheSizeThree() { DefaultContextCache cache = new DefaultContextCache(3); assertThat(cache.size()).isEqualTo(0); assertThat(cache.getMaxSize()).isEqualTo(3); @@ -110,7 +108,7 @@ public class LruContextCacheTests { } @Test - public void ensureLruOrderingIsUpdated() { + void ensureLruOrderingIsUpdated() { DefaultContextCache cache = new DefaultContextCache(3); // Note: when a new entry is added it is considered the MRU entry and inserted at the tail. @@ -134,7 +132,7 @@ public class LruContextCacheTests { } @Test - public void ensureEvictedContextsAreClosed() { + void ensureEvictedContextsAreClosed() { DefaultContextCache cache = new DefaultContextCache(2); cache.put(fooConfig, fooContext); diff --git a/spring-test/src/test/java/org/springframework/test/context/cache/MethodLevelDirtiesContextTests.java b/spring-test/src/test/java/org/springframework/test/context/cache/MethodLevelDirtiesContextTests.java index 4a2a7a893a..5781080cf1 100644 --- a/spring-test/src/test/java/org/springframework/test/context/cache/MethodLevelDirtiesContextTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/cache/MethodLevelDirtiesContextTests.java @@ -18,18 +18,17 @@ package org.springframework.test.context.cache; import java.util.concurrent.atomic.AtomicInteger; -import org.junit.FixMethodOrder; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.MethodSorters; +import org.junit.jupiter.api.MethodOrderer; +import org.junit.jupiter.api.Order; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestMethodOrder; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import org.springframework.test.context.support.DependencyInjectionTestExecutionListener; import org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener; import org.springframework.test.context.support.DirtiesContextTestExecutionListener; @@ -47,24 +46,13 @@ import static org.springframework.test.annotation.DirtiesContext.MethodMode.BEFO * @author Sam Brannen * @since 4.2 */ -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration -@FixMethodOrder(MethodSorters.NAME_ASCENDING) -public class MethodLevelDirtiesContextTests { +@SpringJUnitConfig +@TestMethodOrder(MethodOrderer.OrderAnnotation.class) +class MethodLevelDirtiesContextTests { private static final AtomicInteger contextCount = new AtomicInteger(); - @Configuration - static class Config { - - @Bean - Integer count() { - return contextCount.incrementAndGet(); - } - } - - @Autowired private ConfigurableApplicationContext context; @@ -73,28 +61,28 @@ public class MethodLevelDirtiesContextTests { @Test - // test## prefix required for @FixMethodOrder. - public void test01() throws Exception { + @Order(1) + void basics() throws Exception { performAssertions(1); } @Test + @Order(2) @DirtiesContext(methodMode = BEFORE_METHOD) - // test## prefix required for @FixMethodOrder. - public void test02_dirtyContextBeforeTestMethod() throws Exception { + void dirtyContextBeforeTestMethod() throws Exception { performAssertions(2); } @Test + @Order(3) @DirtiesContext - // test## prefix required for @FixMethodOrder. - public void test03_dirtyContextAfterTestMethod() throws Exception { + void dirtyContextAfterTestMethod() throws Exception { performAssertions(2); } @Test - // test## prefix required for @FixMethodOrder. - public void test04() throws Exception { + @Order(4) + void backToBasics() throws Exception { performAssertions(3); } @@ -108,4 +96,14 @@ public class MethodLevelDirtiesContextTests { assertThat(contextCount.get()).as("context creation count: ").isEqualTo(expectedContextCreationCount); } + + @Configuration + static class Config { + + @Bean + Integer count() { + return contextCount.incrementAndGet(); + } + } + } diff --git a/spring-test/src/test/java/org/springframework/test/context/cache/SpringRunnerContextCacheTests.java b/spring-test/src/test/java/org/springframework/test/context/cache/SpringExtensionContextCacheTests.java similarity index 66% rename from spring-test/src/test/java/org/springframework/test/context/cache/SpringRunnerContextCacheTests.java rename to spring-test/src/test/java/org/springframework/test/context/cache/SpringExtensionContextCacheTests.java index df687faf81..d43557322c 100644 --- a/spring-test/src/test/java/org/springframework/test/context/cache/SpringRunnerContextCacheTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/cache/SpringExtensionContextCacheTests.java @@ -16,19 +16,16 @@ package org.springframework.test.context.cache; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.FixMethodOrder; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.MethodSorters; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationContext; import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.TestExecutionListeners; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import org.springframework.test.context.support.DependencyInjectionTestExecutionListener; import org.springframework.test.context.support.DirtiesContextTestExecutionListener; @@ -37,9 +34,9 @@ import static org.springframework.test.context.cache.ContextCacheTestUtils.asser import static org.springframework.test.context.cache.ContextCacheTestUtils.resetContextCache; /** - * JUnit 4 based unit test which verifies correct {@link ContextCache + * Unit tests which verify correct {@link ContextCache * application context caching} in conjunction with the - * {@link SpringJUnit4ClassRunner} and the {@link DirtiesContext + * {@link SpringExtension} and the {@link DirtiesContext * @DirtiesContext} annotation at the method level. * * @author Sam Brannen @@ -48,50 +45,48 @@ import static org.springframework.test.context.cache.ContextCacheTestUtils.reset * @see ContextCacheTests * @see LruContextCacheTests */ -@RunWith(SpringJUnit4ClassRunner.class) -@FixMethodOrder(MethodSorters.NAME_ASCENDING) +@SpringJUnitConfig(locations = "../junit4/SpringJUnit4ClassRunnerAppCtxTests-context.xml") @TestExecutionListeners({ DependencyInjectionTestExecutionListener.class, DirtiesContextTestExecutionListener.class }) -@ContextConfiguration("../junit4/SpringJUnit4ClassRunnerAppCtxTests-context.xml") -public class SpringRunnerContextCacheTests { +class SpringExtensionContextCacheTests { private static ApplicationContext dirtiedApplicationContext; @Autowired - protected ApplicationContext applicationContext; + ApplicationContext applicationContext; - @BeforeClass - public static void verifyInitialCacheState() { + @BeforeAll + static void verifyInitialCacheState() { dirtiedApplicationContext = null; resetContextCache(); assertContextCacheStatistics("BeforeClass", 0, 0, 0); } - @AfterClass - public static void verifyFinalCacheState() { + @AfterAll + static void verifyFinalCacheState() { assertContextCacheStatistics("AfterClass", 1, 1, 2); } @Test @DirtiesContext - public void dirtyContext() { + void dirtyContext() { assertContextCacheStatistics("dirtyContext()", 1, 0, 1); assertThat(this.applicationContext).as("The application context should have been autowired.").isNotNull(); - SpringRunnerContextCacheTests.dirtiedApplicationContext = this.applicationContext; + SpringExtensionContextCacheTests.dirtiedApplicationContext = this.applicationContext; } @Test - public void verifyContextDirty() { + void verifyContextDirty() { assertContextCacheStatistics("verifyContextWasDirtied()", 1, 0, 2); assertThat(this.applicationContext).as("The application context should have been autowired.").isNotNull(); - assertThat(this.applicationContext).as("The application context should have been 'dirtied'.").isNotSameAs(SpringRunnerContextCacheTests.dirtiedApplicationContext); - SpringRunnerContextCacheTests.dirtiedApplicationContext = this.applicationContext; + assertThat(this.applicationContext).as("The application context should have been 'dirtied'.").isNotSameAs(SpringExtensionContextCacheTests.dirtiedApplicationContext); + SpringExtensionContextCacheTests.dirtiedApplicationContext = this.applicationContext; } @Test - public void verifyContextNotDirty() { + void verifyContextNotDirty() { assertContextCacheStatistics("verifyContextWasNotDirtied()", 1, 1, 2); assertThat(this.applicationContext).as("The application context should have been autowired.").isNotNull(); - assertThat(this.applicationContext).as("The application context should NOT have been 'dirtied'.").isSameAs(SpringRunnerContextCacheTests.dirtiedApplicationContext); + assertThat(this.applicationContext).as("The application context should NOT have been 'dirtied'.").isSameAs(SpringExtensionContextCacheTests.dirtiedApplicationContext); } } diff --git a/spring-test/src/test/java/org/springframework/test/context/configuration/interfaces/ActiveProfilesInterfaceTests.java b/spring-test/src/test/java/org/springframework/test/context/configuration/interfaces/ActiveProfilesInterfaceTests.java index e30db8a7dc..3a6d264e0b 100644 --- a/spring-test/src/test/java/org/springframework/test/context/configuration/interfaces/ActiveProfilesInterfaceTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/configuration/interfaces/ActiveProfilesInterfaceTests.java @@ -16,14 +16,14 @@ package org.springframework.test.context.configuration.interfaces; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Profile; -import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.tests.sample.beans.Employee; import static org.assertj.core.api.Assertions.assertThat; @@ -32,15 +32,15 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Sam Brannen * @since 4.3 */ -@RunWith(SpringRunner.class) -public class ActiveProfilesInterfaceTests implements ActiveProfilesTestInterface { +@ExtendWith(SpringExtension.class) +class ActiveProfilesInterfaceTests implements ActiveProfilesTestInterface { @Autowired Employee employee; @Test - public void profileFromTestInterface() { + void profileFromTestInterface() { assertThat(employee).isNotNull(); assertThat(employee.getName()).isEqualTo("dev"); } diff --git a/spring-test/src/test/java/org/springframework/test/context/configuration/interfaces/BootstrapWithInterfaceTests.java b/spring-test/src/test/java/org/springframework/test/context/configuration/interfaces/BootstrapWithInterfaceTests.java index 8cb2ae1531..f695537bb5 100644 --- a/spring-test/src/test/java/org/springframework/test/context/configuration/interfaces/BootstrapWithInterfaceTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/configuration/interfaces/BootstrapWithInterfaceTests.java @@ -16,11 +16,11 @@ package org.springframework.test.context.configuration.interfaces; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; import static org.assertj.core.api.Assertions.assertThat; @@ -28,15 +28,15 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Sam Brannen * @since 4.3 */ -@RunWith(SpringRunner.class) -public class BootstrapWithInterfaceTests implements BootstrapWithTestInterface { +@ExtendWith(SpringExtension.class) +class BootstrapWithInterfaceTests implements BootstrapWithTestInterface { @Autowired String foo; @Test - public void injectedBean() { + void injectedBean() { assertThat(foo).isEqualTo("foo"); } diff --git a/spring-test/src/test/java/org/springframework/test/context/configuration/interfaces/ContextConfigurationInterfaceTests.java b/spring-test/src/test/java/org/springframework/test/context/configuration/interfaces/ContextConfigurationInterfaceTests.java index 17594448cb..8f302fd423 100644 --- a/spring-test/src/test/java/org/springframework/test/context/configuration/interfaces/ContextConfigurationInterfaceTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/configuration/interfaces/ContextConfigurationInterfaceTests.java @@ -16,11 +16,11 @@ package org.springframework.test.context.configuration.interfaces; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.tests.sample.beans.Employee; import static org.assertj.core.api.Assertions.assertThat; @@ -29,15 +29,15 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Sam Brannen * @since 4.3 */ -@RunWith(SpringRunner.class) -public class ContextConfigurationInterfaceTests implements ContextConfigurationTestInterface { +@ExtendWith(SpringExtension.class) +class ContextConfigurationInterfaceTests implements ContextConfigurationTestInterface { @Autowired Employee employee; @Test - public void profileFromTestInterface() { + void profileFromTestInterface() { assertThat(employee).isNotNull(); assertThat(employee.getName()).isEqualTo("Dilbert"); } diff --git a/spring-test/src/test/java/org/springframework/test/context/configuration/interfaces/ContextHierarchyInterfaceTests.java b/spring-test/src/test/java/org/springframework/test/context/configuration/interfaces/ContextHierarchyInterfaceTests.java index 21d24c366c..6fa066903a 100644 --- a/spring-test/src/test/java/org/springframework/test/context/configuration/interfaces/ContextHierarchyInterfaceTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/configuration/interfaces/ContextHierarchyInterfaceTests.java @@ -16,12 +16,12 @@ package org.springframework.test.context.configuration.interfaces; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationContext; -import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; import static org.assertj.core.api.Assertions.assertThat; @@ -29,8 +29,8 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Sam Brannen * @since 4.3 */ -@RunWith(SpringRunner.class) -public class ContextHierarchyInterfaceTests implements ContextHierarchyTestInterface { +@ExtendWith(SpringExtension.class) +class ContextHierarchyInterfaceTests implements ContextHierarchyTestInterface { @Autowired String foo; @@ -46,7 +46,7 @@ public class ContextHierarchyInterfaceTests implements ContextHierarchyTestInter @Test - public void loadContextHierarchy() { + void loadContextHierarchy() { assertThat(context).as("child ApplicationContext").isNotNull(); assertThat(context.getParent()).as("parent ApplicationContext").isNotNull(); assertThat(context.getParent().getParent()).as("grandparent ApplicationContext").isNull(); diff --git a/spring-test/src/test/java/org/springframework/test/context/configuration/interfaces/DirtiesContextInterfaceTests.java b/spring-test/src/test/java/org/springframework/test/context/configuration/interfaces/DirtiesContextInterfaceTests.java index 73195564f1..bf9f7b0f6b 100644 --- a/spring-test/src/test/java/org/springframework/test/context/configuration/interfaces/DirtiesContextInterfaceTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/configuration/interfaces/DirtiesContextInterfaceTests.java @@ -18,9 +18,9 @@ package org.springframework.test.context.configuration.interfaces; import java.util.concurrent.atomic.AtomicInteger; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; @@ -41,14 +41,14 @@ import static org.springframework.test.context.junit4.JUnitTestingUtils.runTests * @author Sam Brannen * @since 4.3 */ -public class DirtiesContextInterfaceTests { +class DirtiesContextInterfaceTests { private static final AtomicInteger cacheHits = new AtomicInteger(0); private static final AtomicInteger cacheMisses = new AtomicInteger(0); - @BeforeClass - public static void verifyInitialCacheState() { + @BeforeAll + static void verifyInitialCacheState() { resetContextCache(); // Reset static counters in case tests are run multiple times in a test suite -- // for example, via JUnit's @Suite. @@ -57,13 +57,13 @@ public class DirtiesContextInterfaceTests { assertContextCacheStatistics("BeforeClass", 0, cacheHits.get(), cacheMisses.get()); } - @AfterClass - public static void verifyFinalCacheState() { + @AfterAll + static void verifyFinalCacheState() { assertContextCacheStatistics("AfterClass", 0, cacheHits.get(), cacheMisses.get()); } @Test - public void verifyDirtiesContextBehavior() throws Exception { + void verifyDirtiesContextBehavior() throws Exception { runTestClassAndAssertStats(ClassLevelDirtiesContextWithCleanMethodsAndDefaultModeTestCase.class, 1); assertContextCacheStatistics("after class-level @DirtiesContext with clean test method and default class mode", 0, cacheHits.get(), cacheMisses.incrementAndGet()); @@ -90,7 +90,7 @@ public class DirtiesContextInterfaceTests { ApplicationContext applicationContext; - @Test + @org.junit.Test public void verifyContextWasAutowired() { assertThat(this.applicationContext).as("The application context should have been autowired.").isNotNull(); } diff --git a/spring-test/src/test/java/org/springframework/test/context/configuration/interfaces/SqlConfigInterfaceTests.java b/spring-test/src/test/java/org/springframework/test/context/configuration/interfaces/SqlConfigInterfaceTests.java index 5998734353..f12b8ab905 100644 --- a/spring-test/src/test/java/org/springframework/test/context/configuration/interfaces/SqlConfigInterfaceTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/configuration/interfaces/SqlConfigInterfaceTests.java @@ -16,11 +16,17 @@ package org.springframework.test.context.configuration.interfaces; -import org.junit.Test; +import javax.sql.DataSource; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.test.context.jdbc.Sql; import org.springframework.test.context.jdbc.SqlConfig; -import org.springframework.test.context.junit4.AbstractTransactionalJUnit4SpringContextTests; +import org.springframework.test.context.junit.jupiter.SpringExtension; +import org.springframework.test.jdbc.JdbcTestUtils; import static org.assertj.core.api.Assertions.assertThat; @@ -28,19 +34,30 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Sam Brannen * @since 4.3 */ -public class SqlConfigInterfaceTests extends AbstractTransactionalJUnit4SpringContextTests - implements SqlConfigTestInterface { +@ExtendWith(SpringExtension.class) +class SqlConfigInterfaceTests implements SqlConfigTestInterface { + + JdbcTemplate jdbcTemplate; + + @Autowired + void setDataSource(DataSource dataSource) { + this.jdbcTemplate = new JdbcTemplate(dataSource); + } @Test @Sql(scripts = "/org/springframework/test/context/jdbc/schema.sql", // config = @SqlConfig(separator = ";")) @Sql("/org/springframework/test/context/jdbc/data-add-users-with-custom-script-syntax.sql") - public void methodLevelScripts() { + void methodLevelScripts() { assertNumUsers(3); } - protected void assertNumUsers(int expected) { + void assertNumUsers(int expected) { assertThat(countRowsInTable("user")).as("Number of rows in the 'user' table.").isEqualTo(expected); } + int countRowsInTable(String tableName) { + return JdbcTestUtils.countRowsInTable(this.jdbcTemplate, tableName); + } + } diff --git a/spring-test/src/test/java/org/springframework/test/context/configuration/interfaces/TestPropertySourceInterfaceTests.java b/spring-test/src/test/java/org/springframework/test/context/configuration/interfaces/TestPropertySourceInterfaceTests.java index ad3d18dcde..e1e8baa035 100644 --- a/spring-test/src/test/java/org/springframework/test/context/configuration/interfaces/TestPropertySourceInterfaceTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/configuration/interfaces/TestPropertySourceInterfaceTests.java @@ -16,30 +16,29 @@ package org.springframework.test.context.configuration.interfaces; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Configuration; import org.springframework.core.env.Environment; -import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; import static org.assertj.core.api.Assertions.assertThat; - /** * @author Sam Brannen * @since 4.3 */ -@RunWith(SpringRunner.class) -public class TestPropertySourceInterfaceTests implements TestPropertySourceTestInterface { +@ExtendWith(SpringExtension.class) +class TestPropertySourceInterfaceTests implements TestPropertySourceTestInterface { @Autowired Environment env; @Test - public void propertiesAreAvailableInEnvironment() { + void propertiesAreAvailableInEnvironment() { assertThat(property("foo")).isEqualTo("bar"); assertThat(property("enigma")).isEqualTo("42"); } diff --git a/spring-test/src/test/java/org/springframework/test/context/configuration/interfaces/WebAppConfigurationInterfaceTests.java b/spring-test/src/test/java/org/springframework/test/context/configuration/interfaces/WebAppConfigurationInterfaceTests.java index e470c55f57..0c7af46d42 100644 --- a/spring-test/src/test/java/org/springframework/test/context/configuration/interfaces/WebAppConfigurationInterfaceTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/configuration/interfaces/WebAppConfigurationInterfaceTests.java @@ -16,11 +16,11 @@ package org.springframework.test.context.configuration.interfaces; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.web.context.WebApplicationContext; import static org.assertj.core.api.Assertions.assertThat; @@ -29,15 +29,15 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Sam Brannen * @since 4.3 */ -@RunWith(SpringRunner.class) -public class WebAppConfigurationInterfaceTests implements WebAppConfigurationTestInterface { +@ExtendWith(SpringExtension.class) +class WebAppConfigurationInterfaceTests implements WebAppConfigurationTestInterface { @Autowired WebApplicationContext wac; @Test - public void wacLoaded() { + void wacLoaded() { assertThat(wac).isNotNull(); } diff --git a/spring-test/src/test/java/org/springframework/test/context/env/ApplicationPropertyOverridePropertiesFileTestPropertySourceTests.java b/spring-test/src/test/java/org/springframework/test/context/env/ApplicationPropertyOverridePropertiesFileTestPropertySourceTests.java index c4dca5e9e8..4ab9c372f2 100644 --- a/spring-test/src/test/java/org/springframework/test/context/env/ApplicationPropertyOverridePropertiesFileTestPropertySourceTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/env/ApplicationPropertyOverridePropertiesFileTestPropertySourceTests.java @@ -16,8 +16,8 @@ package org.springframework.test.context.env; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Configuration; @@ -25,7 +25,7 @@ import org.springframework.context.annotation.PropertySource; import org.springframework.core.env.Environment; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.TestPropertySource; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; import static org.assertj.core.api.Assertions.assertThat; @@ -39,17 +39,17 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Sam Brannen * @since 4.1 */ -@RunWith(SpringJUnit4ClassRunner.class) +@ExtendWith(SpringExtension.class) @ContextConfiguration @TestPropertySource("ApplicationPropertyOverridePropertiesFileTestPropertySourceTests.properties") -public class ApplicationPropertyOverridePropertiesFileTestPropertySourceTests { +class ApplicationPropertyOverridePropertiesFileTestPropertySourceTests { @Autowired protected Environment env; @Test - public void verifyPropertiesAreAvailableInEnvironment() { + void verifyPropertiesAreAvailableInEnvironment() { assertThat(env.getProperty("explicit")).isEqualTo("test override"); } diff --git a/spring-test/src/test/java/org/springframework/test/context/env/DefaultPropertiesFileDetectionTestPropertySourceTests.java b/spring-test/src/test/java/org/springframework/test/context/env/DefaultPropertiesFileDetectionTestPropertySourceTests.java index 801d95da35..5a15d3046a 100644 --- a/spring-test/src/test/java/org/springframework/test/context/env/DefaultPropertiesFileDetectionTestPropertySourceTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/env/DefaultPropertiesFileDetectionTestPropertySourceTests.java @@ -16,15 +16,15 @@ package org.springframework.test.context.env; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Configuration; import org.springframework.core.env.Environment; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.TestPropertySource; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; import static org.assertj.core.api.Assertions.assertThat; @@ -35,17 +35,17 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Sam Brannen * @since 4.1 */ -@RunWith(SpringJUnit4ClassRunner.class) +@ExtendWith(SpringExtension.class) @ContextConfiguration @TestPropertySource -public class DefaultPropertiesFileDetectionTestPropertySourceTests { +class DefaultPropertiesFileDetectionTestPropertySourceTests { @Autowired protected Environment env; @Test - public void verifyPropertiesAreAvailableInEnvironment() { + void verifyPropertiesAreAvailableInEnvironment() { // from DefaultPropertiesFileDetectionTestPropertySourceTests.properties assertEnvironmentValue("riddle", "auto detected"); } diff --git a/spring-test/src/test/java/org/springframework/test/context/env/ExplicitPropertiesFileTestPropertySourceTests.java b/spring-test/src/test/java/org/springframework/test/context/env/ExplicitPropertiesFileTestPropertySourceTests.java index 3b1cff9598..31da089a47 100644 --- a/spring-test/src/test/java/org/springframework/test/context/env/ExplicitPropertiesFileTestPropertySourceTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/env/ExplicitPropertiesFileTestPropertySourceTests.java @@ -16,15 +16,15 @@ package org.springframework.test.context.env; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Configuration; import org.springframework.core.env.Environment; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.TestPropertySource; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; import static org.assertj.core.api.Assertions.assertThat; @@ -35,7 +35,7 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Sam Brannen * @since 4.1 */ -@RunWith(SpringJUnit4ClassRunner.class) +@ExtendWith(SpringExtension.class) @ContextConfiguration @TestPropertySource("explicit.properties") public class ExplicitPropertiesFileTestPropertySourceTests { @@ -45,15 +45,13 @@ public class ExplicitPropertiesFileTestPropertySourceTests { @Test - public void verifyPropertiesAreAvailableInEnvironment() { + void verifyPropertiesAreAvailableInEnvironment() { String userHomeKey = "user.home"; assertThat(env.getProperty(userHomeKey)).isEqualTo(System.getProperty(userHomeKey)); assertThat(env.getProperty("explicit")).isEqualTo("enigma"); } - // ------------------------------------------------------------------- - @Configuration static class Config { /* no user beans required for these tests */ diff --git a/spring-test/src/test/java/org/springframework/test/context/env/ExtendedDefaultPropertiesFileDetectionTestPropertySourceTests.java b/spring-test/src/test/java/org/springframework/test/context/env/ExtendedDefaultPropertiesFileDetectionTestPropertySourceTests.java index 5d51fa5fdb..61fcffe44c 100644 --- a/spring-test/src/test/java/org/springframework/test/context/env/ExtendedDefaultPropertiesFileDetectionTestPropertySourceTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/env/ExtendedDefaultPropertiesFileDetectionTestPropertySourceTests.java @@ -16,7 +16,7 @@ package org.springframework.test.context.env; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.test.context.TestPropertySource; @@ -29,11 +29,12 @@ import org.springframework.test.context.TestPropertySource; * @since 4.1 */ @TestPropertySource -public class ExtendedDefaultPropertiesFileDetectionTestPropertySourceTests extends +class ExtendedDefaultPropertiesFileDetectionTestPropertySourceTests extends DefaultPropertiesFileDetectionTestPropertySourceTests { @Test - public void verifyPropertiesAreAvailableInEnvironment() { + @Override + void verifyPropertiesAreAvailableInEnvironment() { super.verifyPropertiesAreAvailableInEnvironment(); // from ExtendedDefaultPropertiesFileDetectionTestPropertySourceTests.properties assertEnvironmentValue("enigma", "auto detected"); diff --git a/spring-test/src/test/java/org/springframework/test/context/env/InheritedRelativePathPropertiesFileTestPropertySourceTests.java b/spring-test/src/test/java/org/springframework/test/context/env/InheritedRelativePathPropertiesFileTestPropertySourceTests.java index 9af4f4436c..61ee2c5701 100644 --- a/spring-test/src/test/java/org/springframework/test/context/env/InheritedRelativePathPropertiesFileTestPropertySourceTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/env/InheritedRelativePathPropertiesFileTestPropertySourceTests.java @@ -26,7 +26,7 @@ import org.springframework.test.context.TestPropertySource; * @author Sam Brannen * @since 4.1 */ -public class InheritedRelativePathPropertiesFileTestPropertySourceTests extends +class InheritedRelativePathPropertiesFileTestPropertySourceTests extends ExplicitPropertiesFileTestPropertySourceTests { /* all tests are in superclass */ diff --git a/spring-test/src/test/java/org/springframework/test/context/env/InlinedPropertiesOverridePropertiesFilesTestPropertySourceTests.java b/spring-test/src/test/java/org/springframework/test/context/env/InlinedPropertiesOverridePropertiesFilesTestPropertySourceTests.java index e412664636..09a89a25d2 100644 --- a/spring-test/src/test/java/org/springframework/test/context/env/InlinedPropertiesOverridePropertiesFilesTestPropertySourceTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/env/InlinedPropertiesOverridePropertiesFilesTestPropertySourceTests.java @@ -16,8 +16,8 @@ package org.springframework.test.context.env; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; @@ -25,7 +25,7 @@ import org.springframework.context.annotation.Configuration; import org.springframework.core.env.Environment; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.TestPropertySource; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; import static org.assertj.core.api.Assertions.assertThat; @@ -36,10 +36,10 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Sam Brannen * @since 4.3 */ -@RunWith(SpringJUnit4ClassRunner.class) +@ExtendWith(SpringExtension.class) @ContextConfiguration @TestPropertySource(locations = "explicit.properties", properties = "explicit = inlined") -public class InlinedPropertiesOverridePropertiesFilesTestPropertySourceTests { +class InlinedPropertiesOverridePropertiesFilesTestPropertySourceTests { @Autowired Environment env; @@ -49,7 +49,7 @@ public class InlinedPropertiesOverridePropertiesFilesTestPropertySourceTests { @Test - public void inlinedPropertyOverridesValueFromPropertiesFile() { + void inlinedPropertyOverridesValueFromPropertiesFile() { assertThat(env.getProperty("explicit")).isEqualTo("inlined"); assertThat(this.explicit).isEqualTo("inlined"); } diff --git a/spring-test/src/test/java/org/springframework/test/context/env/InlinedPropertiesTestPropertySourceTests.java b/spring-test/src/test/java/org/springframework/test/context/env/InlinedPropertiesTestPropertySourceTests.java index ad2a4263db..efc89c4758 100644 --- a/spring-test/src/test/java/org/springframework/test/context/env/InlinedPropertiesTestPropertySourceTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/env/InlinedPropertiesTestPropertySourceTests.java @@ -16,8 +16,8 @@ package org.springframework.test.context.env; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Configuration; @@ -25,7 +25,7 @@ import org.springframework.core.env.ConfigurableEnvironment; import org.springframework.core.env.EnumerablePropertySource; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.TestPropertySource; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; import static org.assertj.core.api.Assertions.assertThat; import static org.springframework.test.context.support.TestPropertySourceUtils.INLINED_PROPERTIES_PROPERTY_SOURCE_NAME; @@ -37,11 +37,11 @@ import static org.springframework.test.context.support.TestPropertySourceUtils.I * @author Sam Brannen * @since 4.1 */ -@RunWith(SpringJUnit4ClassRunner.class) +@ExtendWith(SpringExtension.class) @ContextConfiguration @TestPropertySource(properties = { "", "foo = bar", "baz quux", "enigma: 42", "x.y.z = a=b=c", "server.url = https://example.com", "key.value.1: key=value", "key.value.2 key=value", "key.value.3 key:value" }) -public class InlinedPropertiesTestPropertySourceTests { +class InlinedPropertiesTestPropertySourceTests { @Autowired private ConfigurableEnvironment env; @@ -52,7 +52,7 @@ public class InlinedPropertiesTestPropertySourceTests { } @Test - public void propertiesAreAvailableInEnvironment() { + void propertiesAreAvailableInEnvironment() { // Simple key/value pairs assertThat(property("foo")).isEqualTo("bar"); assertThat(property("baz")).isEqualTo("quux"); @@ -68,7 +68,7 @@ public class InlinedPropertiesTestPropertySourceTests { @Test @SuppressWarnings("rawtypes") - public void propertyNameOrderingIsPreservedInEnvironment() { + void propertyNameOrderingIsPreservedInEnvironment() { final String[] expectedPropertyNames = new String[] { "foo", "baz", "enigma", "x.y.z", "server.url", "key.value.1", "key.value.2", "key.value.3" }; EnumerablePropertySource eps = (EnumerablePropertySource) env.getPropertySources().get( diff --git a/spring-test/src/test/java/org/springframework/test/context/env/MergedPropertiesFilesOverriddenByInlinedPropertiesTestPropertySourceTests.java b/spring-test/src/test/java/org/springframework/test/context/env/MergedPropertiesFilesOverriddenByInlinedPropertiesTestPropertySourceTests.java index fd2c74b304..ffb0484a59 100644 --- a/spring-test/src/test/java/org/springframework/test/context/env/MergedPropertiesFilesOverriddenByInlinedPropertiesTestPropertySourceTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/env/MergedPropertiesFilesOverriddenByInlinedPropertiesTestPropertySourceTests.java @@ -16,7 +16,7 @@ package org.springframework.test.context.env; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.test.context.TestPropertySource; @@ -31,18 +31,18 @@ import static org.assertj.core.api.Assertions.assertThat; * @since 4.1 */ @TestPropertySource(properties = { "explicit = inlined", "extended = inlined1", "extended = inlined2" }) -public class MergedPropertiesFilesOverriddenByInlinedPropertiesTestPropertySourceTests extends +class MergedPropertiesFilesOverriddenByInlinedPropertiesTestPropertySourceTests extends MergedPropertiesFilesTestPropertySourceTests { @Test @Override - public void verifyPropertiesAreAvailableInEnvironment() { + void verifyPropertiesAreAvailableInEnvironment() { assertThat(env.getProperty("explicit")).isEqualTo("inlined"); } @Test @Override - public void verifyExtendedPropertiesAreAvailableInEnvironment() { + void verifyExtendedPropertiesAreAvailableInEnvironment() { assertThat(env.getProperty("extended")).isEqualTo("inlined2"); } diff --git a/spring-test/src/test/java/org/springframework/test/context/env/MergedPropertiesFilesTestPropertySourceTests.java b/spring-test/src/test/java/org/springframework/test/context/env/MergedPropertiesFilesTestPropertySourceTests.java index 92e2225106..d6b5e6b4c7 100644 --- a/spring-test/src/test/java/org/springframework/test/context/env/MergedPropertiesFilesTestPropertySourceTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/env/MergedPropertiesFilesTestPropertySourceTests.java @@ -16,7 +16,7 @@ package org.springframework.test.context.env; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.test.context.TestPropertySource; @@ -30,11 +30,11 @@ import static org.assertj.core.api.Assertions.assertThat; * @since 4.1 */ @TestPropertySource("extended.properties") -public class MergedPropertiesFilesTestPropertySourceTests extends +class MergedPropertiesFilesTestPropertySourceTests extends ExplicitPropertiesFileTestPropertySourceTests { @Test - public void verifyExtendedPropertiesAreAvailableInEnvironment() { + void verifyExtendedPropertiesAreAvailableInEnvironment() { assertThat(env.getProperty("extended", Integer.class).intValue()).isEqualTo(42); } diff --git a/spring-test/src/test/java/org/springframework/test/context/env/SystemPropertyOverridePropertiesFileTestPropertySourceTests.java b/spring-test/src/test/java/org/springframework/test/context/env/SystemPropertyOverridePropertiesFileTestPropertySourceTests.java index 42a0a6c7ff..d36244f2f2 100644 --- a/spring-test/src/test/java/org/springframework/test/context/env/SystemPropertyOverridePropertiesFileTestPropertySourceTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/env/SystemPropertyOverridePropertiesFileTestPropertySourceTests.java @@ -16,17 +16,17 @@ package org.springframework.test.context.env; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Configuration; import org.springframework.core.env.Environment; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.TestPropertySource; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; import static org.assertj.core.api.Assertions.assertThat; @@ -38,10 +38,10 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Sam Brannen * @since 4.1 */ -@RunWith(SpringJUnit4ClassRunner.class) +@ExtendWith(SpringExtension.class) @ContextConfiguration @TestPropertySource("SystemPropertyOverridePropertiesFileTestPropertySourceTests.properties") -public class SystemPropertyOverridePropertiesFileTestPropertySourceTests { +class SystemPropertyOverridePropertiesFileTestPropertySourceTests { private static final String KEY = SystemPropertyOverridePropertiesFileTestPropertySourceTests.class.getSimpleName() + ".riddle"; @@ -49,18 +49,18 @@ public class SystemPropertyOverridePropertiesFileTestPropertySourceTests { protected Environment env; - @BeforeClass - public static void setSystemProperty() { + @BeforeAll + static void setSystemProperty() { System.setProperty(KEY, "override me!"); } - @AfterClass - public static void removeSystemProperty() { + @AfterAll + static void removeSystemProperty() { System.setProperty(KEY, ""); } @Test - public void verifyPropertiesAreAvailableInEnvironment() { + void verifyPropertiesAreAvailableInEnvironment() { assertThat(env.getProperty(KEY)).isEqualTo("enigma"); } diff --git a/spring-test/src/test/java/org/springframework/test/context/env/TestPropertySourceTestSuite.java b/spring-test/src/test/java/org/springframework/test/context/env/TestPropertySourceTestSuite.java index 1adab5d39d..97c5c62e25 100644 --- a/spring-test/src/test/java/org/springframework/test/context/env/TestPropertySourceTestSuite.java +++ b/spring-test/src/test/java/org/springframework/test/context/env/TestPropertySourceTestSuite.java @@ -36,7 +36,7 @@ import org.springframework.test.context.TestPropertySource; * @since 5.2 */ @RunWith(JUnitPlatform.class) -@IncludeEngines("junit-vintage") +@IncludeEngines("junit-jupiter") @SelectPackages("org.springframework.test.context.env") @IncludeClassNamePatterns(".*Tests$") @UseTechnicalNames diff --git a/spring-test/src/test/java/org/springframework/test/context/env/repeatable/AbstractRepeatableTestPropertySourceTests.java b/spring-test/src/test/java/org/springframework/test/context/env/repeatable/AbstractRepeatableTestPropertySourceTests.java index 2f180aaa05..2273231db9 100644 --- a/spring-test/src/test/java/org/springframework/test/context/env/repeatable/AbstractRepeatableTestPropertySourceTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/env/repeatable/AbstractRepeatableTestPropertySourceTests.java @@ -16,14 +16,14 @@ package org.springframework.test.context.env.repeatable; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Configuration; import org.springframework.core.env.Environment; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.TestPropertySource; -import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; import static org.assertj.core.api.Assertions.assertThat; @@ -34,7 +34,7 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Sam Brannen * @since 5.2 */ -@RunWith(SpringRunner.class) +@ExtendWith(SpringExtension.class) @ContextConfiguration abstract class AbstractRepeatableTestPropertySourceTests { diff --git a/spring-test/src/test/java/org/springframework/test/context/env/repeatable/DefaultPropertiesFileDetectionRepeatedTestPropertySourceTests.java b/spring-test/src/test/java/org/springframework/test/context/env/repeatable/DefaultPropertiesFileDetectionRepeatedTestPropertySourceTests.java index ea55266e84..db2658314a 100644 --- a/spring-test/src/test/java/org/springframework/test/context/env/repeatable/DefaultPropertiesFileDetectionRepeatedTestPropertySourceTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/env/repeatable/DefaultPropertiesFileDetectionRepeatedTestPropertySourceTests.java @@ -16,7 +16,7 @@ package org.springframework.test.context.env.repeatable; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.test.context.TestPropertySource; @@ -30,11 +30,11 @@ import org.springframework.test.context.TestPropertySource; */ @TestPropertySource @TestPropertySource("local.properties") -public class DefaultPropertiesFileDetectionRepeatedTestPropertySourceTests +class DefaultPropertiesFileDetectionRepeatedTestPropertySourceTests extends AbstractRepeatableTestPropertySourceTests { @Test - public void test() { + void test() { assertEnvironmentValue("default.value", "default file"); assertEnvironmentValue("key1", "local file"); } diff --git a/spring-test/src/test/java/org/springframework/test/context/env/repeatable/ExplicitPropertiesFilesRepeatedTestPropertySourceTests.java b/spring-test/src/test/java/org/springframework/test/context/env/repeatable/ExplicitPropertiesFilesRepeatedTestPropertySourceTests.java index 8cbf68ce03..3fe63435af 100644 --- a/spring-test/src/test/java/org/springframework/test/context/env/repeatable/ExplicitPropertiesFilesRepeatedTestPropertySourceTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/env/repeatable/ExplicitPropertiesFilesRepeatedTestPropertySourceTests.java @@ -16,7 +16,7 @@ package org.springframework.test.context.env.repeatable; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.test.context.TestPropertySource; @@ -33,10 +33,10 @@ import org.springframework.test.context.TestPropertySource; */ @TestPropertySource("first.properties") @TestPropertySource("second.properties") -public class ExplicitPropertiesFilesRepeatedTestPropertySourceTests extends AbstractRepeatableTestPropertySourceTests { +class ExplicitPropertiesFilesRepeatedTestPropertySourceTests extends AbstractRepeatableTestPropertySourceTests { @Test - public void test() { + void test() { assertEnvironmentValue("alpha", "omega"); assertEnvironmentValue("first", "1111"); assertEnvironmentValue("second", "2222"); diff --git a/spring-test/src/test/java/org/springframework/test/context/env/repeatable/LocalInlinedPropertyAndInheritedInlinedPropertyTests.java b/spring-test/src/test/java/org/springframework/test/context/env/repeatable/LocalInlinedPropertyAndInheritedInlinedPropertyTests.java index ddfbd1b4c6..e350fb4e94 100644 --- a/spring-test/src/test/java/org/springframework/test/context/env/repeatable/LocalInlinedPropertyAndInheritedInlinedPropertyTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/env/repeatable/LocalInlinedPropertyAndInheritedInlinedPropertyTests.java @@ -16,7 +16,7 @@ package org.springframework.test.context.env.repeatable; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.test.context.TestPropertySource; @@ -29,10 +29,10 @@ import org.springframework.test.context.TestPropertySource; * @since 5.2 */ @TestPropertySource(properties = "key2 = local") -public class LocalInlinedPropertyAndInheritedInlinedPropertyTests extends AbstractClassWithTestProperty { +class LocalInlinedPropertyAndInheritedInlinedPropertyTests extends AbstractClassWithTestProperty { @Test - public void test() { + void test() { assertEnvironmentValue("key1", "parent"); assertEnvironmentValue("key2", "local"); } diff --git a/spring-test/src/test/java/org/springframework/test/context/env/repeatable/LocalInlinedPropertyAndMetaInlinedPropertyTests.java b/spring-test/src/test/java/org/springframework/test/context/env/repeatable/LocalInlinedPropertyAndMetaInlinedPropertyTests.java index 5badcc2bb0..99c48f864c 100644 --- a/spring-test/src/test/java/org/springframework/test/context/env/repeatable/LocalInlinedPropertyAndMetaInlinedPropertyTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/env/repeatable/LocalInlinedPropertyAndMetaInlinedPropertyTests.java @@ -16,7 +16,7 @@ package org.springframework.test.context.env.repeatable; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.test.context.TestPropertySource; @@ -30,10 +30,10 @@ import org.springframework.test.context.TestPropertySource; */ @TestPropertySource(properties = "key1 = local") @MetaInlinedTestProperty -public class LocalInlinedPropertyAndMetaInlinedPropertyTests extends AbstractRepeatableTestPropertySourceTests { +class LocalInlinedPropertyAndMetaInlinedPropertyTests extends AbstractRepeatableTestPropertySourceTests { @Test - public void test() { + void test() { assertEnvironmentValue("key1", "local"); assertEnvironmentValue("enigma", "meta"); } diff --git a/spring-test/src/test/java/org/springframework/test/context/env/repeatable/LocalInlinedPropertyAndMetaMetaInlinedPropertyTests.java b/spring-test/src/test/java/org/springframework/test/context/env/repeatable/LocalInlinedPropertyAndMetaMetaInlinedPropertyTests.java index 1f02a961d5..0d67caf6ea 100644 --- a/spring-test/src/test/java/org/springframework/test/context/env/repeatable/LocalInlinedPropertyAndMetaMetaInlinedPropertyTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/env/repeatable/LocalInlinedPropertyAndMetaMetaInlinedPropertyTests.java @@ -16,7 +16,7 @@ package org.springframework.test.context.env.repeatable; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.test.context.TestPropertySource; @@ -30,10 +30,10 @@ import org.springframework.test.context.TestPropertySource; */ @TestPropertySource(properties = "key1 = local") @MetaComposedTestProperty -public class LocalInlinedPropertyAndMetaMetaInlinedPropertyTests extends AbstractRepeatableTestPropertySourceTests { +class LocalInlinedPropertyAndMetaMetaInlinedPropertyTests extends AbstractRepeatableTestPropertySourceTests { @Test - public void test() { + void test() { assertEnvironmentValue("key1", "local"); assertEnvironmentValue("enigma", "meta meta"); } diff --git a/spring-test/src/test/java/org/springframework/test/context/env/repeatable/LocalInlinedPropertyOverridesInheritedAndMetaInlinedPropertiesTests.java b/spring-test/src/test/java/org/springframework/test/context/env/repeatable/LocalInlinedPropertyOverridesInheritedAndMetaInlinedPropertiesTests.java index 5c221a59be..1ed10b3089 100644 --- a/spring-test/src/test/java/org/springframework/test/context/env/repeatable/LocalInlinedPropertyOverridesInheritedAndMetaInlinedPropertiesTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/env/repeatable/LocalInlinedPropertyOverridesInheritedAndMetaInlinedPropertiesTests.java @@ -21,7 +21,7 @@ import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.test.context.TestPropertySource; import org.springframework.test.context.env.repeatable.LocalInlinedPropertyOverridesInheritedAndMetaInlinedPropertiesTests.Key1InlinedTestProperty; @@ -36,10 +36,10 @@ import org.springframework.test.context.env.repeatable.LocalInlinedPropertyOverr */ @TestPropertySource(properties = "key1 = local") @Key1InlinedTestProperty -public class LocalInlinedPropertyOverridesInheritedAndMetaInlinedPropertiesTests extends AbstractClassWithTestProperty { +class LocalInlinedPropertyOverridesInheritedAndMetaInlinedPropertiesTests extends AbstractClassWithTestProperty { @Test - public void test() { + void test() { assertEnvironmentValue("key1", "local"); } diff --git a/spring-test/src/test/java/org/springframework/test/context/env/repeatable/LocalInlinedPropertyOverridesInheritedInlinedPropertyTests.java b/spring-test/src/test/java/org/springframework/test/context/env/repeatable/LocalInlinedPropertyOverridesInheritedInlinedPropertyTests.java index b5c42216c7..0d5995108d 100644 --- a/spring-test/src/test/java/org/springframework/test/context/env/repeatable/LocalInlinedPropertyOverridesInheritedInlinedPropertyTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/env/repeatable/LocalInlinedPropertyOverridesInheritedInlinedPropertyTests.java @@ -16,7 +16,7 @@ package org.springframework.test.context.env.repeatable; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.test.context.TestPropertySource; @@ -30,11 +30,11 @@ import org.springframework.test.context.TestPropertySource; */ @TestPropertySource(properties = "key1 = local value") @TestPropertySource(properties = "second = local override") -public class LocalInlinedPropertyOverridesInheritedInlinedPropertyTests extends RepeatedTestPropertySourceTests { +class LocalInlinedPropertyOverridesInheritedInlinedPropertyTests extends RepeatedTestPropertySourceTests { @Test @Override - public void test() { + void test() { assertEnvironmentValue("key1", "local value"); assertEnvironmentValue("second", "local override"); assertEnvironmentValue("first", "repeated override"); diff --git a/spring-test/src/test/java/org/springframework/test/context/env/repeatable/LocalInlinedPropertyOverridesMetaInlinedPropertyTests.java b/spring-test/src/test/java/org/springframework/test/context/env/repeatable/LocalInlinedPropertyOverridesMetaInlinedPropertyTests.java index b3d1a79e71..544ec324fa 100644 --- a/spring-test/src/test/java/org/springframework/test/context/env/repeatable/LocalInlinedPropertyOverridesMetaInlinedPropertyTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/env/repeatable/LocalInlinedPropertyOverridesMetaInlinedPropertyTests.java @@ -16,7 +16,7 @@ package org.springframework.test.context.env.repeatable; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.test.context.TestPropertySource; @@ -30,10 +30,10 @@ import org.springframework.test.context.TestPropertySource; */ @TestPropertySource(properties = "enigma = local override") @MetaInlinedTestProperty -public class LocalInlinedPropertyOverridesMetaInlinedPropertyTests extends AbstractRepeatableTestPropertySourceTests { +class LocalInlinedPropertyOverridesMetaInlinedPropertyTests extends AbstractRepeatableTestPropertySourceTests { @Test - public void test() { + void test() { assertEnvironmentValue("enigma", "local override"); } diff --git a/spring-test/src/test/java/org/springframework/test/context/env/repeatable/LocalPropertiesFileAndMetaPropertiesFileTests.java b/spring-test/src/test/java/org/springframework/test/context/env/repeatable/LocalPropertiesFileAndMetaPropertiesFileTests.java index c488ff2bfe..405f92eb78 100644 --- a/spring-test/src/test/java/org/springframework/test/context/env/repeatable/LocalPropertiesFileAndMetaPropertiesFileTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/env/repeatable/LocalPropertiesFileAndMetaPropertiesFileTests.java @@ -21,7 +21,7 @@ import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.test.context.TestPropertySource; import org.springframework.test.context.env.repeatable.LocalPropertiesFileAndMetaPropertiesFileTests.MetaFileTestProperty; @@ -40,10 +40,10 @@ import org.springframework.test.context.env.repeatable.LocalPropertiesFileAndMet */ @TestPropertySource("local.properties") @MetaFileTestProperty -public class LocalPropertiesFileAndMetaPropertiesFileTests extends AbstractRepeatableTestPropertySourceTests { +class LocalPropertiesFileAndMetaPropertiesFileTests extends AbstractRepeatableTestPropertySourceTests { @Test - public void test() { + void test() { assertEnvironmentValue("key1", "local file"); assertEnvironmentValue("key2", "meta file"); } diff --git a/spring-test/src/test/java/org/springframework/test/context/env/repeatable/MetaInlinedPropertyOverridesMetaMetaInlinedPropertyTests.java b/spring-test/src/test/java/org/springframework/test/context/env/repeatable/MetaInlinedPropertyOverridesMetaMetaInlinedPropertyTests.java index eb307400d1..e45ca893c8 100644 --- a/spring-test/src/test/java/org/springframework/test/context/env/repeatable/MetaInlinedPropertyOverridesMetaMetaInlinedPropertyTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/env/repeatable/MetaInlinedPropertyOverridesMetaMetaInlinedPropertyTests.java @@ -16,7 +16,7 @@ package org.springframework.test.context.env.repeatable; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.test.context.TestPropertySource; @@ -29,10 +29,10 @@ import org.springframework.test.context.TestPropertySource; */ @MetaInlinedTestProperty @MetaComposedTestProperty -public class MetaInlinedPropertyOverridesMetaMetaInlinedPropertyTests extends AbstractRepeatableTestPropertySourceTests { +class MetaInlinedPropertyOverridesMetaMetaInlinedPropertyTests extends AbstractRepeatableTestPropertySourceTests { @Test - public void test() { + void test() { assertEnvironmentValue("enigma", "meta"); } diff --git a/spring-test/src/test/java/org/springframework/test/context/env/repeatable/RepeatedTestPropertySourceTests.java b/spring-test/src/test/java/org/springframework/test/context/env/repeatable/RepeatedTestPropertySourceTests.java index cf2de51822..5d9c0a3f0f 100644 --- a/spring-test/src/test/java/org/springframework/test/context/env/repeatable/RepeatedTestPropertySourceTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/env/repeatable/RepeatedTestPropertySourceTests.java @@ -16,7 +16,7 @@ package org.springframework.test.context.env.repeatable; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.test.context.TestPropertySource; @@ -32,10 +32,10 @@ import org.springframework.test.context.TestPropertySource; @TestPropertySource(properties = "first = repeated") @TestPropertySource(properties = "second = repeated") @TestPropertySource(properties = "first = repeated override") -public class RepeatedTestPropertySourceTests extends AbstractRepeatableTestPropertySourceTests { +class RepeatedTestPropertySourceTests extends AbstractRepeatableTestPropertySourceTests { @Test - public void test() { + void test() { assertEnvironmentValue("first", "repeated override"); assertEnvironmentValue("second", "repeated"); } diff --git a/spring-test/src/test/java/org/springframework/test/context/env/repeatable/ReversedExplicitPropertiesFilesRepeatedTestPropertySourceTests.java b/spring-test/src/test/java/org/springframework/test/context/env/repeatable/ReversedExplicitPropertiesFilesRepeatedTestPropertySourceTests.java index 800f86f001..5cf40b40cf 100644 --- a/spring-test/src/test/java/org/springframework/test/context/env/repeatable/ReversedExplicitPropertiesFilesRepeatedTestPropertySourceTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/env/repeatable/ReversedExplicitPropertiesFilesRepeatedTestPropertySourceTests.java @@ -16,7 +16,7 @@ package org.springframework.test.context.env.repeatable; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.test.context.TestPropertySource; @@ -29,10 +29,10 @@ import org.springframework.test.context.TestPropertySource; */ @TestPropertySource("second.properties") @TestPropertySource("first.properties") -public class ReversedExplicitPropertiesFilesRepeatedTestPropertySourceTests extends AbstractRepeatableTestPropertySourceTests { +class ReversedExplicitPropertiesFilesRepeatedTestPropertySourceTests extends AbstractRepeatableTestPropertySourceTests { @Test - public void test() { + void test() { assertEnvironmentValue("alpha", "beta"); assertEnvironmentValue("first", "1111"); assertEnvironmentValue("second", "1111"); diff --git a/spring-test/src/test/java/org/springframework/test/context/env/subpackage/SubpackageInheritedRelativePathPropertiesFileTestPropertySourceTests.java b/spring-test/src/test/java/org/springframework/test/context/env/subpackage/SubpackageInheritedRelativePathPropertiesFileTestPropertySourceTests.java index e626ae46f7..64d32df8bb 100644 --- a/spring-test/src/test/java/org/springframework/test/context/env/subpackage/SubpackageInheritedRelativePathPropertiesFileTestPropertySourceTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/env/subpackage/SubpackageInheritedRelativePathPropertiesFileTestPropertySourceTests.java @@ -27,7 +27,7 @@ import org.springframework.test.context.env.ExplicitPropertiesFileTestPropertySo * @author Sam Brannen * @since 4.1 */ -public class SubpackageInheritedRelativePathPropertiesFileTestPropertySourceTests extends +class SubpackageInheritedRelativePathPropertiesFileTestPropertySourceTests extends ExplicitPropertiesFileTestPropertySourceTests { /* all tests are in superclass */ diff --git a/spring-test/src/test/java/org/springframework/test/context/event/CustomTestEventTests.java b/spring-test/src/test/java/org/springframework/test/context/event/CustomTestEventTests.java index 14c3a11032..96b580c793 100644 --- a/spring-test/src/test/java/org/springframework/test/context/event/CustomTestEventTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/event/CustomTestEventTests.java @@ -20,9 +20,9 @@ import java.lang.reflect.Method; import java.util.ArrayList; import java.util.List; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.context.ApplicationEvent; import org.springframework.context.annotation.Configuration; @@ -31,7 +31,7 @@ import org.springframework.test.context.TestContext; import org.springframework.test.context.TestExecutionListener; import org.springframework.test.context.TestExecutionListeners; import org.springframework.test.context.event.CustomTestEventTests.CustomEventPublishingTestExecutionListener; -import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; import static org.assertj.core.api.Assertions.assertThat; import static org.springframework.test.context.TestExecutionListeners.MergeMode.MERGE_WITH_DEFAULTS; @@ -43,14 +43,14 @@ import static org.springframework.test.context.TestExecutionListeners.MergeMode. * @author Sam Brannen * @since 5.2 */ -@RunWith(SpringRunner.class) +@ExtendWith(SpringExtension.class) @TestExecutionListeners(listeners = CustomEventPublishingTestExecutionListener.class, mergeMode = MERGE_WITH_DEFAULTS) public class CustomTestEventTests { private static final List events = new ArrayList<>(); - @Before + @BeforeEach public void clearEvents() { events.clear(); } diff --git a/spring-test/src/test/java/org/springframework/test/context/event/EventPublishingTestExecutionListenerIntegrationTests.java b/spring-test/src/test/java/org/springframework/test/context/event/EventPublishingTestExecutionListenerIntegrationTests.java index 0207da6892..c3edfeb838 100644 --- a/spring-test/src/test/java/org/springframework/test/context/event/EventPublishingTestExecutionListenerIntegrationTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/event/EventPublishingTestExecutionListenerIntegrationTests.java @@ -23,9 +23,9 @@ import java.util.concurrent.CountDownLatch; import java.util.concurrent.Executor; import java.util.concurrent.TimeUnit; -import org.junit.After; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler; import org.springframework.context.annotation.Bean; @@ -46,7 +46,7 @@ import org.springframework.test.context.event.annotation.BeforeTestClass; import org.springframework.test.context.event.annotation.BeforeTestExecution; import org.springframework.test.context.event.annotation.BeforeTestMethod; import org.springframework.test.context.event.annotation.PrepareTestInstance; -import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.util.ReflectionUtils; import static java.lang.annotation.ElementType.METHOD; @@ -83,7 +83,7 @@ public class EventPublishingTestExecutionListenerIntegrationTests { private final Method traceableTestMethod = ReflectionUtils.findMethod(ExampleTestCase.class, "traceableTest"); - @After + @AfterEach public void closeApplicationContext() { this.testContext.markApplicationContextDirty(null); } @@ -182,7 +182,7 @@ public class EventPublishingTestExecutionListenerIntegrationTests { @interface Traceable { } - @RunWith(SpringRunner.class) + @ExtendWith(SpringExtension.class) @ContextConfiguration(classes = TestEventListenerConfiguration.class) public static class ExampleTestCase { diff --git a/spring-test/src/test/java/org/springframework/test/context/event/EventPublishingTestExecutionListenerTests.java b/spring-test/src/test/java/org/springframework/test/context/event/EventPublishingTestExecutionListenerTests.java index e05fff03fb..a18badd01a 100644 --- a/spring-test/src/test/java/org/springframework/test/context/event/EventPublishingTestExecutionListenerTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/event/EventPublishingTestExecutionListenerTests.java @@ -19,15 +19,14 @@ package org.springframework.test.context.event; import java.util.function.Consumer; import java.util.function.Function; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TestName; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInfo; import org.mockito.ArgumentCaptor; import org.mockito.Captor; import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoSettings; +import org.mockito.quality.Strictness; import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationEvent; @@ -48,14 +47,11 @@ import static org.mockito.Mockito.verify; * @author Sam Brannen * @since 5.2 */ -@RunWith(MockitoJUnitRunner.class) -public class EventPublishingTestExecutionListenerTests { +@MockitoSettings(strictness = Strictness.LENIENT) +class EventPublishingTestExecutionListenerTests { private final EventPublishingTestExecutionListener listener = new EventPublishingTestExecutionListener(); - @Rule - public final TestName testName = new TestName(); - @Mock private TestContext testContext; @@ -66,82 +62,82 @@ public class EventPublishingTestExecutionListenerTests { private ArgumentCaptor> eventFactory; - @Before - public void configureMock() { + @BeforeEach + void configureMock(TestInfo testInfo) { // Force Mockito to invoke the interface default method willCallRealMethod().given(testContext).publishEvent(any()); given(testContext.getApplicationContext()).willReturn(applicationContext); // Only allow events to be published for test methods named "publish*". - given(testContext.hasApplicationContext()).willReturn(testName.getMethodName().startsWith("publish")); + given(testContext.hasApplicationContext()).willReturn(testInfo.getTestMethod().get().getName().startsWith("publish")); } @Test - public void publishBeforeTestClassEvent() { + void publishBeforeTestClassEvent() { assertEvent(BeforeTestClassEvent.class, listener::beforeTestClass); } @Test - public void publishPrepareTestInstanceEvent() { + void publishPrepareTestInstanceEvent() { assertEvent(PrepareTestInstanceEvent.class, listener::prepareTestInstance); } @Test - public void publishBeforeTestMethodEvent() { + void publishBeforeTestMethodEvent() { assertEvent(BeforeTestMethodEvent.class, listener::beforeTestMethod); } @Test - public void publishBeforeTestExecutionEvent() { + void publishBeforeTestExecutionEvent() { assertEvent(BeforeTestExecutionEvent.class, listener::beforeTestExecution); } @Test - public void publishAfterTestExecutionEvent() { + void publishAfterTestExecutionEvent() { assertEvent(AfterTestExecutionEvent.class, listener::afterTestExecution); } @Test - public void publishAfterTestMethodEvent() { + void publishAfterTestMethodEvent() { assertEvent(AfterTestMethodEvent.class, listener::afterTestMethod); } @Test - public void publishAfterTestClassEvent() { + void publishAfterTestClassEvent() { assertEvent(AfterTestClassEvent.class, listener::afterTestClass); } @Test - public void doesNotPublishBeforeTestClassEventIfApplicationContextHasNotBeenLoaded() { + void doesNotPublishBeforeTestClassEventIfApplicationContextHasNotBeenLoaded() { assertNoEvent(BeforeTestClassEvent.class, listener::beforeTestClass); } @Test - public void doesNotPublishPrepareTestInstanceEventIfApplicationContextHasNotBeenLoaded() { + void doesNotPublishPrepareTestInstanceEventIfApplicationContextHasNotBeenLoaded() { assertNoEvent(PrepareTestInstanceEvent.class, listener::prepareTestInstance); } @Test - public void doesNotPublishBeforeTestMethodEventIfApplicationContextHasNotBeenLoaded() { + void doesNotPublishBeforeTestMethodEventIfApplicationContextHasNotBeenLoaded() { assertNoEvent(BeforeTestMethodEvent.class, listener::beforeTestMethod); } @Test - public void doesNotPublishBeforeTestExecutionEventIfApplicationContextHasNotBeenLoaded() { + void doesNotPublishBeforeTestExecutionEventIfApplicationContextHasNotBeenLoaded() { assertNoEvent(BeforeTestExecutionEvent.class, listener::beforeTestExecution); } @Test - public void doesNotPublishAfterTestExecutionEventIfApplicationContextHasNotBeenLoaded() { + void doesNotPublishAfterTestExecutionEventIfApplicationContextHasNotBeenLoaded() { assertNoEvent(AfterTestExecutionEvent.class, listener::afterTestExecution); } @Test - public void doesNotPublishAfterTestMethodEventIfApplicationContextHasNotBeenLoaded() { + void doesNotPublishAfterTestMethodEventIfApplicationContextHasNotBeenLoaded() { assertNoEvent(AfterTestMethodEvent.class, listener::afterTestMethod); } @Test - public void doesNotPublishAfterTestClassEventIfApplicationContextHasNotBeenLoaded() { + void doesNotPublishAfterTestClassEventIfApplicationContextHasNotBeenLoaded() { assertNoEvent(AfterTestClassEvent.class, listener::afterTestClass); } diff --git a/spring-test/src/test/java/org/springframework/test/context/expression/ExpressionUsageTests.java b/spring-test/src/test/java/org/springframework/test/context/expression/ExpressionUsageTests.java index f5cdb57a3d..14f4772d44 100644 --- a/spring-test/src/test/java/org/springframework/test/context/expression/ExpressionUsageTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/expression/ExpressionUsageTests.java @@ -18,13 +18,11 @@ package org.springframework.test.context.expression; import java.util.Properties; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import static org.assertj.core.api.Assertions.assertThat; @@ -32,9 +30,8 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Andy Clement * @author Dave Syer */ -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration -public class ExpressionUsageTests { +@SpringJUnitConfig +class ExpressionUsageTests { @Autowired @Qualifier("derived") @@ -50,7 +47,7 @@ public class ExpressionUsageTests { @Test - public void testSpr5906() throws Exception { + void testSpr5906() throws Exception { // verify the property values have been evaluated as expressions assertThat(props.getProperty("user.name")).isEqualTo("Dave"); assertThat(props.getProperty("username")).isEqualTo("Andy"); @@ -61,7 +58,7 @@ public class ExpressionUsageTests { } @Test - public void testSpr5847() throws Exception { + void testSpr5847() throws Exception { assertThat(andy2.getName()).isEqualTo("Andy"); assertThat(andy.getName()).isEqualTo("Andy"); } diff --git a/spring-test/src/test/java/org/springframework/test/context/groovy/AbsolutePathGroovySpringContextTests.java b/spring-test/src/test/java/org/springframework/test/context/groovy/AbsolutePathGroovySpringContextTests.java index c300c62078..ca99657ced 100644 --- a/spring-test/src/test/java/org/springframework/test/context/groovy/AbsolutePathGroovySpringContextTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/groovy/AbsolutePathGroovySpringContextTests.java @@ -28,7 +28,7 @@ import org.springframework.test.context.ContextConfiguration; * @see RelativePathGroovySpringContextTests */ @ContextConfiguration(locations = "/org/springframework/test/context/groovy/context.groovy", inheritLocations = false) -public class AbsolutePathGroovySpringContextTests extends GroovySpringContextTests { +class AbsolutePathGroovySpringContextTests extends GroovySpringContextTests { /* all tests are in the superclass */ diff --git a/spring-test/src/test/java/org/springframework/test/context/groovy/DefaultScriptDetectionGroovySpringContextTests.java b/spring-test/src/test/java/org/springframework/test/context/groovy/DefaultScriptDetectionGroovySpringContextTests.java index 012080a230..038dc5200e 100644 --- a/spring-test/src/test/java/org/springframework/test/context/groovy/DefaultScriptDetectionGroovySpringContextTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/groovy/DefaultScriptDetectionGroovySpringContextTests.java @@ -16,12 +16,10 @@ package org.springframework.test.context.groovy; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import org.springframework.tests.sample.beans.Employee; import org.springframework.tests.sample.beans.Pet; @@ -35,23 +33,22 @@ import static org.assertj.core.api.Assertions.assertThat; * @since 4.1 * @see DefaultScriptDetectionGroovySpringContextTestsContext */ -@RunWith(SpringJUnit4ClassRunner.class) +@SpringJUnitConfig // Config loaded from DefaultScriptDetectionGroovySpringContextTestsContext.groovy -@ContextConfiguration -public class DefaultScriptDetectionGroovySpringContextTests { +class DefaultScriptDetectionGroovySpringContextTests { @Autowired - private Employee employee; + Employee employee; @Autowired - private Pet pet; + Pet pet; @Autowired - protected String foo; + String foo; @Test - public final void verifyAnnotationAutowiredFields() { + void verifyAnnotationAutowiredFields() { assertThat(this.employee).as("The employee field should have been autowired.").isNotNull(); assertThat(this.employee.getName()).isEqualTo("Dilbert"); diff --git a/spring-test/src/test/java/org/springframework/test/context/groovy/DefaultScriptDetectionXmlSupersedesGroovySpringContextTests.java b/spring-test/src/test/java/org/springframework/test/context/groovy/DefaultScriptDetectionXmlSupersedesGroovySpringContextTests.java index 65c2054fd7..20783ee117 100644 --- a/spring-test/src/test/java/org/springframework/test/context/groovy/DefaultScriptDetectionXmlSupersedesGroovySpringContextTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/groovy/DefaultScriptDetectionXmlSupersedesGroovySpringContextTests.java @@ -16,12 +16,10 @@ package org.springframework.test.context.groovy; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import static org.assertj.core.api.Assertions.assertThat; @@ -32,16 +30,15 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Sam Brannen * @since 4.1 */ -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration -public class DefaultScriptDetectionXmlSupersedesGroovySpringContextTests { +@SpringJUnitConfig +class DefaultScriptDetectionXmlSupersedesGroovySpringContextTests { @Autowired - protected String foo; + String foo; @Test - public final void foo() { + final void foo() { assertThat(this.foo).as("The foo field should have been autowired.").isEqualTo("Foo"); } diff --git a/spring-test/src/test/java/org/springframework/test/context/groovy/GroovyControlGroupTests.java b/spring-test/src/test/java/org/springframework/test/context/groovy/GroovyControlGroupTests.java index 96f9aa0b62..db5995a1d5 100644 --- a/spring-test/src/test/java/org/springframework/test/context/groovy/GroovyControlGroupTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/groovy/GroovyControlGroupTests.java @@ -16,7 +16,7 @@ package org.springframework.test.context.groovy; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.context.ApplicationContext; import org.springframework.context.support.GenericGroovyApplicationContext; @@ -38,11 +38,11 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Sam Brannen * @since 4.1 */ -public class GroovyControlGroupTests { +class GroovyControlGroupTests { @Test @SuppressWarnings("resource") - public void verifyScriptUsingGenericGroovyApplicationContext() { + void verifyScriptUsingGenericGroovyApplicationContext() { ApplicationContext ctx = new GenericGroovyApplicationContext(getClass(), "context.groovy"); String foo = ctx.getBean("foo", String.class); diff --git a/spring-test/src/test/java/org/springframework/test/context/groovy/GroovySpringContextTests.java b/spring-test/src/test/java/org/springframework/test/context/groovy/GroovySpringContextTests.java index 9e6b9d0544..0bfd5900a9 100644 --- a/spring-test/src/test/java/org/springframework/test/context/groovy/GroovySpringContextTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/groovy/GroovySpringContextTests.java @@ -18,15 +18,15 @@ package org.springframework.test.context.groovy; import javax.annotation.Resource; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.BeanNameAware; import org.springframework.beans.factory.InitializingBean; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationContext; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.tests.sample.beans.Employee; import org.springframework.tests.sample.beans.Pet; @@ -39,9 +39,9 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Sam Brannen * @since 4.1 */ -@RunWith(SpringJUnit4ClassRunner.class) +@ExtendWith(SpringExtension.class) @ContextConfiguration("context.groovy") -public class GroovySpringContextTests implements BeanNameAware, InitializingBean { +class GroovySpringContextTests implements BeanNameAware, InitializingBean { private Employee employee; @@ -86,18 +86,18 @@ public class GroovySpringContextTests implements BeanNameAware, InitializingBean @Test - public void verifyBeanNameSet() { + void verifyBeanNameSet() { assertThat(this.beanName.startsWith(getClass().getName())).as("The bean name of this test instance should have been set to the fully qualified class name " + "due to BeanNameAware semantics.").isTrue(); } @Test - public void verifyBeanInitialized() { + void verifyBeanInitialized() { assertThat(this.beanInitialized).as("This test bean should have been initialized due to InitializingBean semantics.").isTrue(); } @Test - public void verifyAnnotationAutowiredFields() { + void verifyAnnotationAutowiredFields() { assertThat(this.nonrequiredLong).as("The nonrequiredLong property should NOT have been autowired.").isNull(); assertThat(this.applicationContext).as("The application context should have been autowired.").isNotNull(); assertThat(this.pet).as("The pet field should have been autowired.").isNotNull(); @@ -105,18 +105,18 @@ public class GroovySpringContextTests implements BeanNameAware, InitializingBean } @Test - public void verifyAnnotationAutowiredMethods() { + void verifyAnnotationAutowiredMethods() { assertThat(this.employee).as("The employee setter method should have been autowired.").isNotNull(); assertThat(this.employee.getName()).isEqualTo("Dilbert"); } @Test - public void verifyResourceAnnotationWiredFields() { + void verifyResourceAnnotationWiredFields() { assertThat(this.foo).as("The foo field should have been wired via @Resource.").isEqualTo("Foo"); } @Test - public void verifyResourceAnnotationWiredMethods() { + void verifyResourceAnnotationWiredMethods() { assertThat(this.bar).as("The bar method should have been wired via @Resource.").isEqualTo("Bar"); } diff --git a/spring-test/src/test/java/org/springframework/test/context/groovy/MixedXmlAndGroovySpringContextTests.java b/spring-test/src/test/java/org/springframework/test/context/groovy/MixedXmlAndGroovySpringContextTests.java index ab735b6143..7d2ecdfe05 100644 --- a/spring-test/src/test/java/org/springframework/test/context/groovy/MixedXmlAndGroovySpringContextTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/groovy/MixedXmlAndGroovySpringContextTests.java @@ -16,12 +16,12 @@ package org.springframework.test.context.groovy; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.tests.sample.beans.Employee; import org.springframework.tests.sample.beans.Pet; @@ -35,25 +35,25 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Sam Brannen * @since 4.1 */ -@RunWith(SpringJUnit4ClassRunner.class) +@ExtendWith(SpringExtension.class) @ContextConfiguration({ "contextA.groovy", "contextB.xml" }) -public class MixedXmlAndGroovySpringContextTests { +class MixedXmlAndGroovySpringContextTests { @Autowired - private Employee employee; + Employee employee; @Autowired - private Pet pet; + Pet pet; @Autowired - protected String foo; + String foo; @Autowired - protected String bar; + String bar; @Test - public final void verifyAnnotationAutowiredFields() { + void verifyAnnotationAutowiredFields() { assertThat(this.employee).as("The employee field should have been autowired.").isNotNull(); assertThat(this.employee.getName()).isEqualTo("Dilbert"); diff --git a/spring-test/src/test/java/org/springframework/test/context/groovy/RelativePathGroovySpringContextTests.java b/spring-test/src/test/java/org/springframework/test/context/groovy/RelativePathGroovySpringContextTests.java index abbac314d7..bef1c2be2b 100644 --- a/spring-test/src/test/java/org/springframework/test/context/groovy/RelativePathGroovySpringContextTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/groovy/RelativePathGroovySpringContextTests.java @@ -28,7 +28,7 @@ import org.springframework.test.context.ContextConfiguration; * @see AbsolutePathGroovySpringContextTests */ @ContextConfiguration(locations = "../groovy/context.groovy", inheritLocations = false) -public class RelativePathGroovySpringContextTests extends GroovySpringContextTests { +class RelativePathGroovySpringContextTests extends GroovySpringContextTests { /* all tests are in the superclass */ diff --git a/spring-test/src/test/java/org/springframework/test/context/hierarchies/meta/MetaHierarchyLevelOneTests.java b/spring-test/src/test/java/org/springframework/test/context/hierarchies/meta/MetaHierarchyLevelOneTests.java index ad22376c3f..1afb623482 100644 --- a/spring-test/src/test/java/org/springframework/test/context/hierarchies/meta/MetaHierarchyLevelOneTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/hierarchies/meta/MetaHierarchyLevelOneTests.java @@ -16,11 +16,11 @@ package org.springframework.test.context.hierarchies.meta; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; import static org.assertj.core.api.Assertions.assertThat; @@ -28,16 +28,16 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Sam Brannen * @since 4.0.3 */ -@RunWith(SpringJUnit4ClassRunner.class) +@ExtendWith(SpringExtension.class) @MetaMetaContextHierarchyConfig -public class MetaHierarchyLevelOneTests { +class MetaHierarchyLevelOneTests { @Autowired private String foo; @Test - public void foo() { + void foo() { assertThat(foo).isEqualTo("Dev Foo"); } diff --git a/spring-test/src/test/java/org/springframework/test/context/hierarchies/meta/MetaHierarchyLevelTwoTests.java b/spring-test/src/test/java/org/springframework/test/context/hierarchies/meta/MetaHierarchyLevelTwoTests.java index f1760442af..2d5b29b957 100644 --- a/spring-test/src/test/java/org/springframework/test/context/hierarchies/meta/MetaHierarchyLevelTwoTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/hierarchies/meta/MetaHierarchyLevelTwoTests.java @@ -16,7 +16,7 @@ package org.springframework.test.context.hierarchies.meta; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationContext; @@ -34,14 +34,14 @@ import static org.assertj.core.api.Assertions.assertThat; */ @ContextConfiguration @ActiveProfiles("prod") -public class MetaHierarchyLevelTwoTests extends MetaHierarchyLevelOneTests { +class MetaHierarchyLevelTwoTests extends MetaHierarchyLevelOneTests { @Configuration @Profile("prod") static class Config { @Bean - public String bar() { + String bar() { return "Prod Bar"; } } @@ -55,12 +55,12 @@ public class MetaHierarchyLevelTwoTests extends MetaHierarchyLevelOneTests { @Test - public void bar() { + void bar() { assertThat(bar).isEqualTo("Prod Bar"); } @Test - public void contextHierarchy() { + void contextHierarchy() { assertThat(context).as("child ApplicationContext").isNotNull(); assertThat(context.getParent()).as("parent ApplicationContext").isNotNull(); assertThat(context.getParent().getParent()).as("grandparent ApplicationContext").isNull(); diff --git a/spring-test/src/test/java/org/springframework/test/context/hierarchies/standard/ClassHierarchyWithMergedConfigLevelOneTests.java b/spring-test/src/test/java/org/springframework/test/context/hierarchies/standard/ClassHierarchyWithMergedConfigLevelOneTests.java index 72f4b93451..21a3985895 100644 --- a/spring-test/src/test/java/org/springframework/test/context/hierarchies/standard/ClassHierarchyWithMergedConfigLevelOneTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/hierarchies/standard/ClassHierarchyWithMergedConfigLevelOneTests.java @@ -16,8 +16,8 @@ package org.springframework.test.context.hierarchies.standard; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; @@ -26,7 +26,7 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.ContextHierarchy; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; import static org.assertj.core.api.Assertions.assertThat; @@ -34,19 +34,19 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Sam Brannen * @since 3.2.2 */ -@RunWith(SpringJUnit4ClassRunner.class) +@ExtendWith(SpringExtension.class) @ContextHierarchy({ // @ContextConfiguration(name = "parent", classes = ClassHierarchyWithMergedConfigLevelOneTests.AppConfig.class),// @ContextConfiguration(name = "child", classes = ClassHierarchyWithMergedConfigLevelOneTests.UserConfig.class) // }) -public class ClassHierarchyWithMergedConfigLevelOneTests { +class ClassHierarchyWithMergedConfigLevelOneTests { @Configuration static class AppConfig { @Bean - public String parent() { + String parent() { return "parent"; } } @@ -59,12 +59,12 @@ public class ClassHierarchyWithMergedConfigLevelOneTests { @Bean - public String user() { + String user() { return appConfig.parent() + " + user"; } @Bean - public String beanFromUserConfig() { + String beanFromUserConfig() { return "from UserConfig"; } } @@ -85,7 +85,7 @@ public class ClassHierarchyWithMergedConfigLevelOneTests { @Test - public void loadContextHierarchy() { + void loadContextHierarchy() { assertThat(context).as("child ApplicationContext").isNotNull(); assertThat(context.getParent()).as("parent ApplicationContext").isNotNull(); assertThat(context.getParent().getParent()).as("grandparent ApplicationContext").isNull(); diff --git a/spring-test/src/test/java/org/springframework/test/context/hierarchies/standard/ClassHierarchyWithMergedConfigLevelTwoTests.java b/spring-test/src/test/java/org/springframework/test/context/hierarchies/standard/ClassHierarchyWithMergedConfigLevelTwoTests.java index 7293632f5b..221b1668b6 100644 --- a/spring-test/src/test/java/org/springframework/test/context/hierarchies/standard/ClassHierarchyWithMergedConfigLevelTwoTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/hierarchies/standard/ClassHierarchyWithMergedConfigLevelTwoTests.java @@ -16,15 +16,15 @@ package org.springframework.test.context.hierarchies.standard; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.ContextHierarchy; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; import static org.assertj.core.api.Assertions.assertThat; @@ -32,9 +32,9 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Sam Brannen * @since 3.2.2 */ -@RunWith(SpringJUnit4ClassRunner.class) +@ExtendWith(SpringExtension.class) @ContextHierarchy(@ContextConfiguration(name = "child", classes = ClassHierarchyWithMergedConfigLevelTwoTests.OrderConfig.class)) -public class ClassHierarchyWithMergedConfigLevelTwoTests extends ClassHierarchyWithMergedConfigLevelOneTests { +class ClassHierarchyWithMergedConfigLevelTwoTests extends ClassHierarchyWithMergedConfigLevelOneTests { @Configuration static class OrderConfig { @@ -43,7 +43,7 @@ public class ClassHierarchyWithMergedConfigLevelTwoTests extends ClassHierarchyW private ClassHierarchyWithMergedConfigLevelOneTests.UserConfig userConfig; @Bean - public String order() { + String order() { return userConfig.user() + " + order"; } } @@ -55,7 +55,7 @@ public class ClassHierarchyWithMergedConfigLevelTwoTests extends ClassHierarchyW @Test @Override - public void loadContextHierarchy() { + void loadContextHierarchy() { super.loadContextHierarchy(); assertThat(order).isEqualTo("parent + user + order"); } diff --git a/spring-test/src/test/java/org/springframework/test/context/hierarchies/standard/ClassHierarchyWithOverriddenConfigLevelTwoTests.java b/spring-test/src/test/java/org/springframework/test/context/hierarchies/standard/ClassHierarchyWithOverriddenConfigLevelTwoTests.java index 8e69789f3c..5705d66265 100644 --- a/spring-test/src/test/java/org/springframework/test/context/hierarchies/standard/ClassHierarchyWithOverriddenConfigLevelTwoTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/hierarchies/standard/ClassHierarchyWithOverriddenConfigLevelTwoTests.java @@ -16,15 +16,15 @@ package org.springframework.test.context.hierarchies.standard; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.ContextHierarchy; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; import static org.assertj.core.api.Assertions.assertThat; @@ -32,9 +32,9 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Sam Brannen * @since 3.2.2 */ -@RunWith(SpringJUnit4ClassRunner.class) +@ExtendWith(SpringExtension.class) @ContextHierarchy(@ContextConfiguration(name = "child", classes = ClassHierarchyWithOverriddenConfigLevelTwoTests.TestUserConfig.class, inheritLocations = false)) -public class ClassHierarchyWithOverriddenConfigLevelTwoTests extends ClassHierarchyWithMergedConfigLevelOneTests { +class ClassHierarchyWithOverriddenConfigLevelTwoTests extends ClassHierarchyWithMergedConfigLevelOneTests { @Configuration static class TestUserConfig { @@ -44,12 +44,12 @@ public class ClassHierarchyWithOverriddenConfigLevelTwoTests extends ClassHierar @Bean - public String user() { + String user() { return appConfig.parent() + " + test user"; } @Bean - public String beanFromTestUserConfig() { + String beanFromTestUserConfig() { return "from TestUserConfig"; } } @@ -61,7 +61,7 @@ public class ClassHierarchyWithOverriddenConfigLevelTwoTests extends ClassHierar @Test @Override - public void loadContextHierarchy() { + void loadContextHierarchy() { assertThat(context).as("child ApplicationContext").isNotNull(); assertThat(context.getParent()).as("parent ApplicationContext").isNotNull(); assertThat(context.getParent().getParent()).as("grandparent ApplicationContext").isNull(); diff --git a/spring-test/src/test/java/org/springframework/test/context/hierarchies/standard/DirtiesContextWithContextHierarchyTests.java b/spring-test/src/test/java/org/springframework/test/context/hierarchies/standard/DirtiesContextWithContextHierarchyTests.java index ad7e431935..0662049ca5 100644 --- a/spring-test/src/test/java/org/springframework/test/context/hierarchies/standard/DirtiesContextWithContextHierarchyTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/hierarchies/standard/DirtiesContextWithContextHierarchyTests.java @@ -16,11 +16,12 @@ package org.springframework.test.context.hierarchies.standard; -import org.junit.Before; -import org.junit.FixMethodOrder; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.MethodSorters; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.MethodOrderer; +import org.junit.jupiter.api.Order; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestMethodOrder; +import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationContext; @@ -30,7 +31,7 @@ import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.annotation.DirtiesContext.HierarchyMode; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.ContextHierarchy; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; import static org.assertj.core.api.Assertions.assertThat; @@ -39,40 +40,18 @@ import static org.assertj.core.api.Assertions.assertThat; * in conjunction with context hierarchies configured via {@link ContextHierarchy}. * *

Note that correct method execution order is essential, thus the use of - * {@link FixMethodOrder}. + * {@link TestMethodOrder @TestMethodOrder}. * * @author Sam Brannen * @since 3.2.2 */ -@RunWith(SpringJUnit4ClassRunner.class) -@ContextHierarchy({ @ContextConfiguration(classes = DirtiesContextWithContextHierarchyTests.ParentConfig.class), - @ContextConfiguration(classes = DirtiesContextWithContextHierarchyTests.ChildConfig.class) }) -@FixMethodOrder(MethodSorters.NAME_ASCENDING) -public class DirtiesContextWithContextHierarchyTests { - - @Configuration - static class ParentConfig { - - @Bean - public StringBuffer foo() { - return new StringBuffer("foo"); - } - - @Bean - public StringBuffer baz() { - return new StringBuffer("baz-parent"); - } - } - - @Configuration - static class ChildConfig { - - @Bean - public StringBuffer baz() { - return new StringBuffer("baz-child"); - } - } - +@ExtendWith(SpringExtension.class) +@ContextHierarchy({ + @ContextConfiguration(classes = DirtiesContextWithContextHierarchyTests.ParentConfig.class), + @ContextConfiguration(classes = DirtiesContextWithContextHierarchyTests.ChildConfig.class) +}) +@TestMethodOrder(MethodOrderer.OrderAnnotation.class) +class DirtiesContextWithContextHierarchyTests { @Autowired private StringBuffer foo; @@ -84,7 +63,42 @@ public class DirtiesContextWithContextHierarchyTests { private ApplicationContext context; - // ------------------------------------------------------------------------- + @BeforeEach + void verifyContextHierarchy() { + assertThat(context).as("child ApplicationContext").isNotNull(); + assertThat(context.getParent()).as("parent ApplicationContext").isNotNull(); + assertThat(context.getParent().getParent()).as("grandparent ApplicationContext").isNull(); + } + + @Test + @Order(1) + void verifyOriginalStateAndDirtyContexts() { + assertOriginalState(); + reverseStringBuffers(); + } + + @Test + @Order(2) + @DirtiesContext + void verifyContextsWereDirtiedAndTriggerExhaustiveCacheClearing() { + assertDirtyParentContext(); + assertDirtyChildContext(); + } + + @Test + @Order(3) + @DirtiesContext(hierarchyMode = HierarchyMode.CURRENT_LEVEL) + void verifyOriginalStateWasReinstatedAndDirtyContextsAndTriggerCurrentLevelCacheClearing() { + assertOriginalState(); + reverseStringBuffers(); + } + + @Test + @Order(4) + void verifyParentContextIsStillDirtyButChildContextHasBeenReinstated() { + assertDirtyParentContext(); + assertCleanChildContext(); + } private void reverseStringBuffers() { foo.reverse(); @@ -112,39 +126,28 @@ public class DirtiesContextWithContextHierarchyTests { assertThat(baz.toString()).isEqualTo("dlihc-zab"); } - // ------------------------------------------------------------------------- - @Before - public void verifyContextHierarchy() { - assertThat(context).as("child ApplicationContext").isNotNull(); - assertThat(context.getParent()).as("parent ApplicationContext").isNotNull(); - assertThat(context.getParent().getParent()).as("grandparent ApplicationContext").isNull(); + @Configuration + static class ParentConfig { + + @Bean + StringBuffer foo() { + return new StringBuffer("foo"); + } + + @Bean + StringBuffer baz() { + return new StringBuffer("baz-parent"); + } } - @Test - public void test1_verifyOriginalStateAndDirtyContexts() { - assertOriginalState(); - reverseStringBuffers(); - } + @Configuration + static class ChildConfig { - @Test - @DirtiesContext - public void test2_verifyContextsWereDirtiedAndTriggerExhaustiveCacheClearing() { - assertDirtyParentContext(); - assertDirtyChildContext(); - } - - @Test - @DirtiesContext(hierarchyMode = HierarchyMode.CURRENT_LEVEL) - public void test3_verifyOriginalStateWasReinstatedAndDirtyContextsAndTriggerCurrentLevelCacheClearing() { - assertOriginalState(); - reverseStringBuffers(); - } - - @Test - public void test4_verifyParentContextIsStillDirtyButChildContextHasBeenReinstated() { - assertDirtyParentContext(); - assertCleanChildContext(); + @Bean + StringBuffer baz() { + return new StringBuffer("baz-child"); + } } } diff --git a/spring-test/src/test/java/org/springframework/test/context/hierarchies/standard/SingleTestClassWithSingleLevelContextHierarchyTests.java b/spring-test/src/test/java/org/springframework/test/context/hierarchies/standard/SingleTestClassWithSingleLevelContextHierarchyTests.java index ecc833fb13..83e1bb63d4 100644 --- a/spring-test/src/test/java/org/springframework/test/context/hierarchies/standard/SingleTestClassWithSingleLevelContextHierarchyTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/hierarchies/standard/SingleTestClassWithSingleLevelContextHierarchyTests.java @@ -16,8 +16,8 @@ package org.springframework.test.context.hierarchies.standard; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationContext; @@ -25,7 +25,7 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.ContextHierarchy; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; import static org.assertj.core.api.Assertions.assertThat; @@ -33,15 +33,15 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Sam Brannen * @since 3.2.2 */ -@RunWith(SpringJUnit4ClassRunner.class) +@ExtendWith(SpringExtension.class) @ContextHierarchy(@ContextConfiguration) -public class SingleTestClassWithSingleLevelContextHierarchyTests { +class SingleTestClassWithSingleLevelContextHierarchyTests { @Configuration static class Config { @Bean - public String foo() { + String foo() { return "foo"; } } @@ -55,7 +55,7 @@ public class SingleTestClassWithSingleLevelContextHierarchyTests { @Test - public void loadContextHierarchy() { + void loadContextHierarchy() { assertThat(context).as("child ApplicationContext").isNotNull(); assertThat(context.getParent()).as("parent ApplicationContext").isNull(); assertThat(foo).isEqualTo("foo"); diff --git a/spring-test/src/test/java/org/springframework/test/context/hierarchies/standard/SingleTestClassWithTwoLevelContextHierarchyAndMixedConfigTypesTests.java b/spring-test/src/test/java/org/springframework/test/context/hierarchies/standard/SingleTestClassWithTwoLevelContextHierarchyAndMixedConfigTypesTests.java index bd9e61b10a..06d6c0607e 100644 --- a/spring-test/src/test/java/org/springframework/test/context/hierarchies/standard/SingleTestClassWithTwoLevelContextHierarchyAndMixedConfigTypesTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/hierarchies/standard/SingleTestClassWithTwoLevelContextHierarchyAndMixedConfigTypesTests.java @@ -16,8 +16,8 @@ package org.springframework.test.context.hierarchies.standard; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationContext; @@ -25,7 +25,7 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.ContextHierarchy; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; import static org.assertj.core.api.Assertions.assertThat; @@ -33,22 +33,22 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Sam Brannen * @since 3.2.2 */ -@RunWith(SpringJUnit4ClassRunner.class) +@ExtendWith(SpringExtension.class) @ContextHierarchy({ @ContextConfiguration(classes = SingleTestClassWithTwoLevelContextHierarchyAndMixedConfigTypesTests.ParentConfig.class), @ContextConfiguration("SingleTestClassWithTwoLevelContextHierarchyAndMixedConfigTypesTests-ChildConfig.xml") }) -public class SingleTestClassWithTwoLevelContextHierarchyAndMixedConfigTypesTests { +class SingleTestClassWithTwoLevelContextHierarchyAndMixedConfigTypesTests { @Configuration static class ParentConfig { @Bean - public String foo() { + String foo() { return "foo"; } @Bean - public String baz() { + String baz() { return "baz-parent"; } } @@ -68,7 +68,7 @@ public class SingleTestClassWithTwoLevelContextHierarchyAndMixedConfigTypesTests @Test - public void loadContextHierarchy() { + void loadContextHierarchy() { assertThat(context).as("child ApplicationContext").isNotNull(); assertThat(context.getParent()).as("parent ApplicationContext").isNotNull(); assertThat(context.getParent().getParent()).as("grandparent ApplicationContext").isNull(); diff --git a/spring-test/src/test/java/org/springframework/test/context/hierarchies/standard/SingleTestClassWithTwoLevelContextHierarchyTests.java b/spring-test/src/test/java/org/springframework/test/context/hierarchies/standard/SingleTestClassWithTwoLevelContextHierarchyTests.java index 39592972fa..56bbaa3085 100644 --- a/spring-test/src/test/java/org/springframework/test/context/hierarchies/standard/SingleTestClassWithTwoLevelContextHierarchyTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/hierarchies/standard/SingleTestClassWithTwoLevelContextHierarchyTests.java @@ -16,8 +16,8 @@ package org.springframework.test.context.hierarchies.standard; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationContext; @@ -25,7 +25,7 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.ContextHierarchy; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; import static org.assertj.core.api.Assertions.assertThat; @@ -33,7 +33,7 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Sam Brannen * @since 3.2.2 */ -@RunWith(SpringJUnit4ClassRunner.class) +@ExtendWith(SpringExtension.class) @ContextHierarchy({ @ContextConfiguration(classes = SingleTestClassWithTwoLevelContextHierarchyTests.ParentConfig.class), @ContextConfiguration(classes = SingleTestClassWithTwoLevelContextHierarchyTests.ChildConfig.class) }) @@ -43,12 +43,12 @@ public class SingleTestClassWithTwoLevelContextHierarchyTests { public static class ParentConfig { @Bean - public String foo() { + String foo() { return "foo"; } @Bean - public String baz() { + String baz() { return "baz-parent"; } } @@ -57,12 +57,12 @@ public class SingleTestClassWithTwoLevelContextHierarchyTests { public static class ChildConfig { @Bean - public String bar() { + String bar() { return "bar"; } @Bean - public String baz() { + String baz() { return "baz-child"; } } @@ -82,7 +82,7 @@ public class SingleTestClassWithTwoLevelContextHierarchyTests { @Test - public void loadContextHierarchy() { + void loadContextHierarchy() { assertThat(context).as("child ApplicationContext").isNotNull(); assertThat(context.getParent()).as("parent ApplicationContext").isNotNull(); assertThat(context.getParent().getParent()).as("grandparent ApplicationContext").isNull(); diff --git a/spring-test/src/test/java/org/springframework/test/context/hierarchies/standard/TestHierarchyLevelOneWithBareContextConfigurationInSubclassTests.java b/spring-test/src/test/java/org/springframework/test/context/hierarchies/standard/TestHierarchyLevelOneWithBareContextConfigurationInSubclassTests.java index 0c238717da..5ffda72cb4 100644 --- a/spring-test/src/test/java/org/springframework/test/context/hierarchies/standard/TestHierarchyLevelOneWithBareContextConfigurationInSubclassTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/hierarchies/standard/TestHierarchyLevelOneWithBareContextConfigurationInSubclassTests.java @@ -16,8 +16,8 @@ package org.springframework.test.context.hierarchies.standard; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationContext; @@ -25,7 +25,7 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.ContextHierarchy; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; import static org.assertj.core.api.Assertions.assertThat; @@ -33,20 +33,20 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Sam Brannen * @since 3.2.2 */ -@RunWith(SpringJUnit4ClassRunner.class) +@ExtendWith(SpringExtension.class) @ContextHierarchy(@ContextConfiguration) -public class TestHierarchyLevelOneWithBareContextConfigurationInSubclassTests { +class TestHierarchyLevelOneWithBareContextConfigurationInSubclassTests { @Configuration static class Config { @Bean - public String foo() { + String foo() { return "foo-level-1"; } @Bean - public String bar() { + String bar() { return "bar"; } } @@ -63,7 +63,7 @@ public class TestHierarchyLevelOneWithBareContextConfigurationInSubclassTests { @Test - public void loadContextHierarchy() { + void loadContextHierarchy() { assertThat(context).as("child ApplicationContext").isNotNull(); assertThat(context.getParent()).as("parent ApplicationContext").isNull(); assertThat(foo).isEqualTo("foo-level-1"); diff --git a/spring-test/src/test/java/org/springframework/test/context/hierarchies/standard/TestHierarchyLevelOneWithBareContextConfigurationInSuperclassTests.java b/spring-test/src/test/java/org/springframework/test/context/hierarchies/standard/TestHierarchyLevelOneWithBareContextConfigurationInSuperclassTests.java index cbcab54b39..41e1d10a8d 100644 --- a/spring-test/src/test/java/org/springframework/test/context/hierarchies/standard/TestHierarchyLevelOneWithBareContextConfigurationInSuperclassTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/hierarchies/standard/TestHierarchyLevelOneWithBareContextConfigurationInSuperclassTests.java @@ -16,15 +16,15 @@ package org.springframework.test.context.hierarchies.standard; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; import static org.assertj.core.api.Assertions.assertThat; @@ -32,20 +32,20 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Sam Brannen * @since 3.2.2 */ -@RunWith(SpringJUnit4ClassRunner.class) +@ExtendWith(SpringExtension.class) @ContextConfiguration -public class TestHierarchyLevelOneWithBareContextConfigurationInSuperclassTests { +class TestHierarchyLevelOneWithBareContextConfigurationInSuperclassTests { @Configuration static class Config { @Bean - public String foo() { + String foo() { return "foo-level-1"; } @Bean - public String bar() { + String bar() { return "bar"; } } @@ -62,7 +62,7 @@ public class TestHierarchyLevelOneWithBareContextConfigurationInSuperclassTests @Test - public void loadContextHierarchy() { + void loadContextHierarchy() { assertThat(context).as("child ApplicationContext").isNotNull(); assertThat(context.getParent()).as("parent ApplicationContext").isNull(); assertThat(foo).isEqualTo("foo-level-1"); diff --git a/spring-test/src/test/java/org/springframework/test/context/hierarchies/standard/TestHierarchyLevelOneWithSingleLevelContextHierarchyTests.java b/spring-test/src/test/java/org/springframework/test/context/hierarchies/standard/TestHierarchyLevelOneWithSingleLevelContextHierarchyTests.java index e84ce142b5..46e808e4b6 100644 --- a/spring-test/src/test/java/org/springframework/test/context/hierarchies/standard/TestHierarchyLevelOneWithSingleLevelContextHierarchyTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/hierarchies/standard/TestHierarchyLevelOneWithSingleLevelContextHierarchyTests.java @@ -16,8 +16,8 @@ package org.springframework.test.context.hierarchies.standard; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationContext; @@ -25,7 +25,7 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.ContextHierarchy; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; import static org.assertj.core.api.Assertions.assertThat; @@ -33,20 +33,20 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Sam Brannen * @since 3.2.2 */ -@RunWith(SpringJUnit4ClassRunner.class) +@ExtendWith(SpringExtension.class) @ContextHierarchy(@ContextConfiguration) -public class TestHierarchyLevelOneWithSingleLevelContextHierarchyTests { +class TestHierarchyLevelOneWithSingleLevelContextHierarchyTests { @Configuration static class Config { @Bean - public String foo() { + String foo() { return "foo-level-1"; } @Bean - public String bar() { + String bar() { return "bar"; } } @@ -63,7 +63,7 @@ public class TestHierarchyLevelOneWithSingleLevelContextHierarchyTests { @Test - public void loadContextHierarchy() { + void loadContextHierarchy() { assertThat(context).as("child ApplicationContext").isNotNull(); assertThat(context.getParent()).as("parent ApplicationContext").isNull(); assertThat(foo).isEqualTo("foo-level-1"); diff --git a/spring-test/src/test/java/org/springframework/test/context/hierarchies/standard/TestHierarchyLevelTwoWithBareContextConfigurationInSubclassTests.java b/spring-test/src/test/java/org/springframework/test/context/hierarchies/standard/TestHierarchyLevelTwoWithBareContextConfigurationInSubclassTests.java index b29da74181..904e6991b9 100644 --- a/spring-test/src/test/java/org/springframework/test/context/hierarchies/standard/TestHierarchyLevelTwoWithBareContextConfigurationInSubclassTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/hierarchies/standard/TestHierarchyLevelTwoWithBareContextConfigurationInSubclassTests.java @@ -16,15 +16,15 @@ package org.springframework.test.context.hierarchies.standard; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; import static org.assertj.core.api.Assertions.assertThat; @@ -32,21 +32,21 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Sam Brannen * @since 3.2.2 */ -@RunWith(SpringJUnit4ClassRunner.class) +@ExtendWith(SpringExtension.class) @ContextConfiguration -public class TestHierarchyLevelTwoWithBareContextConfigurationInSubclassTests extends +class TestHierarchyLevelTwoWithBareContextConfigurationInSubclassTests extends TestHierarchyLevelOneWithBareContextConfigurationInSubclassTests { @Configuration static class Config { @Bean - public String foo() { + String foo() { return "foo-level-2"; } @Bean - public String baz() { + String baz() { return "baz"; } } @@ -67,7 +67,7 @@ public class TestHierarchyLevelTwoWithBareContextConfigurationInSubclassTests ex @Test @Override - public void loadContextHierarchy() { + void loadContextHierarchy() { assertThat(context).as("child ApplicationContext").isNotNull(); assertThat(context.getParent()).as("parent ApplicationContext").isNotNull(); assertThat(context.getParent().getParent()).as("grandparent ApplicationContext").isNull(); diff --git a/spring-test/src/test/java/org/springframework/test/context/hierarchies/standard/TestHierarchyLevelTwoWithBareContextConfigurationInSuperclassTests.java b/spring-test/src/test/java/org/springframework/test/context/hierarchies/standard/TestHierarchyLevelTwoWithBareContextConfigurationInSuperclassTests.java index 34518a62f5..46b6d20523 100644 --- a/spring-test/src/test/java/org/springframework/test/context/hierarchies/standard/TestHierarchyLevelTwoWithBareContextConfigurationInSuperclassTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/hierarchies/standard/TestHierarchyLevelTwoWithBareContextConfigurationInSuperclassTests.java @@ -16,8 +16,8 @@ package org.springframework.test.context.hierarchies.standard; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationContext; @@ -25,7 +25,7 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.ContextHierarchy; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; import static org.assertj.core.api.Assertions.assertThat; @@ -33,21 +33,21 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Sam Brannen * @since 3.2.2 */ -@RunWith(SpringJUnit4ClassRunner.class) +@ExtendWith(SpringExtension.class) @ContextHierarchy(@ContextConfiguration) -public class TestHierarchyLevelTwoWithBareContextConfigurationInSuperclassTests extends +class TestHierarchyLevelTwoWithBareContextConfigurationInSuperclassTests extends TestHierarchyLevelOneWithBareContextConfigurationInSuperclassTests { @Configuration static class Config { @Bean - public String foo() { + String foo() { return "foo-level-2"; } @Bean - public String baz() { + String baz() { return "baz"; } } @@ -68,7 +68,7 @@ public class TestHierarchyLevelTwoWithBareContextConfigurationInSuperclassTests @Test @Override - public void loadContextHierarchy() { + void loadContextHierarchy() { assertThat(context).as("child ApplicationContext").isNotNull(); assertThat(context.getParent()).as("parent ApplicationContext").isNotNull(); assertThat(context.getParent().getParent()).as("grandparent ApplicationContext").isNull(); diff --git a/spring-test/src/test/java/org/springframework/test/context/hierarchies/standard/TestHierarchyLevelTwoWithSingleLevelContextHierarchyAndMixedConfigTypesTests.java b/spring-test/src/test/java/org/springframework/test/context/hierarchies/standard/TestHierarchyLevelTwoWithSingleLevelContextHierarchyAndMixedConfigTypesTests.java index 537168dda6..d9ff5786c2 100644 --- a/spring-test/src/test/java/org/springframework/test/context/hierarchies/standard/TestHierarchyLevelTwoWithSingleLevelContextHierarchyAndMixedConfigTypesTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/hierarchies/standard/TestHierarchyLevelTwoWithSingleLevelContextHierarchyAndMixedConfigTypesTests.java @@ -16,14 +16,14 @@ package org.springframework.test.context.hierarchies.standard; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationContext; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.ContextHierarchy; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; import static org.assertj.core.api.Assertions.assertThat; @@ -31,9 +31,9 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Sam Brannen * @since 3.2.2 */ -@RunWith(SpringJUnit4ClassRunner.class) +@ExtendWith(SpringExtension.class) @ContextHierarchy(@ContextConfiguration) -public class TestHierarchyLevelTwoWithSingleLevelContextHierarchyAndMixedConfigTypesTests extends +class TestHierarchyLevelTwoWithSingleLevelContextHierarchyAndMixedConfigTypesTests extends TestHierarchyLevelOneWithSingleLevelContextHierarchyTests { @Autowired @@ -51,7 +51,7 @@ public class TestHierarchyLevelTwoWithSingleLevelContextHierarchyAndMixedConfigT @Test @Override - public void loadContextHierarchy() { + void loadContextHierarchy() { assertThat(context).as("child ApplicationContext").isNotNull(); assertThat(context.getParent()).as("parent ApplicationContext").isNotNull(); assertThat(context.getParent().getParent()).as("grandparent ApplicationContext").isNull(); diff --git a/spring-test/src/test/java/org/springframework/test/context/hierarchies/standard/TestHierarchyLevelTwoWithSingleLevelContextHierarchyTests.java b/spring-test/src/test/java/org/springframework/test/context/hierarchies/standard/TestHierarchyLevelTwoWithSingleLevelContextHierarchyTests.java index 00ac6a4ac9..d9971ea641 100644 --- a/spring-test/src/test/java/org/springframework/test/context/hierarchies/standard/TestHierarchyLevelTwoWithSingleLevelContextHierarchyTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/hierarchies/standard/TestHierarchyLevelTwoWithSingleLevelContextHierarchyTests.java @@ -16,8 +16,8 @@ package org.springframework.test.context.hierarchies.standard; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationContext; @@ -25,7 +25,7 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.ContextHierarchy; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; import static org.assertj.core.api.Assertions.assertThat; @@ -33,21 +33,21 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Sam Brannen * @since 3.2.2 */ -@RunWith(SpringJUnit4ClassRunner.class) +@ExtendWith(SpringExtension.class) @ContextHierarchy(@ContextConfiguration) -public class TestHierarchyLevelTwoWithSingleLevelContextHierarchyTests extends +class TestHierarchyLevelTwoWithSingleLevelContextHierarchyTests extends TestHierarchyLevelOneWithSingleLevelContextHierarchyTests { @Configuration static class Config { @Bean - public String foo() { + String foo() { return "foo-level-2"; } @Bean - public String baz() { + String baz() { return "baz"; } } @@ -68,7 +68,7 @@ public class TestHierarchyLevelTwoWithSingleLevelContextHierarchyTests extends @Test @Override - public void loadContextHierarchy() { + void loadContextHierarchy() { assertThat(context).as("child ApplicationContext").isNotNull(); assertThat(context.getParent()).as("parent ApplicationContext").isNotNull(); assertThat(foo).isEqualTo("foo-level-2"); diff --git a/spring-test/src/test/java/org/springframework/test/context/hierarchies/web/ControllerIntegrationTests.java b/spring-test/src/test/java/org/springframework/test/context/hierarchies/web/ControllerIntegrationTests.java index 55dca366c1..c9a689f1ac 100644 --- a/spring-test/src/test/java/org/springframework/test/context/hierarchies/web/ControllerIntegrationTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/hierarchies/web/ControllerIntegrationTests.java @@ -18,8 +18,8 @@ package org.springframework.test.context.hierarchies.web; import javax.servlet.ServletContext; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationContext; @@ -29,7 +29,7 @@ import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.ContextHierarchy; import org.springframework.test.context.hierarchies.web.ControllerIntegrationTests.AppConfig; import org.springframework.test.context.hierarchies.web.ControllerIntegrationTests.WebConfig; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.test.context.web.WebAppConfiguration; import org.springframework.web.context.WebApplicationContext; @@ -39,20 +39,20 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Sam Brannen * @since 3.2.2 */ -@RunWith(SpringJUnit4ClassRunner.class) +@ExtendWith(SpringExtension.class) @WebAppConfiguration @ContextHierarchy({ // @ContextConfiguration(name = "root", classes = AppConfig.class), @ContextConfiguration(name = "dispatcher", classes = WebConfig.class) // }) -public class ControllerIntegrationTests { +class ControllerIntegrationTests { @Configuration static class AppConfig { @Bean - public String foo() { + String foo() { return "foo"; } } @@ -61,7 +61,7 @@ public class ControllerIntegrationTests { static class WebConfig { @Bean - public String bar() { + String bar() { return "bar"; } } @@ -80,7 +80,7 @@ public class ControllerIntegrationTests { @Test - public void verifyRootWacSupport() { + void verifyRootWacSupport() { assertThat(foo).isEqualTo("foo"); assertThat(bar).isEqualTo("bar"); diff --git a/spring-test/src/test/java/org/springframework/test/context/hierarchies/web/DispatcherWacRootWacEarTests.java b/spring-test/src/test/java/org/springframework/test/context/hierarchies/web/DispatcherWacRootWacEarTests.java index 411ca7fbe6..bb48aefa72 100644 --- a/spring-test/src/test/java/org/springframework/test/context/hierarchies/web/DispatcherWacRootWacEarTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/hierarchies/web/DispatcherWacRootWacEarTests.java @@ -18,8 +18,8 @@ package org.springframework.test.context.hierarchies.web; import javax.servlet.ServletContext; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationContext; @@ -49,22 +49,22 @@ public class DispatcherWacRootWacEarTests extends RootWacEarTests { private String dispatcher; - @Ignore("Superseded by verifyDispatcherWacConfig()") + @Disabled("Superseded by verifyDispatcherWacConfig()") @Test @Override - public void verifyEarConfig() { + void verifyEarConfig() { /* no-op */ } - @Ignore("Superseded by verifyDispatcherWacConfig()") + @Disabled("Superseded by verifyDispatcherWacConfig()") @Test @Override - public void verifyRootWacConfig() { + void verifyRootWacConfig() { /* no-op */ } @Test - public void verifyDispatcherWacConfig() { + void verifyDispatcherWacConfig() { ApplicationContext parent = wac.getParent(); assertThat(parent).isNotNull(); boolean condition = parent instanceof WebApplicationContext; diff --git a/spring-test/src/test/java/org/springframework/test/context/hierarchies/web/EarTests.java b/spring-test/src/test/java/org/springframework/test/context/hierarchies/web/EarTests.java index ab86ca7185..bf360dce95 100644 --- a/spring-test/src/test/java/org/springframework/test/context/hierarchies/web/EarTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/hierarchies/web/EarTests.java @@ -16,15 +16,15 @@ package org.springframework.test.context.hierarchies.web; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.web.context.WebApplicationContext; import static org.assertj.core.api.Assertions.assertThat; @@ -33,15 +33,15 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Sam Brannen * @since 3.2.2 */ -@RunWith(SpringJUnit4ClassRunner.class) +@ExtendWith(SpringExtension.class) @ContextConfiguration -public class EarTests { +class EarTests { @Configuration static class EarConfig { @Bean - public String ear() { + String ear() { return "ear"; } } @@ -57,7 +57,7 @@ public class EarTests { @Test - public void verifyEarConfig() { + void verifyEarConfig() { boolean condition = context instanceof WebApplicationContext; assertThat(condition).isFalse(); assertThat(context.getParent()).isNull(); diff --git a/spring-test/src/test/java/org/springframework/test/context/hierarchies/web/RootWacEarTests.java b/spring-test/src/test/java/org/springframework/test/context/hierarchies/web/RootWacEarTests.java index 27ff8d5e31..1e89e0735c 100644 --- a/spring-test/src/test/java/org/springframework/test/context/hierarchies/web/RootWacEarTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/hierarchies/web/RootWacEarTests.java @@ -16,8 +16,8 @@ package org.springframework.test.context.hierarchies.web; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationContext; @@ -36,13 +36,13 @@ import static org.assertj.core.api.Assertions.assertThat; */ @WebAppConfiguration @ContextHierarchy(@ContextConfiguration) -public class RootWacEarTests extends EarTests { +class RootWacEarTests extends EarTests { @Configuration static class RootWacConfig { @Bean - public String root() { + String root() { return "root"; } } @@ -60,15 +60,15 @@ public class RootWacEarTests extends EarTests { private String root; - @Ignore("Superseded by verifyRootWacConfig()") + @Disabled("Superseded by verifyRootWacConfig()") @Test @Override - public void verifyEarConfig() { + void verifyEarConfig() { /* no-op */ } @Test - public void verifyRootWacConfig() { + void verifyRootWacConfig() { ApplicationContext parent = wac.getParent(); assertThat(parent).isNotNull(); boolean condition = parent instanceof WebApplicationContext; diff --git a/spring-test/src/test/java/org/springframework/test/context/jdbc/AbstractTransactionalTests.java b/spring-test/src/test/java/org/springframework/test/context/jdbc/AbstractTransactionalTests.java new file mode 100644 index 0000000000..8e205d2ea2 --- /dev/null +++ b/spring-test/src/test/java/org/springframework/test/context/jdbc/AbstractTransactionalTests.java @@ -0,0 +1,55 @@ +/* + * Copyright 2002-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.test.context.jdbc; + +import java.util.List; + +import org.junit.jupiter.api.extension.ExtendWith; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.test.context.junit.jupiter.SpringExtension; +import org.springframework.test.jdbc.JdbcTestUtils; +import org.springframework.transaction.annotation.Transactional; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Sam Brannen + * @since 5.2 + */ +@ExtendWith(SpringExtension.class) +@Transactional +public abstract class AbstractTransactionalTests { + + @Autowired + protected JdbcTemplate jdbcTemplate; + + protected final int countRowsInTable(String tableName) { + return JdbcTestUtils.countRowsInTable(this.jdbcTemplate, tableName); + } + + protected final void assertNumUsers(int expected) { + assertThat(countRowsInTable("user")).as("Number of rows in the 'user' table.").isEqualTo(expected); + } + + protected final void assertUsers(String... expectedUsers) { + List actualUsers = this.jdbcTemplate.queryForList("select name from user", String.class); + assertThat(actualUsers).containsExactlyInAnyOrder(expectedUsers); + } + +} diff --git a/spring-test/src/test/java/org/springframework/test/context/jdbc/ComposedAnnotationSqlScriptsTests.java b/spring-test/src/test/java/org/springframework/test/context/jdbc/ComposedAnnotationSqlScriptsTests.java index b2195dc34b..ff963a272c 100644 --- a/spring-test/src/test/java/org/springframework/test/context/jdbc/ComposedAnnotationSqlScriptsTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/jdbc/ComposedAnnotationSqlScriptsTests.java @@ -18,16 +18,14 @@ package org.springframework.test.context.jdbc; import java.lang.annotation.Retention; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.core.annotation.AliasFor; import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.jdbc.Sql.ExecutionPhase; -import org.springframework.test.context.junit4.AbstractTransactionalJUnit4SpringContextTests; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import static java.lang.annotation.RetentionPolicy.RUNTIME; -import static org.assertj.core.api.Assertions.assertThat; import static org.springframework.test.context.jdbc.Sql.ExecutionPhase.BEFORE_TEST_METHOD; /** @@ -37,9 +35,9 @@ import static org.springframework.test.context.jdbc.Sql.ExecutionPhase.BEFORE_TE * @author Sam Brannen * @since 4.3 */ -@ContextConfiguration(classes = EmptyDatabaseConfig.class) +@SpringJUnitConfig(EmptyDatabaseConfig.class) @DirtiesContext -public class ComposedAnnotationSqlScriptsTests extends AbstractTransactionalJUnit4SpringContextTests { +class ComposedAnnotationSqlScriptsTests extends AbstractTransactionalTests { @Test @ComposedSql( @@ -47,8 +45,8 @@ public class ComposedAnnotationSqlScriptsTests extends AbstractTransactionalJUni statements = "INSERT INTO user VALUES('Dilbert')", executionPhase = BEFORE_TEST_METHOD ) - public void composedSqlAnnotation() { - assertThat(countRowsInTable("user")).as("Number of rows in the 'user' table.").isEqualTo(1); + void composedSqlAnnotation() { + assertNumUsers(1); } diff --git a/spring-test/src/test/java/org/springframework/test/context/jdbc/CustomScriptSyntaxSqlScriptsTests.java b/spring-test/src/test/java/org/springframework/test/context/jdbc/CustomScriptSyntaxSqlScriptsTests.java index 6bbaa3a0fc..66cb076b78 100644 --- a/spring-test/src/test/java/org/springframework/test/context/jdbc/CustomScriptSyntaxSqlScriptsTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/jdbc/CustomScriptSyntaxSqlScriptsTests.java @@ -16,13 +16,10 @@ package org.springframework.test.context.jdbc; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.AbstractTransactionalJUnit4SpringContextTests; - -import static org.assertj.core.api.Assertions.assertThat; /** * Integration tests that verify support for custom SQL script syntax @@ -33,18 +30,14 @@ import static org.assertj.core.api.Assertions.assertThat; */ @ContextConfiguration(classes = EmptyDatabaseConfig.class) @DirtiesContext -public class CustomScriptSyntaxSqlScriptsTests extends AbstractTransactionalJUnit4SpringContextTests { +class CustomScriptSyntaxSqlScriptsTests extends AbstractTransactionalTests { @Test @Sql("schema.sql") @Sql(scripts = "data-add-users-with-custom-script-syntax.sql",// config = @SqlConfig(commentPrefixes = { "`", "%%" }, blockCommentStartDelimiter = "#$", blockCommentEndDelimiter = "$#", separator = "@@")) - public void methodLevelScripts() { + void methodLevelScripts() { assertNumUsers(3); } - protected void assertNumUsers(int expected) { - assertThat(countRowsInTable("user")).as("Number of rows in the 'user' table.").isEqualTo(expected); - } - } diff --git a/spring-test/src/test/java/org/springframework/test/context/jdbc/DataSourceOnlySqlScriptsTests.java b/spring-test/src/test/java/org/springframework/test/context/jdbc/DataSourceOnlySqlScriptsTests.java index e65b750a87..892f122d78 100644 --- a/spring-test/src/test/java/org/springframework/test/context/jdbc/DataSourceOnlySqlScriptsTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/jdbc/DataSourceOnlySqlScriptsTests.java @@ -18,10 +18,10 @@ package org.springframework.test.context.jdbc; import javax.sql.DataSource; -import org.junit.FixMethodOrder; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.MethodSorters; +import org.junit.jupiter.api.MethodOrderer; +import org.junit.jupiter.api.Order; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestMethodOrder; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; @@ -29,8 +29,7 @@ import org.springframework.context.annotation.Configuration; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder; import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import org.springframework.test.jdbc.JdbcTestUtils; import static org.assertj.core.api.Assertions.assertThat; @@ -43,38 +42,38 @@ import static org.springframework.test.transaction.TransactionAssert.assertThatT * @author Sam Brannen * @since 4.1 */ -@RunWith(SpringJUnit4ClassRunner.class) -@FixMethodOrder(MethodSorters.NAME_ASCENDING) -@ContextConfiguration +@SpringJUnitConfig +@TestMethodOrder(MethodOrderer.OrderAnnotation.class) @Sql({ "schema.sql", "data.sql" }) @DirtiesContext -public class DataSourceOnlySqlScriptsTests { +class DataSourceOnlySqlScriptsTests { private JdbcTemplate jdbcTemplate; @Autowired - public void setDataSource(DataSource dataSource) { + void setDataSource(DataSource dataSource) { this.jdbcTemplate = new JdbcTemplate(dataSource); } @Test - // test##_ prefix is required for @FixMethodOrder. - public void test01_classLevelScripts() { + @Order(1) + void classLevelScripts() { assertThatTransaction().isNotActive(); assertNumUsers(1); } @Test @Sql({ "drop-schema.sql", "schema.sql", "data.sql", "data-add-dogbert.sql" }) - // test##_ prefix is required for @FixMethodOrder. - public void test02_methodLevelScripts() { + @Order(2) + void methodLevelScripts() { assertThatTransaction().isNotActive(); assertNumUsers(2); } protected void assertNumUsers(int expected) { - assertThat(JdbcTestUtils.countRowsInTable(jdbcTemplate, "user")).as("Number of rows in the 'user' table.").isEqualTo(expected); + assertThat(JdbcTestUtils.countRowsInTable(jdbcTemplate, "user")).as( + "Number of rows in the 'user' table.").isEqualTo(expected); } @@ -82,10 +81,10 @@ public class DataSourceOnlySqlScriptsTests { static class Config { @Bean - public DataSource dataSource() { + DataSource dataSource() { return new EmbeddedDatabaseBuilder()// - .setName("empty-sql-scripts-without-tx-mgr-test-db")// - .build(); + .setName("empty-sql-scripts-without-tx-mgr-test-db")// + .build(); } } diff --git a/spring-test/src/test/java/org/springframework/test/context/jdbc/DefaultScriptDetectionSqlScriptsTests.java b/spring-test/src/test/java/org/springframework/test/context/jdbc/DefaultScriptDetectionSqlScriptsTests.java index dec72528bf..e473294fd2 100644 --- a/spring-test/src/test/java/org/springframework/test/context/jdbc/DefaultScriptDetectionSqlScriptsTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/jdbc/DefaultScriptDetectionSqlScriptsTests.java @@ -16,13 +16,10 @@ package org.springframework.test.context.jdbc; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.AbstractTransactionalJUnit4SpringContextTests; - -import static org.assertj.core.api.Assertions.assertThat; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; /** * Integration tests that verify support for default SQL script detection. @@ -30,24 +27,20 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Sam Brannen * @since 4.1 */ -@ContextConfiguration(classes = EmptyDatabaseConfig.class) +@SpringJUnitConfig(EmptyDatabaseConfig.class) @Sql @DirtiesContext -public class DefaultScriptDetectionSqlScriptsTests extends AbstractTransactionalJUnit4SpringContextTests { +class DefaultScriptDetectionSqlScriptsTests extends AbstractTransactionalTests { @Test - public void classLevel() { + void classLevel() { assertNumUsers(2); } @Test @Sql - public void methodLevel() { + void methodLevel() { assertNumUsers(3); } - protected void assertNumUsers(int expected) { - assertThat(countRowsInTable("user")).as("Number of rows in the 'user' table.").isEqualTo(expected); - } - } diff --git a/spring-test/src/test/java/org/springframework/test/context/jdbc/EmptyDatabaseConfig.java b/spring-test/src/test/java/org/springframework/test/context/jdbc/EmptyDatabaseConfig.java index 25f9b6fa3f..6a36e322f9 100644 --- a/spring-test/src/test/java/org/springframework/test/context/jdbc/EmptyDatabaseConfig.java +++ b/spring-test/src/test/java/org/springframework/test/context/jdbc/EmptyDatabaseConfig.java @@ -35,17 +35,17 @@ import org.springframework.transaction.PlatformTransactionManager; public class EmptyDatabaseConfig { @Bean - public JdbcTemplate jdbcTemplate(DataSource dataSource) { + JdbcTemplate jdbcTemplate(DataSource dataSource) { return new JdbcTemplate(dataSource); } @Bean - public PlatformTransactionManager transactionManager(DataSource dataSource) { + PlatformTransactionManager transactionManager(DataSource dataSource) { return new DataSourceTransactionManager(dataSource); } @Bean - public DataSource dataSource() { + DataSource dataSource() { return new EmbeddedDatabaseBuilder()// .setName("empty-sql-scripts-test-db")// .build(); diff --git a/spring-test/src/test/java/org/springframework/test/context/jdbc/GlobalCustomScriptSyntaxSqlScriptsTests.java b/spring-test/src/test/java/org/springframework/test/context/jdbc/GlobalCustomScriptSyntaxSqlScriptsTests.java index a7eb393153..1f5e77dda4 100644 --- a/spring-test/src/test/java/org/springframework/test/context/jdbc/GlobalCustomScriptSyntaxSqlScriptsTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/jdbc/GlobalCustomScriptSyntaxSqlScriptsTests.java @@ -16,13 +16,10 @@ package org.springframework.test.context.jdbc; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.AbstractTransactionalJUnit4SpringContextTests; - -import static org.assertj.core.api.Assertions.assertThat; /** * Modified copy of {@link CustomScriptSyntaxSqlScriptsTests} with @@ -34,17 +31,13 @@ import static org.assertj.core.api.Assertions.assertThat; @ContextConfiguration(classes = EmptyDatabaseConfig.class) @DirtiesContext @SqlConfig(commentPrefixes = { "`", "%%" }, blockCommentStartDelimiter = "#$", blockCommentEndDelimiter = "$#", separator = "@@") -public class GlobalCustomScriptSyntaxSqlScriptsTests extends AbstractTransactionalJUnit4SpringContextTests { +class GlobalCustomScriptSyntaxSqlScriptsTests extends AbstractTransactionalTests { @Test @Sql(scripts = "schema.sql", config = @SqlConfig(separator = ";")) @Sql("data-add-users-with-custom-script-syntax.sql") - public void methodLevelScripts() { + void methodLevelScripts() { assertNumUsers(3); } - protected void assertNumUsers(int expected) { - assertThat(countRowsInTable("user")).as("Number of rows in the 'user' table.").isEqualTo(expected); - } - } diff --git a/spring-test/src/test/java/org/springframework/test/context/jdbc/InferredDataSourceSqlScriptsTests.java b/spring-test/src/test/java/org/springframework/test/context/jdbc/InferredDataSourceSqlScriptsTests.java index 5101e75f46..abdbe05fc9 100644 --- a/spring-test/src/test/java/org/springframework/test/context/jdbc/InferredDataSourceSqlScriptsTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/jdbc/InferredDataSourceSqlScriptsTests.java @@ -21,8 +21,7 @@ import java.util.Collections; import java.util.List; import javax.sql.DataSource; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; @@ -31,8 +30,7 @@ import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.datasource.DataSourceTransactionManager; import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder; import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import org.springframework.transaction.PlatformTransactionManager; import static org.assertj.core.api.Assertions.assertThat; @@ -46,28 +44,27 @@ import static org.springframework.test.transaction.TransactionAssert.assertThatT * @since 4.1 * @see InferredDataSourceTransactionalSqlScriptsTests */ -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration +@SpringJUnitConfig @DirtiesContext -public class InferredDataSourceSqlScriptsTests { +class InferredDataSourceSqlScriptsTests { @Autowired - private DataSource dataSource1; + DataSource dataSource1; @Autowired - private DataSource dataSource2; + DataSource dataSource2; @Test @Sql(scripts = "data-add-dogbert.sql", config = @SqlConfig(transactionManager = "txMgr1")) - public void database1() { + void database1() { assertThatTransaction().isNotActive(); assertUsers(new JdbcTemplate(dataSource1), "Dilbert", "Dogbert"); } @Test @Sql(scripts = "data-add-catbert.sql", config = @SqlConfig(transactionManager = "txMgr2")) - public void database2() { + void database2() { assertThatTransaction().isNotActive(); assertUsers(new JdbcTemplate(dataSource2), "Dilbert", "Catbert"); } @@ -85,31 +82,31 @@ public class InferredDataSourceSqlScriptsTests { static class Config { @Bean - public PlatformTransactionManager txMgr1() { + PlatformTransactionManager txMgr1() { return new DataSourceTransactionManager(dataSource1()); } @Bean - public PlatformTransactionManager txMgr2() { + PlatformTransactionManager txMgr2() { return new DataSourceTransactionManager(dataSource2()); } @Bean - public DataSource dataSource1() { + DataSource dataSource1() { return new EmbeddedDatabaseBuilder()// - .setName("database1")// - .addScript("classpath:/org/springframework/test/context/jdbc/schema.sql")// - .addScript("classpath:/org/springframework/test/context/jdbc/data.sql")// - .build(); + .setName("database1")// + .addScript("classpath:/org/springframework/test/context/jdbc/schema.sql")// + .addScript("classpath:/org/springframework/test/context/jdbc/data.sql")// + .build(); } @Bean - public DataSource dataSource2() { + DataSource dataSource2() { return new EmbeddedDatabaseBuilder()// - .setName("database2")// - .addScript("classpath:/org/springframework/test/context/jdbc/schema.sql")// - .addScript("classpath:/org/springframework/test/context/jdbc/data.sql")// - .build(); + .setName("database2")// + .addScript("classpath:/org/springframework/test/context/jdbc/schema.sql")// + .addScript("classpath:/org/springframework/test/context/jdbc/data.sql")// + .build(); } } diff --git a/spring-test/src/test/java/org/springframework/test/context/jdbc/InferredDataSourceTransactionalSqlScriptsTests.java b/spring-test/src/test/java/org/springframework/test/context/jdbc/InferredDataSourceTransactionalSqlScriptsTests.java index 91871e8f38..7ce631c8b1 100644 --- a/spring-test/src/test/java/org/springframework/test/context/jdbc/InferredDataSourceTransactionalSqlScriptsTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/jdbc/InferredDataSourceTransactionalSqlScriptsTests.java @@ -21,8 +21,7 @@ import java.util.Collections; import java.util.List; import javax.sql.DataSource; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; @@ -31,8 +30,7 @@ import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.datasource.DataSourceTransactionManager; import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder; import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import org.springframework.transaction.PlatformTransactionManager; import org.springframework.transaction.annotation.Transactional; @@ -47,22 +45,21 @@ import static org.springframework.test.transaction.TransactionAssert.assertThatT * @since 4.1 * @see InferredDataSourceSqlScriptsTests */ -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration +@SpringJUnitConfig @DirtiesContext -public class InferredDataSourceTransactionalSqlScriptsTests { +class InferredDataSourceTransactionalSqlScriptsTests { @Autowired - private DataSource dataSource1; + DataSource dataSource1; @Autowired - private DataSource dataSource2; + DataSource dataSource2; @Test @Transactional("txMgr1") @Sql(scripts = "data-add-dogbert.sql", config = @SqlConfig(transactionManager = "txMgr1")) - public void database1() { + void database1() { assertThatTransaction().isActive(); assertUsers(new JdbcTemplate(dataSource1), "Dilbert", "Dogbert"); } @@ -70,7 +67,7 @@ public class InferredDataSourceTransactionalSqlScriptsTests { @Test @Transactional("txMgr2") @Sql(scripts = "data-add-catbert.sql", config = @SqlConfig(transactionManager = "txMgr2")) - public void database2() { + void database2() { assertThatTransaction().isActive(); assertUsers(new JdbcTemplate(dataSource2), "Dilbert", "Catbert"); } @@ -88,17 +85,17 @@ public class InferredDataSourceTransactionalSqlScriptsTests { static class Config { @Bean - public PlatformTransactionManager txMgr1() { + PlatformTransactionManager txMgr1() { return new DataSourceTransactionManager(dataSource1()); } @Bean - public PlatformTransactionManager txMgr2() { + PlatformTransactionManager txMgr2() { return new DataSourceTransactionManager(dataSource2()); } @Bean - public DataSource dataSource1() { + DataSource dataSource1() { return new EmbeddedDatabaseBuilder()// .setName("database1")// .addScript("classpath:/org/springframework/test/context/jdbc/schema.sql")// @@ -107,7 +104,7 @@ public class InferredDataSourceTransactionalSqlScriptsTests { } @Bean - public DataSource dataSource2() { + DataSource dataSource2() { return new EmbeddedDatabaseBuilder()// .setName("database2")// .addScript("classpath:/org/springframework/test/context/jdbc/schema.sql")// diff --git a/spring-test/src/test/java/org/springframework/test/context/jdbc/IsolatedTransactionModeSqlScriptsTests.java b/spring-test/src/test/java/org/springframework/test/context/jdbc/IsolatedTransactionModeSqlScriptsTests.java index 1cbcc35bed..e551534053 100644 --- a/spring-test/src/test/java/org/springframework/test/context/jdbc/IsolatedTransactionModeSqlScriptsTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/jdbc/IsolatedTransactionModeSqlScriptsTests.java @@ -16,17 +16,14 @@ package org.springframework.test.context.jdbc; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.jdbc.SqlConfig.TransactionMode; -import org.springframework.test.context.junit4.AbstractTransactionalJUnit4SpringContextTests; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import org.springframework.test.context.transaction.AfterTransaction; import org.springframework.test.context.transaction.BeforeTransaction; -import static org.assertj.core.api.Assertions.assertThat; - /** * Transactional integration tests that verify commit semantics for * {@link SqlConfig#transactionMode} and {@link TransactionMode#ISOLATED}. @@ -34,28 +31,24 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Sam Brannen * @since 4.1 */ -@ContextConfiguration(classes = PopulatedSchemaDatabaseConfig.class) +@SpringJUnitConfig(PopulatedSchemaDatabaseConfig.class) @DirtiesContext -public class IsolatedTransactionModeSqlScriptsTests extends AbstractTransactionalJUnit4SpringContextTests { +class IsolatedTransactionModeSqlScriptsTests extends AbstractTransactionalTests { @BeforeTransaction - public void beforeTransaction() { + void beforeTransaction() { assertNumUsers(0); } @Test @SqlGroup(@Sql(scripts = "data-add-dogbert.sql", config = @SqlConfig(transactionMode = TransactionMode.ISOLATED))) - public void methodLevelScripts() { + void methodLevelScripts() { assertNumUsers(1); } @AfterTransaction - public void afterTransaction() { + void afterTransaction() { assertNumUsers(1); } - protected void assertNumUsers(int expected) { - assertThat(countRowsInTable("user")).as("Number of rows in the 'user' table.").isEqualTo(expected); - } - } diff --git a/spring-test/src/test/java/org/springframework/test/context/jdbc/MergedSqlConfigTests.java b/spring-test/src/test/java/org/springframework/test/context/jdbc/MergedSqlConfigTests.java index 0180a28c76..d9cc836356 100644 --- a/spring-test/src/test/java/org/springframework/test/context/jdbc/MergedSqlConfigTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/jdbc/MergedSqlConfigTests.java @@ -18,7 +18,7 @@ package org.springframework.test.context.jdbc; import java.lang.reflect.Method; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; @@ -39,17 +39,17 @@ import static org.springframework.test.context.jdbc.SqlConfig.TransactionMode.IS * @author Sam Brannen * @since 4.1 */ -public class MergedSqlConfigTests { +class MergedSqlConfigTests { @Test - public void nullLocalSqlConfig() { + void nullLocalSqlConfig() { assertThatIllegalArgumentException() .isThrownBy(() -> new MergedSqlConfig(null, getClass())) .withMessage("Local @SqlConfig must not be null"); } @Test - public void nullTestClass() { + void nullTestClass() { SqlConfig sqlConfig = GlobalConfigClass.class.getAnnotation(SqlConfig.class); assertThatIllegalArgumentException() @@ -58,7 +58,7 @@ public class MergedSqlConfigTests { } @Test - public void localConfigWithEmptyCommentPrefix() throws Exception { + void localConfigWithEmptyCommentPrefix() throws Exception { Method method = getClass().getMethod("localConfigMethodWithEmptyCommentPrefix"); SqlConfig sqlConfig = method.getAnnotation(Sql.class).config(); @@ -68,7 +68,7 @@ public class MergedSqlConfigTests { } @Test - public void localConfigWithEmptyCommentPrefixes() throws Exception { + void localConfigWithEmptyCommentPrefixes() throws Exception { Method method = getClass().getMethod("localConfigMethodWithEmptyCommentPrefixes"); SqlConfig sqlConfig = method.getAnnotation(Sql.class).config(); @@ -78,7 +78,7 @@ public class MergedSqlConfigTests { } @Test - public void localConfigWithDuplicatedCommentPrefixes() throws Exception { + void localConfigWithDuplicatedCommentPrefixes() throws Exception { Method method = getClass().getMethod("localConfigMethodWithDuplicatedCommentPrefixes"); SqlConfig sqlConfig = method.getAnnotation(Sql.class).config(); @@ -88,7 +88,7 @@ public class MergedSqlConfigTests { } @Test - public void localConfigWithDefaults() throws Exception { + void localConfigWithDefaults() throws Exception { Method method = getClass().getMethod("localConfigMethodWithDefaults"); SqlConfig localSqlConfig = method.getAnnotation(Sql.class).config(); MergedSqlConfig cfg = new MergedSqlConfig(localSqlConfig, getClass()); @@ -96,7 +96,7 @@ public class MergedSqlConfigTests { } @Test - public void localConfigWithCustomValues() throws Exception { + void localConfigWithCustomValues() throws Exception { Method method = getClass().getMethod("localConfigMethodWithCustomValues"); SqlConfig localSqlConfig = method.getAnnotation(Sql.class).config(); MergedSqlConfig cfg = new MergedSqlConfig(localSqlConfig, getClass()); @@ -116,7 +116,7 @@ public class MergedSqlConfigTests { } @Test - public void localConfigWithCustomCommentPrefixes() throws Exception { + void localConfigWithCustomCommentPrefixes() throws Exception { Method method = getClass().getMethod("localConfigMethodWithCustomCommentPrefixes"); SqlConfig localSqlConfig = method.getAnnotation(Sql.class).config(); MergedSqlConfig cfg = new MergedSqlConfig(localSqlConfig, getClass()); @@ -126,7 +126,7 @@ public class MergedSqlConfigTests { } @Test - public void localConfigWithMultipleCommentPrefixes() throws Exception { + void localConfigWithMultipleCommentPrefixes() throws Exception { Method method = getClass().getMethod("localConfigMethodWithMultipleCommentPrefixes"); SqlConfig localSqlConfig = method.getAnnotation(Sql.class).config(); MergedSqlConfig cfg = new MergedSqlConfig(localSqlConfig, getClass()); @@ -136,7 +136,7 @@ public class MergedSqlConfigTests { } @Test - public void localConfigWithContinueOnError() throws Exception { + void localConfigWithContinueOnError() throws Exception { Method method = getClass().getMethod("localConfigMethodWithContinueOnError"); SqlConfig localSqlConfig = method.getAnnotation(Sql.class).config(); MergedSqlConfig cfg = new MergedSqlConfig(localSqlConfig, getClass()); @@ -146,7 +146,7 @@ public class MergedSqlConfigTests { } @Test - public void localConfigWithIgnoreFailedDrops() throws Exception { + void localConfigWithIgnoreFailedDrops() throws Exception { Method method = getClass().getMethod("localConfigMethodWithIgnoreFailedDrops"); SqlConfig localSqlConfig = method.getAnnotation(Sql.class).config(); MergedSqlConfig cfg = new MergedSqlConfig(localSqlConfig, getClass()); @@ -156,7 +156,7 @@ public class MergedSqlConfigTests { } @Test - public void globalConfigWithEmptyCommentPrefix() throws Exception { + void globalConfigWithEmptyCommentPrefix() throws Exception { SqlConfig sqlConfig = GlobalConfigWithWithEmptyCommentPrefixClass.class.getAnnotation(SqlConfig.class); assertThatIllegalArgumentException() @@ -165,7 +165,7 @@ public class MergedSqlConfigTests { } @Test - public void globalConfigWithEmptyCommentPrefixes() throws Exception { + void globalConfigWithEmptyCommentPrefixes() throws Exception { SqlConfig sqlConfig = GlobalConfigWithWithEmptyCommentPrefixesClass.class.getAnnotation(SqlConfig.class); assertThatIllegalArgumentException() @@ -174,7 +174,7 @@ public class MergedSqlConfigTests { } @Test - public void globalConfigWithDuplicatedCommentPrefixes() throws Exception { + void globalConfigWithDuplicatedCommentPrefixes() throws Exception { SqlConfig sqlConfig = GlobalConfigWithWithDuplicatedCommentPrefixesClass.class.getAnnotation(SqlConfig.class); assertThatIllegalArgumentException() @@ -183,7 +183,7 @@ public class MergedSqlConfigTests { } @Test - public void globalConfigWithDefaults() throws Exception { + void globalConfigWithDefaults() throws Exception { Method method = GlobalConfigWithDefaultsClass.class.getMethod("globalConfigMethod"); SqlConfig localSqlConfig = method.getAnnotation(Sql.class).config(); MergedSqlConfig cfg = new MergedSqlConfig(localSqlConfig, GlobalConfigWithDefaultsClass.class); @@ -191,7 +191,7 @@ public class MergedSqlConfigTests { } @Test - public void globalConfig() throws Exception { + void globalConfig() throws Exception { Method method = GlobalConfigClass.class.getMethod("globalConfigMethod"); SqlConfig localSqlConfig = method.getAnnotation(Sql.class).config(); MergedSqlConfig cfg = new MergedSqlConfig(localSqlConfig, GlobalConfigClass.class); @@ -211,7 +211,7 @@ public class MergedSqlConfigTests { } @Test - public void globalConfigWithLocalOverrides() throws Exception { + void globalConfigWithLocalOverrides() throws Exception { Method method = GlobalConfigClass.class.getMethod("globalConfigWithLocalOverridesMethod"); SqlConfig localSqlConfig = method.getAnnotation(Sql.class).config(); MergedSqlConfig cfg = new MergedSqlConfig(localSqlConfig, GlobalConfigClass.class); @@ -231,7 +231,7 @@ public class MergedSqlConfigTests { } @Test - public void globalConfigWithCommentPrefixAndLocalOverrides() throws Exception { + void globalConfigWithCommentPrefixAndLocalOverrides() throws Exception { Class testClass = GlobalConfigWithPrefixClass.class; Method method = testClass.getMethod("commentPrefixesOverrideCommentPrefix"); @@ -248,7 +248,7 @@ public class MergedSqlConfigTests { } @Test - public void globalConfigWithCommentPrefixesAndLocalOverrides() throws Exception { + void globalConfigWithCommentPrefixesAndLocalOverrides() throws Exception { Class testClass = GlobalConfigWithPrefixesClass.class; Method method = testClass.getMethod("commentPrefixesOverrideCommentPrefixes"); diff --git a/spring-test/src/test/java/org/springframework/test/context/jdbc/MetaAnnotationSqlScriptsTests.java b/spring-test/src/test/java/org/springframework/test/context/jdbc/MetaAnnotationSqlScriptsTests.java index 08e4f1ab6a..365e44fb95 100644 --- a/spring-test/src/test/java/org/springframework/test/context/jdbc/MetaAnnotationSqlScriptsTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/jdbc/MetaAnnotationSqlScriptsTests.java @@ -19,15 +19,13 @@ package org.springframework.test.context.jdbc; import java.lang.annotation.Retention; import java.lang.annotation.Target; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.AbstractTransactionalJUnit4SpringContextTests; import static java.lang.annotation.ElementType.METHOD; import static java.lang.annotation.RetentionPolicy.RUNTIME; -import static org.assertj.core.api.Assertions.assertThat; /** * Integration tests that verify support for using {@link Sql @Sql} and @@ -38,35 +36,31 @@ import static org.assertj.core.api.Assertions.assertThat; */ @ContextConfiguration(classes = EmptyDatabaseConfig.class) @DirtiesContext -public class MetaAnnotationSqlScriptsTests extends AbstractTransactionalJUnit4SpringContextTests { +class MetaAnnotationSqlScriptsTests extends AbstractTransactionalTests { @Test @MetaSql - public void metaSqlAnnotation() { + void metaSqlAnnotation() { assertNumUsers(1); } @Test @MetaSqlGroup - public void metaSqlGroupAnnotation() { + void metaSqlGroupAnnotation() { assertNumUsers(1); } - protected void assertNumUsers(int expected) { - assertThat(countRowsInTable("user")).as("Number of rows in the 'user' table.").isEqualTo(expected); - } - @Sql({ "drop-schema.sql", "schema.sql", "data.sql" }) @Retention(RUNTIME) @Target(METHOD) - static @interface MetaSql { + @interface MetaSql { } @SqlGroup({ @Sql("drop-schema.sql"), @Sql("schema.sql"), @Sql("data.sql") }) @Retention(RUNTIME) @Target(METHOD) - static @interface MetaSqlGroup { + @interface MetaSqlGroup { } } diff --git a/spring-test/src/test/java/org/springframework/test/context/jdbc/MultipleDataSourcesAndTransactionManagersSqlScriptsTests.java b/spring-test/src/test/java/org/springframework/test/context/jdbc/MultipleDataSourcesAndTransactionManagersSqlScriptsTests.java index a6df109771..e58d9ffdb2 100644 --- a/spring-test/src/test/java/org/springframework/test/context/jdbc/MultipleDataSourcesAndTransactionManagersSqlScriptsTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/jdbc/MultipleDataSourcesAndTransactionManagersSqlScriptsTests.java @@ -21,8 +21,7 @@ import java.util.Collections; import java.util.List; import javax.sql.DataSource; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; @@ -31,8 +30,7 @@ import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.datasource.DataSourceTransactionManager; import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder; import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import org.springframework.transaction.PlatformTransactionManager; import static org.assertj.core.api.Assertions.assertThat; @@ -46,11 +44,10 @@ import static org.assertj.core.api.Assertions.assertThat; * @since 4.1 * @see MultipleDataSourcesAndTransactionManagersTransactionalSqlScriptsTests */ -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration +@SpringJUnitConfig @DirtiesContext @SqlConfig(dataSource = "dataSource1", transactionManager = "txMgr1") -public class MultipleDataSourcesAndTransactionManagersSqlScriptsTests { +class MultipleDataSourcesAndTransactionManagersSqlScriptsTests { @Autowired private DataSource dataSource1; @@ -61,13 +58,13 @@ public class MultipleDataSourcesAndTransactionManagersSqlScriptsTests { @Test @Sql("data-add-dogbert.sql") - public void database1() { + void database1() { assertUsers(new JdbcTemplate(dataSource1), "Dilbert", "Dogbert"); } @Test @Sql(scripts = "data-add-catbert.sql", config = @SqlConfig(dataSource = "dataSource2", transactionManager = "txMgr2")) - public void database2() { + void database2() { assertUsers(new JdbcTemplate(dataSource2), "Dilbert", "Catbert"); } @@ -84,17 +81,17 @@ public class MultipleDataSourcesAndTransactionManagersSqlScriptsTests { static class Config { @Bean - public PlatformTransactionManager txMgr1() { + PlatformTransactionManager txMgr1() { return new DataSourceTransactionManager(dataSource1()); } @Bean - public PlatformTransactionManager txMgr2() { + PlatformTransactionManager txMgr2() { return new DataSourceTransactionManager(dataSource2()); } @Bean - public DataSource dataSource1() { + DataSource dataSource1() { return new EmbeddedDatabaseBuilder()// .setName("database1")// .addScript("classpath:/org/springframework/test/context/jdbc/schema.sql")// @@ -103,7 +100,7 @@ public class MultipleDataSourcesAndTransactionManagersSqlScriptsTests { } @Bean - public DataSource dataSource2() { + DataSource dataSource2() { return new EmbeddedDatabaseBuilder()// .setName("database2")// .addScript("classpath:/org/springframework/test/context/jdbc/schema.sql")// diff --git a/spring-test/src/test/java/org/springframework/test/context/jdbc/MultipleDataSourcesAndTransactionManagersTransactionalSqlScriptsTests.java b/spring-test/src/test/java/org/springframework/test/context/jdbc/MultipleDataSourcesAndTransactionManagersTransactionalSqlScriptsTests.java index 54e9e644c2..51f9ac12f9 100644 --- a/spring-test/src/test/java/org/springframework/test/context/jdbc/MultipleDataSourcesAndTransactionManagersTransactionalSqlScriptsTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/jdbc/MultipleDataSourcesAndTransactionManagersTransactionalSqlScriptsTests.java @@ -21,8 +21,7 @@ import java.util.Collections; import java.util.List; import javax.sql.DataSource; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; @@ -31,8 +30,7 @@ import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.datasource.DataSourceTransactionManager; import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder; import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import org.springframework.transaction.PlatformTransactionManager; import org.springframework.transaction.annotation.Transactional; @@ -45,30 +43,29 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Sam Brannen * @since 4.1 */ -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration +@SpringJUnitConfig @DirtiesContext @Transactional(transactionManager = "txMgr1") @SqlConfig(dataSource = "dataSource1", transactionManager = "txMgr1") -public class MultipleDataSourcesAndTransactionManagersTransactionalSqlScriptsTests { +class MultipleDataSourcesAndTransactionManagersTransactionalSqlScriptsTests { @Autowired - private DataSource dataSource1; + DataSource dataSource1; @Autowired - private DataSource dataSource2; + DataSource dataSource2; @Test @Sql("data-add-dogbert.sql") - public void database1() { + void database1() { assertUsers(new JdbcTemplate(dataSource1), "Dilbert", "Dogbert"); } @Test @Transactional(transactionManager = "txMgr2") @Sql(scripts = "data-add-catbert.sql", config = @SqlConfig(dataSource = "dataSource2", transactionManager = "txMgr2")) - public void database2() { + void database2() { assertUsers(new JdbcTemplate(dataSource2), "Dilbert", "Catbert"); } @@ -85,17 +82,17 @@ public class MultipleDataSourcesAndTransactionManagersTransactionalSqlScriptsTes static class Config { @Bean - public PlatformTransactionManager txMgr1() { + PlatformTransactionManager txMgr1() { return new DataSourceTransactionManager(dataSource1()); } @Bean - public PlatformTransactionManager txMgr2() { + PlatformTransactionManager txMgr2() { return new DataSourceTransactionManager(dataSource2()); } @Bean - public DataSource dataSource1() { + DataSource dataSource1() { return new EmbeddedDatabaseBuilder()// .setName("database1")// .addScript("classpath:/org/springframework/test/context/jdbc/schema.sql")// @@ -104,7 +101,7 @@ public class MultipleDataSourcesAndTransactionManagersTransactionalSqlScriptsTes } @Bean - public DataSource dataSource2() { + DataSource dataSource2() { return new EmbeddedDatabaseBuilder()// .setName("database2")// .addScript("classpath:/org/springframework/test/context/jdbc/schema.sql")// diff --git a/spring-test/src/test/java/org/springframework/test/context/jdbc/NonTransactionalSqlScriptsTests.java b/spring-test/src/test/java/org/springframework/test/context/jdbc/NonTransactionalSqlScriptsTests.java index 0ebe27918b..8dbb23e52c 100644 --- a/spring-test/src/test/java/org/springframework/test/context/jdbc/NonTransactionalSqlScriptsTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/jdbc/NonTransactionalSqlScriptsTests.java @@ -16,16 +16,15 @@ package org.springframework.test.context.jdbc; -import org.junit.FixMethodOrder; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.MethodSorters; +import org.junit.jupiter.api.MethodOrderer; +import org.junit.jupiter.api.Order; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestMethodOrder; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import org.springframework.test.jdbc.JdbcTestUtils; import static org.assertj.core.api.Assertions.assertThat; @@ -37,30 +36,29 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Sam Brannen * @since 4.1 */ -@RunWith(SpringJUnit4ClassRunner.class) -@FixMethodOrder(MethodSorters.NAME_ASCENDING) -@ContextConfiguration(classes = EmptyDatabaseConfig.class) +@SpringJUnitConfig(EmptyDatabaseConfig.class) +@TestMethodOrder(MethodOrderer.OrderAnnotation.class) @Sql({ "schema.sql", "data.sql" }) @DirtiesContext -public class NonTransactionalSqlScriptsTests { +class NonTransactionalSqlScriptsTests { @Autowired JdbcTemplate jdbcTemplate; @Test - // test##_ prefix is required for @FixMethodOrder. - public void test01_classLevelScripts() { + @Order(1) + void classLevelScripts() { assertNumUsers(1); } @Test @Sql("data-add-dogbert.sql") - // test##_ prefix is required for @FixMethodOrder. - public void test02_methodLevelScripts() { + @Order(2) + void methodLevelScripts() { assertNumUsers(2); } - protected void assertNumUsers(int expected) { + void assertNumUsers(int expected) { assertThat(JdbcTestUtils.countRowsInTable(jdbcTemplate, "user")).as("Number of rows in the 'user' table.").isEqualTo(expected); } diff --git a/spring-test/src/test/java/org/springframework/test/context/jdbc/PopulatedSchemaDatabaseConfig.java b/spring-test/src/test/java/org/springframework/test/context/jdbc/PopulatedSchemaDatabaseConfig.java index ed302b9913..a7774d38a7 100644 --- a/spring-test/src/test/java/org/springframework/test/context/jdbc/PopulatedSchemaDatabaseConfig.java +++ b/spring-test/src/test/java/org/springframework/test/context/jdbc/PopulatedSchemaDatabaseConfig.java @@ -36,12 +36,12 @@ import org.springframework.transaction.PlatformTransactionManager; public class PopulatedSchemaDatabaseConfig { @Bean - public PlatformTransactionManager transactionManager() { + PlatformTransactionManager transactionManager() { return new DataSourceTransactionManager(dataSource()); } @Bean - public DataSource dataSource() { + DataSource dataSource() { return new EmbeddedDatabaseBuilder()// .generateUniqueName(true) .addScript("classpath:/org/springframework/test/context/jdbc/schema.sql") // @@ -49,7 +49,7 @@ public class PopulatedSchemaDatabaseConfig { } @Bean - public JdbcTemplate jdbcTemplate(DataSource dataSource) { + JdbcTemplate jdbcTemplate(DataSource dataSource) { return new JdbcTemplate(dataSource); } diff --git a/spring-test/src/test/java/org/springframework/test/context/jdbc/PopulatedSchemaTransactionalSqlScriptsTests.java b/spring-test/src/test/java/org/springframework/test/context/jdbc/PopulatedSchemaTransactionalSqlScriptsTests.java index f309c9359f..374613d6ac 100644 --- a/spring-test/src/test/java/org/springframework/test/context/jdbc/PopulatedSchemaTransactionalSqlScriptsTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/jdbc/PopulatedSchemaTransactionalSqlScriptsTests.java @@ -16,16 +16,13 @@ package org.springframework.test.context.jdbc; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.AbstractTransactionalJUnit4SpringContextTests; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import org.springframework.test.context.transaction.AfterTransaction; import org.springframework.test.context.transaction.BeforeTransaction; -import static org.assertj.core.api.Assertions.assertThat; - /** * Transactional integration tests that verify rollback semantics for * {@link Sql @Sql} support. @@ -33,24 +30,20 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Sam Brannen * @since 4.1 */ -@ContextConfiguration(classes = PopulatedSchemaDatabaseConfig.class) +@SpringJUnitConfig(PopulatedSchemaDatabaseConfig.class) @DirtiesContext -public class PopulatedSchemaTransactionalSqlScriptsTests extends AbstractTransactionalJUnit4SpringContextTests { +class PopulatedSchemaTransactionalSqlScriptsTests extends AbstractTransactionalTests { @BeforeTransaction @AfterTransaction - public void verifyPreAndPostTransactionDatabaseState() { + void verifyPreAndPostTransactionDatabaseState() { assertNumUsers(0); } @Test @SqlGroup(@Sql("data-add-dogbert.sql")) - public void methodLevelScripts() { + void methodLevelScripts() { assertNumUsers(1); } - protected void assertNumUsers(int expected) { - assertThat(countRowsInTable("user")).as("Number of rows in the 'user' table.").isEqualTo(expected); - } - } diff --git a/spring-test/src/test/java/org/springframework/test/context/jdbc/PrimaryDataSourceTests.java b/spring-test/src/test/java/org/springframework/test/context/jdbc/PrimaryDataSourceTests.java index 225c766e2c..0db28f8762 100644 --- a/spring-test/src/test/java/org/springframework/test/context/jdbc/PrimaryDataSourceTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/jdbc/PrimaryDataSourceTests.java @@ -18,8 +18,7 @@ package org.springframework.test.context.jdbc; import javax.sql.DataSource; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; @@ -28,8 +27,7 @@ import org.springframework.context.annotation.Primary; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder; import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import org.springframework.test.jdbc.JdbcTestUtils; import static org.assertj.core.api.Assertions.assertThat; @@ -43,17 +41,16 @@ import static org.springframework.test.transaction.TransactionAssert.assertThatT * @since 4.3 * @see org.springframework.test.context.transaction.PrimaryTransactionManagerTests */ -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration +@SpringJUnitConfig @DirtiesContext -public class PrimaryDataSourceTests { +class PrimaryDataSourceTests { @Configuration static class Config { @Primary @Bean - public DataSource primaryDataSource() { + DataSource primaryDataSource() { // @formatter:off return new EmbeddedDatabaseBuilder() .generateUniqueName(true) @@ -63,7 +60,7 @@ public class PrimaryDataSourceTests { } @Bean - public DataSource additionalDataSource() { + DataSource additionalDataSource() { return new EmbeddedDatabaseBuilder().generateUniqueName(true).build(); } @@ -74,13 +71,13 @@ public class PrimaryDataSourceTests { @Autowired - public void setDataSource(DataSource dataSource) { + void setDataSource(DataSource dataSource) { this.jdbcTemplate = new JdbcTemplate(dataSource); } @Test @Sql("data.sql") - public void dataSourceTest() { + void dataSourceTest() { assertThatTransaction().isNotActive(); assertThat(JdbcTestUtils.countRowsInTable(this.jdbcTemplate, "user")).as("Number of rows in the 'user' table.").isEqualTo(1); } diff --git a/spring-test/src/test/java/org/springframework/test/context/jdbc/RepeatableSqlAnnotationSqlScriptsTests.java b/spring-test/src/test/java/org/springframework/test/context/jdbc/RepeatableSqlAnnotationSqlScriptsTests.java index c1b827a1b1..2b3e9a52bb 100644 --- a/spring-test/src/test/java/org/springframework/test/context/jdbc/RepeatableSqlAnnotationSqlScriptsTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/jdbc/RepeatableSqlAnnotationSqlScriptsTests.java @@ -18,15 +18,13 @@ package org.springframework.test.context.jdbc; import java.lang.annotation.Repeatable; -import org.junit.FixMethodOrder; -import org.junit.Test; -import org.junit.runners.MethodSorters; +import org.junit.jupiter.api.MethodOrderer; +import org.junit.jupiter.api.Order; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestMethodOrder; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.AbstractTransactionalJUnit4SpringContextTests; - -import static org.assertj.core.api.Assertions.assertThat; /** * This is a copy of {@link TransactionalSqlScriptsTests} that verifies proper @@ -35,16 +33,16 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Sam Brannen * @since 4.1 */ -@FixMethodOrder(MethodSorters.NAME_ASCENDING) +@TestMethodOrder(MethodOrderer.OrderAnnotation.class) @ContextConfiguration(classes = EmptyDatabaseConfig.class) @Sql("schema.sql") @Sql("data.sql") @DirtiesContext -public class RepeatableSqlAnnotationSqlScriptsTests extends AbstractTransactionalJUnit4SpringContextTests { +class RepeatableSqlAnnotationSqlScriptsTests extends AbstractTransactionalTests { @Test - // test##_ prefix is required for @FixMethodOrder. - public void test01_classLevelScripts() { + @Order(1) + void classLevelScripts() { assertNumUsers(1); } @@ -53,13 +51,9 @@ public class RepeatableSqlAnnotationSqlScriptsTests extends AbstractTransactiona @Sql("schema.sql") @Sql("data.sql") @Sql("data-add-dogbert.sql") - // test##_ prefix is required for @FixMethodOrder. - public void test02_methodLevelScripts() { + @Order(1) + void methodLevelScripts() { assertNumUsers(2); } - protected void assertNumUsers(int expected) { - assertThat(countRowsInTable("user")).as("Number of rows in the 'user' table.").isEqualTo(expected); - } - } diff --git a/spring-test/src/test/java/org/springframework/test/context/jdbc/SqlScriptsTestExecutionListenerTests.java b/spring-test/src/test/java/org/springframework/test/context/jdbc/SqlScriptsTestExecutionListenerTests.java index 2c7039d32c..85ee9f5038 100644 --- a/spring-test/src/test/java/org/springframework/test/context/jdbc/SqlScriptsTestExecutionListenerTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/jdbc/SqlScriptsTestExecutionListenerTests.java @@ -16,7 +16,7 @@ package org.springframework.test.context.jdbc; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.mockito.BDDMockito; import org.springframework.beans.factory.config.AutowireCapableBeanFactory; @@ -38,7 +38,7 @@ import static org.mockito.Mockito.mock; * @author Sam Brannen * @since 4.1 */ -public class SqlScriptsTestExecutionListenerTests { +class SqlScriptsTestExecutionListenerTests { private final SqlScriptsTestExecutionListener listener = new SqlScriptsTestExecutionListener(); @@ -46,7 +46,7 @@ public class SqlScriptsTestExecutionListenerTests { @Test - public void missingValueAndScriptsAndStatementsAtClassLevel() throws Exception { + void missingValueAndScriptsAndStatementsAtClassLevel() throws Exception { Class clazz = MissingValueAndScriptsAndStatementsAtClassLevel.class; BDDMockito.> given(testContext.getTestClass()).willReturn(clazz); given(testContext.getTestMethod()).willReturn(clazz.getDeclaredMethod("foo")); @@ -55,7 +55,7 @@ public class SqlScriptsTestExecutionListenerTests { } @Test - public void missingValueAndScriptsAndStatementsAtMethodLevel() throws Exception { + void missingValueAndScriptsAndStatementsAtMethodLevel() throws Exception { Class clazz = MissingValueAndScriptsAndStatementsAtMethodLevel.class; BDDMockito.> given(testContext.getTestClass()).willReturn(clazz); given(testContext.getTestMethod()).willReturn(clazz.getDeclaredMethod("foo")); @@ -64,7 +64,7 @@ public class SqlScriptsTestExecutionListenerTests { } @Test - public void valueAndScriptsDeclared() throws Exception { + void valueAndScriptsDeclared() throws Exception { Class clazz = ValueAndScriptsDeclared.class; BDDMockito.> given(testContext.getTestClass()).willReturn(clazz); given(testContext.getTestMethod()).willReturn(clazz.getDeclaredMethod("foo")); @@ -77,7 +77,7 @@ public class SqlScriptsTestExecutionListenerTests { } @Test - public void isolatedTxModeDeclaredWithoutTxMgr() throws Exception { + void isolatedTxModeDeclaredWithoutTxMgr() throws Exception { ApplicationContext ctx = mock(ApplicationContext.class); given(ctx.getResource(anyString())).willReturn(mock(Resource.class)); given(ctx.getAutowireCapableBeanFactory()).willReturn(mock(AutowireCapableBeanFactory.class)); @@ -91,7 +91,7 @@ public class SqlScriptsTestExecutionListenerTests { } @Test - public void missingDataSourceAndTxMgr() throws Exception { + void missingDataSourceAndTxMgr() throws Exception { ApplicationContext ctx = mock(ApplicationContext.class); given(ctx.getResource(anyString())).willReturn(mock(Resource.class)); given(ctx.getAutowireCapableBeanFactory()).willReturn(mock(AutowireCapableBeanFactory.class)); diff --git a/spring-test/src/test/java/org/springframework/test/context/jdbc/TransactionalAfterTestMethodSqlScriptsTests.java b/spring-test/src/test/java/org/springframework/test/context/jdbc/TransactionalAfterTestMethodSqlScriptsTests.java index c87bf73584..b3f4091a67 100644 --- a/spring-test/src/test/java/org/springframework/test/context/jdbc/TransactionalAfterTestMethodSqlScriptsTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/jdbc/TransactionalAfterTestMethodSqlScriptsTests.java @@ -16,20 +16,18 @@ package org.springframework.test.context.jdbc; -import org.junit.FixMethodOrder; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TestName; -import org.junit.runners.MethodSorters; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.MethodOrderer; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInfo; +import org.junit.jupiter.api.TestMethodOrder; import org.springframework.jdbc.BadSqlGrammarException; import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.jdbc.Sql.ExecutionPhase; -import org.springframework.test.context.junit4.AbstractTransactionalJUnit4SpringContextTests; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import org.springframework.test.context.transaction.AfterTransaction; -import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatExceptionOfType; import static org.springframework.test.context.jdbc.Sql.ExecutionPhase.AFTER_TEST_METHOD; @@ -40,43 +38,42 @@ import static org.springframework.test.context.jdbc.Sql.ExecutionPhase.AFTER_TES * @author Sam Brannen * @since 4.1 */ -@FixMethodOrder(MethodSorters.NAME_ASCENDING) -@ContextConfiguration(classes = EmptyDatabaseConfig.class) +@SpringJUnitConfig(EmptyDatabaseConfig.class) +@TestMethodOrder(MethodOrderer.Alphanumeric.class) @DirtiesContext -public class TransactionalAfterTestMethodSqlScriptsTests extends AbstractTransactionalJUnit4SpringContextTests { +class TransactionalAfterTestMethodSqlScriptsTests extends AbstractTransactionalTests { - @Rule - public TestName testName = new TestName(); + String testName; + @BeforeEach + void trackTestName(TestInfo testInfo) { + this.testName = testInfo.getTestMethod().get().getName(); + } + @AfterTransaction - public void afterTransaction() { - if ("test01".equals(testName.getMethodName())) { + void afterTransaction() { + if ("test01".equals(testName)) { // Should throw a BadSqlGrammarException after test01, assuming 'drop-schema.sql' was executed - assertThatExceptionOfType(BadSqlGrammarException.class).isThrownBy(() -> - assertNumUsers(99)); + assertThatExceptionOfType(BadSqlGrammarException.class).isThrownBy(() -> assertNumUsers(99)); } } @Test - @SqlGroup({// - @Sql({ "schema.sql", "data.sql" }),// - @Sql(scripts = "drop-schema.sql", executionPhase = AFTER_TEST_METHOD) // + @SqlGroup({ + @Sql({ "schema.sql", "data.sql" }), + @Sql(scripts = "drop-schema.sql", executionPhase = AFTER_TEST_METHOD) }) - // test## is required for @FixMethodOrder. - public void test01() { + // test## is required for @TestMethodOrder. + void test01() { assertNumUsers(1); } @Test @Sql({ "schema.sql", "data.sql", "data-add-dogbert.sql" }) - // test## is required for @FixMethodOrder. - public void test02() { + // test## is required for @TestMethodOrder. + void test02() { assertNumUsers(2); } - protected void assertNumUsers(int expected) { - assertThat(countRowsInTable("user")).as("Number of rows in the 'user' table.").isEqualTo(expected); - } - } diff --git a/spring-test/src/test/java/org/springframework/test/context/jdbc/TransactionalInlinedStatementsSqlScriptsTests.java b/spring-test/src/test/java/org/springframework/test/context/jdbc/TransactionalInlinedStatementsSqlScriptsTests.java index 8095c52169..6e1628d84f 100644 --- a/spring-test/src/test/java/org/springframework/test/context/jdbc/TransactionalInlinedStatementsSqlScriptsTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/jdbc/TransactionalInlinedStatementsSqlScriptsTests.java @@ -16,20 +16,13 @@ package org.springframework.test.context.jdbc; -import org.junit.FixMethodOrder; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.MethodSorters; +import org.junit.jupiter.api.MethodOrderer; +import org.junit.jupiter.api.Order; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestMethodOrder; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import org.springframework.test.jdbc.JdbcTestUtils; -import org.springframework.transaction.annotation.Transactional; - -import static org.assertj.core.api.Assertions.assertThat; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; /** * Transactional integration tests for {@link Sql @Sql} support with @@ -39,23 +32,18 @@ import static org.assertj.core.api.Assertions.assertThat; * @since 4.2 * @see TransactionalSqlScriptsTests */ -@RunWith(SpringJUnit4ClassRunner.class) -@FixMethodOrder(MethodSorters.NAME_ASCENDING) -@ContextConfiguration(classes = EmptyDatabaseConfig.class) -@Transactional +@SpringJUnitConfig(EmptyDatabaseConfig.class) +@TestMethodOrder(MethodOrderer.OrderAnnotation.class) @Sql( scripts = "schema.sql", statements = "INSERT INTO user VALUES('Dilbert')" ) @DirtiesContext -public class TransactionalInlinedStatementsSqlScriptsTests { - - @Autowired - JdbcTemplate jdbcTemplate; +class TransactionalInlinedStatementsSqlScriptsTests extends AbstractTransactionalTests { @Test - // test##_ prefix is required for @FixMethodOrder. - public void test01_classLevelScripts() { + @Order(1) + void classLevelScripts() { assertNumUsers(1); } @@ -63,17 +51,9 @@ public class TransactionalInlinedStatementsSqlScriptsTests { @Sql(statements = "DROP TABLE user IF EXISTS") @Sql("schema.sql") @Sql(statements = "INSERT INTO user VALUES ('Dilbert'), ('Dogbert'), ('Catbert')") - // test##_ prefix is required for @FixMethodOrder. - public void test02_methodLevelScripts() { + @Order(2) + void methodLevelScripts() { assertNumUsers(3); } - protected int countRowsInTable(String tableName) { - return JdbcTestUtils.countRowsInTable(this.jdbcTemplate, tableName); - } - - protected void assertNumUsers(int expected) { - assertThat(countRowsInTable("user")).as("Number of rows in the 'user' table.").isEqualTo(expected); - } - } diff --git a/spring-test/src/test/java/org/springframework/test/context/jdbc/TransactionalSqlScriptsTests.java b/spring-test/src/test/java/org/springframework/test/context/jdbc/TransactionalSqlScriptsTests.java index 097f6b5127..1bb5ad5032 100644 --- a/spring-test/src/test/java/org/springframework/test/context/jdbc/TransactionalSqlScriptsTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/jdbc/TransactionalSqlScriptsTests.java @@ -16,20 +16,13 @@ package org.springframework.test.context.jdbc; -import org.junit.FixMethodOrder; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.MethodSorters; +import org.junit.jupiter.api.MethodOrderer; +import org.junit.jupiter.api.Order; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestMethodOrder; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import org.springframework.test.jdbc.JdbcTestUtils; -import org.springframework.transaction.annotation.Transactional; - -import static org.assertj.core.api.Assertions.assertThat; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; /** * Transactional integration tests for {@link Sql @Sql} support. @@ -37,36 +30,23 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Sam Brannen * @since 4.1 */ -@RunWith(SpringJUnit4ClassRunner.class) -@FixMethodOrder(MethodSorters.NAME_ASCENDING) -@ContextConfiguration(classes = EmptyDatabaseConfig.class) -@Transactional +@SpringJUnitConfig(EmptyDatabaseConfig.class) +@TestMethodOrder(MethodOrderer.OrderAnnotation.class) @Sql({ "schema.sql", "data.sql" }) @DirtiesContext -public class TransactionalSqlScriptsTests { - - @Autowired - JdbcTemplate jdbcTemplate; +public class TransactionalSqlScriptsTests extends AbstractTransactionalTests { @Test - // test##_ prefix is required for @FixMethodOrder. - public void test01_classLevelScripts() { + @Order(1) + public void classLevelScripts() { assertNumUsers(1); } @Test @Sql({ "recreate-schema.sql", "data.sql", "data-add-dogbert.sql" }) - // test##_ prefix is required for @FixMethodOrder. - public void test02_methodLevelScripts() { + @Order(2) + public void methodLevelScripts() { assertNumUsers(2); } - protected int countRowsInTable(String tableName) { - return JdbcTestUtils.countRowsInTable(this.jdbcTemplate, tableName); - } - - protected void assertNumUsers(int expected) { - assertThat(countRowsInTable("user")).as("Number of rows in the 'user' table.").isEqualTo(expected); - } - } diff --git a/spring-test/src/test/java/org/springframework/test/context/jdbc/merging/AbstractSqlMergeModeTests.java b/spring-test/src/test/java/org/springframework/test/context/jdbc/merging/AbstractSqlMergeModeTests.java index 90f9c4f53e..bed80c8ced 100644 --- a/spring-test/src/test/java/org/springframework/test/context/jdbc/merging/AbstractSqlMergeModeTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/jdbc/merging/AbstractSqlMergeModeTests.java @@ -16,15 +16,11 @@ package org.springframework.test.context.jdbc.merging; -import java.util.List; - import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.jdbc.AbstractTransactionalTests; import org.springframework.test.context.jdbc.EmptyDatabaseConfig; import org.springframework.test.context.jdbc.SqlMergeMode; -import org.springframework.test.context.junit4.AbstractTransactionalJUnit4SpringContextTests; - -import static org.assertj.core.api.Assertions.assertThat; /** * Abstract base class for tests involving {@link SqlMergeMode @SqlMergeMode}. @@ -34,11 +30,6 @@ import static org.assertj.core.api.Assertions.assertThat; */ @ContextConfiguration(classes = EmptyDatabaseConfig.class) @DirtiesContext -abstract class AbstractSqlMergeModeTests extends AbstractTransactionalJUnit4SpringContextTests { - - protected void assertUsers(String... expectedUsers) { - List actualUsers = super.jdbcTemplate.queryForList("select name from user", String.class); - assertThat(actualUsers).containsExactlyInAnyOrder(expectedUsers); - } +abstract class AbstractSqlMergeModeTests extends AbstractTransactionalTests { } diff --git a/spring-test/src/test/java/org/springframework/test/context/jdbc/merging/ClassLevelMergeSqlMergeModeTests.java b/spring-test/src/test/java/org/springframework/test/context/jdbc/merging/ClassLevelMergeSqlMergeModeTests.java index cabdfdb0a0..9fa876c1ee 100644 --- a/spring-test/src/test/java/org/springframework/test/context/jdbc/merging/ClassLevelMergeSqlMergeModeTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/jdbc/merging/ClassLevelMergeSqlMergeModeTests.java @@ -16,7 +16,7 @@ package org.springframework.test.context.jdbc.merging; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.test.context.jdbc.Sql; import org.springframework.test.context.jdbc.SqlMergeMode; @@ -36,23 +36,23 @@ import static org.springframework.test.context.jdbc.SqlMergeMode.MergeMode.OVERR */ @Sql({ "../recreate-schema.sql", "../data-add-catbert.sql" }) @SqlMergeMode(MERGE) -public class ClassLevelMergeSqlMergeModeTests extends AbstractSqlMergeModeTests { +class ClassLevelMergeSqlMergeModeTests extends AbstractSqlMergeModeTests { @Test - public void classLevelScripts() { + void classLevelScripts() { assertUsers("Catbert"); } @Test @Sql("../data-add-dogbert.sql") - public void merged() { + void merged() { assertUsers("Catbert", "Dogbert"); } @Test @Sql({ "../recreate-schema.sql", "../data.sql", "../data-add-dogbert.sql", "../data-add-catbert.sql" }) @SqlMergeMode(OVERRIDE) - public void overridden() { + void overridden() { assertUsers("Dilbert", "Dogbert", "Catbert"); } diff --git a/spring-test/src/test/java/org/springframework/test/context/jdbc/merging/ClassLevelOverrideSqlMergeModeTests.java b/spring-test/src/test/java/org/springframework/test/context/jdbc/merging/ClassLevelOverrideSqlMergeModeTests.java index 12117ede9c..2de1e6a98d 100644 --- a/spring-test/src/test/java/org/springframework/test/context/jdbc/merging/ClassLevelOverrideSqlMergeModeTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/jdbc/merging/ClassLevelOverrideSqlMergeModeTests.java @@ -16,7 +16,7 @@ package org.springframework.test.context.jdbc.merging; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.test.context.jdbc.Sql; import org.springframework.test.context.jdbc.SqlMergeMode; @@ -36,23 +36,23 @@ import static org.springframework.test.context.jdbc.SqlMergeMode.MergeMode.OVERR */ @Sql({ "../recreate-schema.sql", "../data-add-catbert.sql" }) @SqlMergeMode(OVERRIDE) -public class ClassLevelOverrideSqlMergeModeTests extends AbstractSqlMergeModeTests { +class ClassLevelOverrideSqlMergeModeTests extends AbstractSqlMergeModeTests { @Test - public void classLevelScripts() { + void classLevelScripts() { assertUsers("Catbert"); } @Test @Sql("../data-add-dogbert.sql") @SqlMergeMode(MERGE) - public void merged() { + void merged() { assertUsers("Catbert", "Dogbert"); } @Test @Sql({ "../recreate-schema.sql", "../data.sql", "../data-add-dogbert.sql", "../data-add-catbert.sql" }) - public void overridden() { + void overridden() { assertUsers("Dilbert", "Dogbert", "Catbert"); } diff --git a/spring-test/src/test/java/org/springframework/test/context/junit4/SpringJUnit4TestSuite.java b/spring-test/src/test/java/org/springframework/test/context/junit4/SpringJUnit4TestSuite.java index b41b51d597..13222ed97f 100644 --- a/spring-test/src/test/java/org/springframework/test/context/junit4/SpringJUnit4TestSuite.java +++ b/spring-test/src/test/java/org/springframework/test/context/junit4/SpringJUnit4TestSuite.java @@ -20,9 +20,6 @@ import org.junit.runner.RunWith; import org.junit.runners.Suite; import org.junit.runners.Suite.SuiteClasses; -import org.springframework.test.context.cache.ClassLevelDirtiesContextTests; -import org.springframework.test.context.cache.SpringRunnerContextCacheTests; -import org.springframework.test.context.jdbc.IsolatedTransactionModeSqlScriptsTests; import org.springframework.test.context.junit4.annotation.AnnotationConfigSpringJUnit4ClassRunnerAppCtxTests; import org.springframework.test.context.junit4.annotation.BeanOverridingDefaultConfigClassesInheritedTests; import org.springframework.test.context.junit4.annotation.BeanOverridingExplicitConfigClassesInheritedTests; @@ -43,7 +40,6 @@ import org.springframework.test.context.junit4.profile.annotation.DevProfileReso import org.springframework.test.context.junit4.profile.xml.DefaultProfileXmlConfigTests; import org.springframework.test.context.junit4.profile.xml.DevProfileResolverXmlConfigTests; import org.springframework.test.context.junit4.profile.xml.DevProfileXmlConfigTests; -import org.springframework.test.context.transaction.programmatic.ProgrammaticTxMgmtTests; /** * JUnit test suite for tests involving {@link SpringRunner} and the @@ -99,8 +95,6 @@ StandardJUnit4FeaturesTests.class,// InheritedConfigSpringJUnit4ClassRunnerAppCtxTests.class,// PropertiesBasedSpringJUnit4ClassRunnerAppCtxTests.class,// CustomDefaultContextLoaderClassSpringRunnerTests.class,// - SpringRunnerContextCacheTests.class,// - ClassLevelDirtiesContextTests.class,// ParameterizedDependencyInjectionTests.class,// ConcreteTransactionalJUnit4SpringContextTests.class,// ClassLevelTransactionalSpringRunnerTests.class,// @@ -111,8 +105,6 @@ StandardJUnit4FeaturesTests.class,// RollbackOverrideDefaultRollbackFalseTransactionalTests.class,// BeforeAndAfterTransactionAnnotationTests.class,// TimedTransactionalSpringRunnerTests.class,// - ProgrammaticTxMgmtTests.class,// - IsolatedTransactionModeSqlScriptsTests.class,// HibernateSessionFlushingTests.class // }) public class SpringJUnit4TestSuite { diff --git a/spring-test/src/test/java/org/springframework/test/context/junit4/concurrency/SpringJUnit4ConcurrencyTests.java b/spring-test/src/test/java/org/springframework/test/context/junit4/concurrency/SpringJUnit4ConcurrencyTests.java index 941ed2edf7..e27ac1701e 100644 --- a/spring-test/src/test/java/org/springframework/test/context/junit4/concurrency/SpringJUnit4ConcurrencyTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/junit4/concurrency/SpringJUnit4ConcurrencyTests.java @@ -24,7 +24,6 @@ import org.junit.Ignore; import org.junit.Test; import org.junit.experimental.ParallelComputer; -import org.springframework.test.context.hierarchies.web.DispatcherWacRootWacEarTests; import org.springframework.test.context.junit4.InheritedConfigSpringJUnit4ClassRunnerAppCtxTests; import org.springframework.test.context.junit4.MethodLevelTransactionalSpringRunnerTests; import org.springframework.test.context.junit4.SpringJUnit47ClassRunnerRuleTests; @@ -35,11 +34,6 @@ import org.springframework.test.context.junit4.rules.BaseAppCtxRuleTests; import org.springframework.test.context.junit4.rules.BasicAnnotationConfigWacSpringRuleTests; import org.springframework.test.context.junit4.rules.SpringClassRule; import org.springframework.test.context.junit4.rules.SpringMethodRule; -import org.springframework.test.context.web.RequestAndSessionScopedBeansWacTests; -import org.springframework.test.context.web.socket.WebSocketServletServerContainerFactoryBeanTests; -import org.springframework.test.web.client.samples.SampleTests; -import org.springframework.test.web.servlet.samples.context.JavaConfigTests; -import org.springframework.test.web.servlet.samples.context.WebAppResourceTests; import org.springframework.tests.TestGroup; import org.springframework.tests.TestGroups; import org.springframework.util.ReflectionUtils; @@ -85,14 +79,8 @@ public class SpringJUnit4ConcurrencyTests { MethodLevelTransactionalSpringRunnerTests.class, TimedTransactionalSpringRunnerTests.class, // Web and Scopes - DispatcherWacRootWacEarTests.class, BasicAnnotationConfigWacSpringRuleTests.class, - RequestAndSessionScopedBeansWacTests.class, - WebSocketServletServerContainerFactoryBeanTests.class, // Spring MVC Test - JavaConfigTests.class, - WebAppResourceTests.class, - SampleTests.class }; diff --git a/spring-test/src/test/java/org/springframework/test/context/junit4/rules/ProgrammaticTxMgmtSpringRuleTests.java b/spring-test/src/test/java/org/springframework/test/context/junit4/rules/ProgrammaticTxMgmtSpringRuleTests.java index 8bd5043cfb..4480d4cc32 100644 --- a/spring-test/src/test/java/org/springframework/test/context/junit4/rules/ProgrammaticTxMgmtSpringRuleTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/junit4/rules/ProgrammaticTxMgmtSpringRuleTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2015 the original author or authors. + * Copyright 2002-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,32 +16,55 @@ package org.springframework.test.context.junit4.rules; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; import javax.sql.DataSource; import org.junit.ClassRule; import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.TestName; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.core.io.Resource; +import org.springframework.dao.DataAccessException; +import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.datasource.DataSourceTransactionManager; import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder; +import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator; +import org.springframework.test.annotation.Commit; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.transaction.programmatic.ProgrammaticTxMgmtTests; +import org.springframework.test.context.transaction.AfterTransaction; +import org.springframework.test.context.transaction.BeforeTransaction; +import org.springframework.test.context.transaction.TestTransaction; +import org.springframework.test.jdbc.JdbcTestUtils; import org.springframework.transaction.PlatformTransactionManager; +import org.springframework.transaction.annotation.Propagation; +import org.springframework.transaction.annotation.Transactional; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatIllegalStateException; +import static org.assertj.core.api.Assertions.fail; +import static org.springframework.test.transaction.TransactionAssert.assertThatTransaction; /** - * This class is an extension of {@link ProgrammaticTxMgmtTests} - * that has been modified to use {@link SpringClassRule} and - * {@link SpringMethodRule}. + * This class is a copy of + * {@link org.springframework.test.context.transaction.programmatic.ProgrammaticTxMgmtTests} + * that has been modified to use {@link SpringClassRule} and {@link SpringMethodRule}. * * @author Sam Brannen * @since 4.2 */ @RunWith(JUnit4.class) @ContextConfiguration -public class ProgrammaticTxMgmtSpringRuleTests extends ProgrammaticTxMgmtTests { +@Transactional +public class ProgrammaticTxMgmtSpringRuleTests { @ClassRule public static final SpringClassRule springClassRule = new SpringClassRule(); @@ -49,20 +72,232 @@ public class ProgrammaticTxMgmtSpringRuleTests extends ProgrammaticTxMgmtTests { @Rule public final SpringMethodRule springMethodRule = new SpringMethodRule(); - // All tests are in superclass. + @Rule + public TestName testName = new TestName(); + + String sqlScriptEncoding; + JdbcTemplate jdbcTemplate; + + @Autowired + ApplicationContext applicationContext; + + @Autowired + void setDataSource(DataSource dataSource) { + this.jdbcTemplate = new JdbcTemplate(dataSource); + } + + @BeforeTransaction + void beforeTransaction() { + deleteFromTables("user"); + executeSqlScript("classpath:/org/springframework/test/context/jdbc/data.sql", false); + } + + @AfterTransaction + void afterTransaction() { + String method = this.testName.getMethodName(); + switch (method) { + case "commitTxAndStartNewTx": + case "commitTxButDoNotStartNewTx": { + assertUsers("Dogbert"); + break; + } + case "rollbackTxAndStartNewTx": + case "rollbackTxButDoNotStartNewTx": + case "startTxWithExistingTransaction": { + assertUsers("Dilbert"); + break; + } + case "rollbackTxAndStartNewTxWithDefaultCommitSemantics": { + assertUsers("Dilbert", "Dogbert"); + break; + } + default: { + fail("missing 'after transaction' assertion for test method: " + method); + } + } + } + + @Test + @Transactional(propagation = Propagation.NOT_SUPPORTED) + public void isActiveWithNonExistentTransactionContext() { + assertThat(TestTransaction.isActive()).isFalse(); + } + + @Test + @Transactional(propagation = Propagation.NOT_SUPPORTED) + public void flagForRollbackWithNonExistentTransactionContext() { + assertThatIllegalStateException().isThrownBy(TestTransaction::flagForRollback); + } + + @Test + @Transactional(propagation = Propagation.NOT_SUPPORTED) + public void flagForCommitWithNonExistentTransactionContext() { + assertThatIllegalStateException().isThrownBy(TestTransaction::flagForCommit); + } + + @Test + @Transactional(propagation = Propagation.NOT_SUPPORTED) + public void isFlaggedForRollbackWithNonExistentTransactionContext() { + assertThatIllegalStateException().isThrownBy(TestTransaction::isFlaggedForRollback); + } + + @Test + @Transactional(propagation = Propagation.NOT_SUPPORTED) + public void startTxWithNonExistentTransactionContext() { + assertThatIllegalStateException().isThrownBy(TestTransaction::start); + } + + @Test + public void startTxWithExistingTransaction() { + assertThatIllegalStateException().isThrownBy(TestTransaction::start); + } + + @Test + @Transactional(propagation = Propagation.NOT_SUPPORTED) + public void endTxWithNonExistentTransactionContext() { + assertThatIllegalStateException().isThrownBy(TestTransaction::end); + } + + @Test + public void commitTxAndStartNewTx() { + assertThatTransaction().isActive(); + assertThat(TestTransaction.isActive()).isTrue(); + assertUsers("Dilbert"); + deleteFromTables("user"); + assertUsers(); + + // Commit + TestTransaction.flagForCommit(); + assertThat(TestTransaction.isFlaggedForRollback()).isFalse(); + TestTransaction.end(); + assertThatTransaction().isNotActive(); + assertThat(TestTransaction.isActive()).isFalse(); + assertUsers(); + + executeSqlScript("classpath:/org/springframework/test/context/jdbc/data-add-dogbert.sql", false); + assertUsers("Dogbert"); + + TestTransaction.start(); + assertThatTransaction().isActive(); + assertThat(TestTransaction.isActive()).isTrue(); + } + + @Test + public void commitTxButDoNotStartNewTx() { + assertThatTransaction().isActive(); + assertThat(TestTransaction.isActive()).isTrue(); + assertUsers("Dilbert"); + deleteFromTables("user"); + assertUsers(); + + // Commit + TestTransaction.flagForCommit(); + assertThat(TestTransaction.isFlaggedForRollback()).isFalse(); + TestTransaction.end(); + assertThat(TestTransaction.isActive()).isFalse(); + assertThatTransaction().isNotActive(); + assertUsers(); + + executeSqlScript("classpath:/org/springframework/test/context/jdbc/data-add-dogbert.sql", false); + assertUsers("Dogbert"); + } + + @Test + public void rollbackTxAndStartNewTx() { + assertThatTransaction().isActive(); + assertThat(TestTransaction.isActive()).isTrue(); + assertUsers("Dilbert"); + deleteFromTables("user"); + assertUsers(); + + // Rollback (automatically) + assertThat(TestTransaction.isFlaggedForRollback()).isTrue(); + TestTransaction.end(); + assertThat(TestTransaction.isActive()).isFalse(); + assertThatTransaction().isNotActive(); + assertUsers("Dilbert"); + + // Start new transaction with default rollback semantics + TestTransaction.start(); + assertThatTransaction().isActive(); + assertThat(TestTransaction.isFlaggedForRollback()).isTrue(); + assertThat(TestTransaction.isActive()).isTrue(); + + executeSqlScript("classpath:/org/springframework/test/context/jdbc/data-add-dogbert.sql", false); + assertUsers("Dilbert", "Dogbert"); + } + + @Test + public void rollbackTxButDoNotStartNewTx() { + assertThatTransaction().isActive(); + assertThat(TestTransaction.isActive()).isTrue(); + assertUsers("Dilbert"); + deleteFromTables("user"); + assertUsers(); + + // Rollback (automatically) + assertThat(TestTransaction.isFlaggedForRollback()).isTrue(); + TestTransaction.end(); + assertThat(TestTransaction.isActive()).isFalse(); + assertThatTransaction().isNotActive(); + assertUsers("Dilbert"); + } + + @Test + @Commit + public void rollbackTxAndStartNewTxWithDefaultCommitSemantics() { + assertThatTransaction().isActive(); + assertThat(TestTransaction.isActive()).isTrue(); + assertUsers("Dilbert"); + deleteFromTables("user"); + assertUsers(); + + // Rollback + TestTransaction.flagForRollback(); + assertThat(TestTransaction.isFlaggedForRollback()).isTrue(); + TestTransaction.end(); + assertThat(TestTransaction.isActive()).isFalse(); + assertThatTransaction().isNotActive(); + assertUsers("Dilbert"); + + // Start new transaction with default commit semantics + TestTransaction.start(); + assertThatTransaction().isActive(); + assertThat(TestTransaction.isFlaggedForRollback()).isFalse(); + assertThat(TestTransaction.isActive()).isTrue(); + + executeSqlScript("classpath:/org/springframework/test/context/jdbc/data-add-dogbert.sql", false); + assertUsers("Dilbert", "Dogbert"); + } + + protected int deleteFromTables(String... names) { + return JdbcTestUtils.deleteFromTables(this.jdbcTemplate, names); + } + + protected void executeSqlScript(String sqlResourcePath, boolean continueOnError) throws DataAccessException { + Resource resource = this.applicationContext.getResource(sqlResourcePath); + new ResourceDatabasePopulator(continueOnError, false, this.sqlScriptEncoding, resource).execute(jdbcTemplate.getDataSource()); + } + + private void assertUsers(String... users) { + List expected = Arrays.asList(users); + Collections.sort(expected); + List actual = jdbcTemplate.queryForList("select name from user", String.class); + Collections.sort(actual); + assertThat(actual).as("Users in database;").isEqualTo(expected); + } - // ------------------------------------------------------------------------- @Configuration static class Config { @Bean - public PlatformTransactionManager transactionManager() { + PlatformTransactionManager transactionManager() { return new DataSourceTransactionManager(dataSource()); } @Bean - public DataSource dataSource() { + DataSource dataSource() { return new EmbeddedDatabaseBuilder()// .generateUniqueName(true)// .addScript("classpath:/org/springframework/test/context/jdbc/schema.sql") // diff --git a/spring-test/src/test/java/org/springframework/test/context/junit4/rules/TransactionalSqlScriptsSpringRuleTests.java b/spring-test/src/test/java/org/springframework/test/context/junit4/rules/TransactionalSqlScriptsSpringRuleTests.java index 523a3b36eb..8132c4e9ae 100644 --- a/spring-test/src/test/java/org/springframework/test/context/junit4/rules/TransactionalSqlScriptsSpringRuleTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/junit4/rules/TransactionalSqlScriptsSpringRuleTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2015 the original author or authors. + * Copyright 2002-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -60,8 +60,7 @@ public class TransactionalSqlScriptsSpringRuleTests extends TransactionalSqlScri */ @Test @Override - // test##_ prefix is required for @FixMethodOrder. - public void test01_classLevelScripts() { + public void classLevelScripts() { assertNumUsers(1); } @@ -71,8 +70,7 @@ public class TransactionalSqlScriptsSpringRuleTests extends TransactionalSqlScri @Test @Sql({ "../../jdbc/drop-schema.sql", "../../jdbc/schema.sql", "../../jdbc/data.sql", "../../jdbc/data-add-dogbert.sql" }) @Override - // test##_ prefix is required for @FixMethodOrder. - public void test02_methodLevelScripts() { + public void methodLevelScripts() { assertNumUsers(2); } diff --git a/spring-test/src/test/java/org/springframework/test/context/support/ActiveProfilesUtilsTests.java b/spring-test/src/test/java/org/springframework/test/context/support/ActiveProfilesUtilsTests.java index 2444018717..cc48df4885 100644 --- a/spring-test/src/test/java/org/springframework/test/context/support/ActiveProfilesUtilsTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/support/ActiveProfilesUtilsTests.java @@ -24,7 +24,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.core.annotation.AnnotationConfigurationException; import org.springframework.test.context.ActiveProfiles; @@ -44,59 +44,59 @@ import static org.springframework.test.context.support.ActiveProfilesUtils.resol * @author Michail Nikolaev * @since 3.1 */ -public class ActiveProfilesUtilsTests extends AbstractContextConfigurationUtilsTests { +class ActiveProfilesUtilsTests extends AbstractContextConfigurationUtilsTests { private void assertResolvedProfiles(Class testClass, String... expected) { assertThat(resolveActiveProfiles(testClass)).isEqualTo(expected); } @Test - public void resolveActiveProfilesWithoutAnnotation() { + void resolveActiveProfilesWithoutAnnotation() { assertResolvedProfiles(Enigma.class, EMPTY_STRING_ARRAY); } @Test - public void resolveActiveProfilesWithNoProfilesDeclared() { + void resolveActiveProfilesWithNoProfilesDeclared() { assertResolvedProfiles(BareAnnotations.class, EMPTY_STRING_ARRAY); } @Test - public void resolveActiveProfilesWithEmptyProfiles() { + void resolveActiveProfilesWithEmptyProfiles() { assertResolvedProfiles(EmptyProfiles.class, EMPTY_STRING_ARRAY); } @Test - public void resolveActiveProfilesWithDuplicatedProfiles() { + void resolveActiveProfilesWithDuplicatedProfiles() { assertResolvedProfiles(DuplicatedProfiles.class, "foo", "bar", "baz"); } @Test - public void resolveActiveProfilesWithLocalAndInheritedDuplicatedProfiles() { + void resolveActiveProfilesWithLocalAndInheritedDuplicatedProfiles() { assertResolvedProfiles(ExtendedDuplicatedProfiles.class, "foo", "bar", "baz", "cat", "dog"); } @Test - public void resolveActiveProfilesWithLocalAnnotation() { + void resolveActiveProfilesWithLocalAnnotation() { assertResolvedProfiles(LocationsFoo.class, "foo"); } @Test - public void resolveActiveProfilesWithInheritedAnnotationAndLocations() { + void resolveActiveProfilesWithInheritedAnnotationAndLocations() { assertResolvedProfiles(InheritedLocationsFoo.class, "foo"); } @Test - public void resolveActiveProfilesWithInheritedAnnotationAndClasses() { + void resolveActiveProfilesWithInheritedAnnotationAndClasses() { assertResolvedProfiles(InheritedClassesFoo.class, "foo"); } @Test - public void resolveActiveProfilesWithLocalAndInheritedAnnotations() { + void resolveActiveProfilesWithLocalAndInheritedAnnotations() { assertResolvedProfiles(LocationsBar.class, "foo", "bar"); } @Test - public void resolveActiveProfilesWithOverriddenAnnotation() { + void resolveActiveProfilesWithOverriddenAnnotation() { assertResolvedProfiles(Animals.class, "dog", "cat"); } @@ -104,7 +104,7 @@ public class ActiveProfilesUtilsTests extends AbstractContextConfigurationUtilsT * @since 4.0 */ @Test - public void resolveActiveProfilesWithMetaAnnotation() { + void resolveActiveProfilesWithMetaAnnotation() { assertResolvedProfiles(MetaLocationsFoo.class, "foo"); } @@ -112,7 +112,7 @@ public class ActiveProfilesUtilsTests extends AbstractContextConfigurationUtilsT * @since 4.0 */ @Test - public void resolveActiveProfilesWithMetaAnnotationAndOverrides() { + void resolveActiveProfilesWithMetaAnnotationAndOverrides() { assertResolvedProfiles(MetaLocationsFooWithOverrides.class, "foo"); } @@ -120,7 +120,7 @@ public class ActiveProfilesUtilsTests extends AbstractContextConfigurationUtilsT * @since 4.0 */ @Test - public void resolveActiveProfilesWithMetaAnnotationAndOverriddenAttributes() { + void resolveActiveProfilesWithMetaAnnotationAndOverriddenAttributes() { assertResolvedProfiles(MetaLocationsFooWithOverriddenAttributes.class, "foo1", "foo2"); } @@ -128,7 +128,7 @@ public class ActiveProfilesUtilsTests extends AbstractContextConfigurationUtilsT * @since 4.0 */ @Test - public void resolveActiveProfilesWithLocalAndInheritedMetaAnnotations() { + void resolveActiveProfilesWithLocalAndInheritedMetaAnnotations() { assertResolvedProfiles(MetaLocationsBar.class, "foo", "bar"); } @@ -136,7 +136,7 @@ public class ActiveProfilesUtilsTests extends AbstractContextConfigurationUtilsT * @since 4.0 */ @Test - public void resolveActiveProfilesWithOverriddenMetaAnnotation() { + void resolveActiveProfilesWithOverriddenMetaAnnotation() { assertResolvedProfiles(MetaAnimals.class, "dog", "cat"); } @@ -144,7 +144,7 @@ public class ActiveProfilesUtilsTests extends AbstractContextConfigurationUtilsT * @since 4.0 */ @Test - public void resolveActiveProfilesWithResolver() { + void resolveActiveProfilesWithResolver() { assertResolvedProfiles(FooActiveProfilesResolverTestCase.class, "foo"); } @@ -152,7 +152,7 @@ public class ActiveProfilesUtilsTests extends AbstractContextConfigurationUtilsT * @since 4.0 */ @Test - public void resolveActiveProfilesWithInheritedResolver() { + void resolveActiveProfilesWithInheritedResolver() { assertResolvedProfiles(InheritedFooActiveProfilesResolverTestCase.class, "foo"); } @@ -160,7 +160,7 @@ public class ActiveProfilesUtilsTests extends AbstractContextConfigurationUtilsT * @since 4.0 */ @Test - public void resolveActiveProfilesWithMergedInheritedResolver() { + void resolveActiveProfilesWithMergedInheritedResolver() { assertResolvedProfiles(MergedInheritedFooActiveProfilesResolverTestCase.class, "foo", "bar"); } @@ -168,7 +168,7 @@ public class ActiveProfilesUtilsTests extends AbstractContextConfigurationUtilsT * @since 4.0 */ @Test - public void resolveActiveProfilesWithOverridenInheritedResolver() { + void resolveActiveProfilesWithOverridenInheritedResolver() { assertResolvedProfiles(OverridenInheritedFooActiveProfilesResolverTestCase.class, "bar"); } @@ -176,7 +176,7 @@ public class ActiveProfilesUtilsTests extends AbstractContextConfigurationUtilsT * @since 4.0 */ @Test - public void resolveActiveProfilesWithResolverAndProfiles() { + void resolveActiveProfilesWithResolverAndProfiles() { assertResolvedProfiles(ResolverAndProfilesTestCase.class, "bar"); } @@ -184,7 +184,7 @@ public class ActiveProfilesUtilsTests extends AbstractContextConfigurationUtilsT * @since 4.0 */ @Test - public void resolveActiveProfilesWithResolverAndValue() { + void resolveActiveProfilesWithResolverAndValue() { assertResolvedProfiles(ResolverAndValueTestCase.class, "bar"); } @@ -192,7 +192,7 @@ public class ActiveProfilesUtilsTests extends AbstractContextConfigurationUtilsT * @since 4.0 */ @Test - public void resolveActiveProfilesWithConflictingProfilesAndValue() { + void resolveActiveProfilesWithConflictingProfilesAndValue() { assertThatExceptionOfType(AnnotationConfigurationException.class).isThrownBy(() -> resolveActiveProfiles(ConflictingProfilesAndValueTestCase.class)); } @@ -201,7 +201,7 @@ public class ActiveProfilesUtilsTests extends AbstractContextConfigurationUtilsT * @since 4.0 */ @Test - public void resolveActiveProfilesWithResolverWithoutDefaultConstructor() { + void resolveActiveProfilesWithResolverWithoutDefaultConstructor() { assertThatIllegalStateException().isThrownBy(() -> resolveActiveProfiles(NoDefaultConstructorActiveProfilesResolverTestCase.class)); } @@ -209,7 +209,7 @@ public class ActiveProfilesUtilsTests extends AbstractContextConfigurationUtilsT /** * @since 4.0 */ - public void resolveActiveProfilesWithResolverThatReturnsNull() { + void resolveActiveProfilesWithResolverThatReturnsNull() { assertResolvedProfiles(NullActiveProfilesResolverTestCase.class); } @@ -219,7 +219,7 @@ public class ActiveProfilesUtilsTests extends AbstractContextConfigurationUtilsT * @since 4.0.3 */ @Test - public void resolveActiveProfilesWithMetaAnnotationAndTestClassVerifyingResolver() { + void resolveActiveProfilesWithMetaAnnotationAndTestClassVerifyingResolver() { Class testClass = TestClassVerifyingActiveProfilesResolverTestCase.class; assertResolvedProfiles(testClass, testClass.getSimpleName()); } @@ -229,7 +229,7 @@ public class ActiveProfilesUtilsTests extends AbstractContextConfigurationUtilsT * @since 4.1.5 */ @Test - public void resolveActiveProfilesWithDefaultActiveProfilesResolver() { + void resolveActiveProfilesWithDefaultActiveProfilesResolver() { assertResolvedProfiles(DefaultActiveProfilesResolverTestCase.class, "default"); } @@ -238,7 +238,7 @@ public class ActiveProfilesUtilsTests extends AbstractContextConfigurationUtilsT * @since 4.1.5 */ @Test - public void resolveActiveProfilesWithExtendedDefaultActiveProfilesResolver() { + void resolveActiveProfilesWithExtendedDefaultActiveProfilesResolver() { assertResolvedProfiles(ExtendedDefaultActiveProfilesResolverTestCase.class, "default", "foo"); } diff --git a/spring-test/src/test/java/org/springframework/test/context/support/AnnotationConfigContextLoaderTests.java b/spring-test/src/test/java/org/springframework/test/context/support/AnnotationConfigContextLoaderTests.java index 3aa9a4b2dd..aaac4af95e 100644 --- a/spring-test/src/test/java/org/springframework/test/context/support/AnnotationConfigContextLoaderTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/support/AnnotationConfigContextLoaderTests.java @@ -16,7 +16,7 @@ package org.springframework.test.context.support; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.test.context.MergedContextConfiguration; @@ -29,7 +29,7 @@ import static org.assertj.core.api.Assertions.assertThatIllegalStateException; * @author Sam Brannen * @since 3.1 */ -public class AnnotationConfigContextLoaderTests { +class AnnotationConfigContextLoaderTests { private final AnnotationConfigContextLoader contextLoader = new AnnotationConfigContextLoader(); @@ -41,7 +41,7 @@ public class AnnotationConfigContextLoaderTests { * @since 4.0.4 */ @Test - public void configMustNotContainLocations() throws Exception { + void configMustNotContainLocations() throws Exception { MergedContextConfiguration mergedConfig = new MergedContextConfiguration(getClass(), new String[] { "config.xml" }, EMPTY_CLASS_ARRAY, EMPTY_STRING_ARRAY, contextLoader); assertThatIllegalStateException().isThrownBy(() -> @@ -50,7 +50,7 @@ public class AnnotationConfigContextLoaderTests { } @Test - public void detectDefaultConfigurationClassesForAnnotatedInnerClass() { + void detectDefaultConfigurationClassesForAnnotatedInnerClass() { Class[] configClasses = contextLoader.detectDefaultConfigurationClasses(ContextConfigurationInnerClassTestCase.class); assertThat(configClasses).isNotNull(); assertThat(configClasses.length).as("annotated static ContextConfiguration should be considered.").isEqualTo(1); @@ -61,35 +61,35 @@ public class AnnotationConfigContextLoaderTests { } @Test - public void detectDefaultConfigurationClassesForMultipleAnnotatedInnerClasses() { + void detectDefaultConfigurationClassesForMultipleAnnotatedInnerClasses() { Class[] configClasses = contextLoader.detectDefaultConfigurationClasses(MultipleStaticConfigurationClassesTestCase.class); assertThat(configClasses).isNotNull(); assertThat(configClasses.length).as("multiple annotated static classes should be considered.").isEqualTo(2); } @Test - public void detectDefaultConfigurationClassesForNonAnnotatedInnerClass() { + void detectDefaultConfigurationClassesForNonAnnotatedInnerClass() { Class[] configClasses = contextLoader.detectDefaultConfigurationClasses(PlainVanillaFooConfigInnerClassTestCase.class); assertThat(configClasses).isNotNull(); assertThat(configClasses.length).as("non-annotated static FooConfig should NOT be considered.").isEqualTo(0); } @Test - public void detectDefaultConfigurationClassesForFinalAnnotatedInnerClass() { + void detectDefaultConfigurationClassesForFinalAnnotatedInnerClass() { Class[] configClasses = contextLoader.detectDefaultConfigurationClasses(FinalConfigInnerClassTestCase.class); assertThat(configClasses).isNotNull(); assertThat(configClasses.length).as("final annotated static Config should NOT be considered.").isEqualTo(0); } @Test - public void detectDefaultConfigurationClassesForPrivateAnnotatedInnerClass() { + void detectDefaultConfigurationClassesForPrivateAnnotatedInnerClass() { Class[] configClasses = contextLoader.detectDefaultConfigurationClasses(PrivateConfigInnerClassTestCase.class); assertThat(configClasses).isNotNull(); assertThat(configClasses.length).as("private annotated inner classes should NOT be considered.").isEqualTo(0); } @Test - public void detectDefaultConfigurationClassesForNonStaticAnnotatedInnerClass() { + void detectDefaultConfigurationClassesForNonStaticAnnotatedInnerClass() { Class[] configClasses = contextLoader.detectDefaultConfigurationClasses(NonStaticConfigInnerClassesTestCase.class); assertThat(configClasses).isNotNull(); assertThat(configClasses.length).as("non-static annotated inner classes should NOT be considered.").isEqualTo(0); diff --git a/spring-test/src/test/java/org/springframework/test/context/support/AnnotationConfigContextLoaderUtilsTests.java b/spring-test/src/test/java/org/springframework/test/context/support/AnnotationConfigContextLoaderUtilsTests.java index c75625191d..a8e97820c9 100644 --- a/spring-test/src/test/java/org/springframework/test/context/support/AnnotationConfigContextLoaderUtilsTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/support/AnnotationConfigContextLoaderUtilsTests.java @@ -21,7 +21,7 @@ import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.context.annotation.Configuration; @@ -35,30 +35,30 @@ import static org.springframework.test.context.support.AnnotationConfigContextLo * @author Sam Brannen * @since 4.1.5 */ -public class AnnotationConfigContextLoaderUtilsTests { +class AnnotationConfigContextLoaderUtilsTests { @Test - public void detectDefaultConfigurationClassesWithNullDeclaringClass() { + void detectDefaultConfigurationClassesWithNullDeclaringClass() { assertThatIllegalArgumentException().isThrownBy(() -> detectDefaultConfigurationClasses(null)); } @Test - public void detectDefaultConfigurationClassesWithoutConfigurationClass() { + void detectDefaultConfigurationClassesWithoutConfigurationClass() { Class[] configClasses = detectDefaultConfigurationClasses(NoConfigTestCase.class); assertThat(configClasses).isNotNull(); assertThat(configClasses.length).isEqualTo(0); } @Test - public void detectDefaultConfigurationClassesWithExplicitConfigurationAnnotation() { + void detectDefaultConfigurationClassesWithExplicitConfigurationAnnotation() { Class[] configClasses = detectDefaultConfigurationClasses(ExplicitConfigTestCase.class); assertThat(configClasses).isNotNull(); assertThat(configClasses).isEqualTo(new Class[] { ExplicitConfigTestCase.Config.class }); } @Test - public void detectDefaultConfigurationClassesWithConfigurationMetaAnnotation() { + void detectDefaultConfigurationClassesWithConfigurationMetaAnnotation() { Class[] configClasses = detectDefaultConfigurationClasses(MetaAnnotatedConfigTestCase.class); assertThat(configClasses).isNotNull(); assertThat(configClasses).isEqualTo(new Class[] { MetaAnnotatedConfigTestCase.Config.class }); diff --git a/spring-test/src/test/java/org/springframework/test/context/support/BootstrapTestUtilsContextInitializerTests.java b/spring-test/src/test/java/org/springframework/test/context/support/BootstrapTestUtilsContextInitializerTests.java index 278dc81fa9..e92282a4ca 100644 --- a/spring-test/src/test/java/org/springframework/test/context/support/BootstrapTestUtilsContextInitializerTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/support/BootstrapTestUtilsContextInitializerTests.java @@ -20,7 +20,7 @@ import java.util.Arrays; import java.util.HashSet; import java.util.Set; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.context.ApplicationContextInitializer; import org.springframework.context.support.GenericApplicationContext; @@ -36,10 +36,10 @@ import org.springframework.web.context.support.GenericWebApplicationContext; * @since 3.1 */ @SuppressWarnings("unchecked") -public class BootstrapTestUtilsContextInitializerTests extends AbstractContextConfigurationUtilsTests { +class BootstrapTestUtilsContextInitializerTests extends AbstractContextConfigurationUtilsTests { @Test - public void buildMergedConfigWithSingleLocalInitializer() { + void buildMergedConfigWithSingleLocalInitializer() { Class testClass = SingleInitializer.class; MergedContextConfiguration mergedConfig = buildMergedContextConfiguration(testClass); @@ -48,7 +48,7 @@ public class BootstrapTestUtilsContextInitializerTests extends AbstractContextCo } @Test - public void buildMergedConfigWithLocalInitializerAndConfigClass() { + void buildMergedConfigWithLocalInitializerAndConfigClass() { Class testClass = InitializersFoo.class; MergedContextConfiguration mergedConfig = buildMergedContextConfiguration(testClass); @@ -57,7 +57,7 @@ public class BootstrapTestUtilsContextInitializerTests extends AbstractContextCo } @Test - public void buildMergedConfigWithLocalAndInheritedInitializer() { + void buildMergedConfigWithLocalAndInheritedInitializer() { Class testClass = InitializersBar.class; MergedContextConfiguration mergedConfig = buildMergedContextConfiguration(testClass); @@ -66,7 +66,7 @@ public class BootstrapTestUtilsContextInitializerTests extends AbstractContextCo } @Test - public void buildMergedConfigWithOverriddenInitializers() { + void buildMergedConfigWithOverriddenInitializers() { Class testClass = OverriddenInitializersBar.class; MergedContextConfiguration mergedConfig = buildMergedContextConfiguration(testClass); @@ -75,7 +75,7 @@ public class BootstrapTestUtilsContextInitializerTests extends AbstractContextCo } @Test - public void buildMergedConfigWithOverriddenInitializersAndClasses() { + void buildMergedConfigWithOverriddenInitializersAndClasses() { Class testClass = OverriddenInitializersAndClassesBar.class; MergedContextConfiguration mergedConfig = buildMergedContextConfiguration(testClass); diff --git a/spring-test/src/test/java/org/springframework/test/context/support/BootstrapTestUtilsMergedConfigTests.java b/spring-test/src/test/java/org/springframework/test/context/support/BootstrapTestUtilsMergedConfigTests.java index 6d6d0652dd..04decf0595 100644 --- a/spring-test/src/test/java/org/springframework/test/context/support/BootstrapTestUtilsMergedConfigTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/support/BootstrapTestUtilsMergedConfigTests.java @@ -21,7 +21,7 @@ import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.test.context.BootstrapTestUtils; import org.springframework.test.context.ContextConfiguration; @@ -39,10 +39,10 @@ import static org.assertj.core.api.Assertions.assertThatIllegalStateException; * @author Sam Brannen * @since 3.1 */ -public class BootstrapTestUtilsMergedConfigTests extends AbstractContextConfigurationUtilsTests { +class BootstrapTestUtilsMergedConfigTests extends AbstractContextConfigurationUtilsTests { @Test - public void buildImplicitMergedConfigWithoutAnnotation() { + void buildImplicitMergedConfigWithoutAnnotation() { Class testClass = Enigma.class; MergedContextConfiguration mergedConfig = buildMergedContextConfiguration(testClass); @@ -53,7 +53,7 @@ public class BootstrapTestUtilsMergedConfigTests extends AbstractContextConfigur * @since 4.3 */ @Test - public void buildMergedConfigWithContextConfigurationWithoutLocationsClassesOrInitializers() { + void buildMergedConfigWithContextConfigurationWithoutLocationsClassesOrInitializers() { assertThatIllegalStateException().isThrownBy(() -> buildMergedContextConfiguration(MissingContextAttributesTestCase.class)) .withMessageStartingWith("DelegatingSmartContextLoader was unable to detect defaults, " @@ -61,7 +61,7 @@ public class BootstrapTestUtilsMergedConfigTests extends AbstractContextConfigur } @Test - public void buildMergedConfigWithBareAnnotations() { + void buildMergedConfigWithBareAnnotations() { Class testClass = BareAnnotations.class; MergedContextConfiguration mergedConfig = buildMergedContextConfiguration(testClass); @@ -73,7 +73,7 @@ public class BootstrapTestUtilsMergedConfigTests extends AbstractContextConfigur } @Test - public void buildMergedConfigWithLocalAnnotationAndLocations() { + void buildMergedConfigWithLocalAnnotationAndLocations() { Class testClass = LocationsFoo.class; MergedContextConfiguration mergedConfig = buildMergedContextConfiguration(testClass); @@ -82,7 +82,7 @@ public class BootstrapTestUtilsMergedConfigTests extends AbstractContextConfigur } @Test - public void buildMergedConfigWithMetaAnnotationAndLocations() { + void buildMergedConfigWithMetaAnnotationAndLocations() { Class testClass = MetaLocationsFoo.class; MergedContextConfiguration mergedConfig = buildMergedContextConfiguration(testClass); @@ -91,7 +91,7 @@ public class BootstrapTestUtilsMergedConfigTests extends AbstractContextConfigur } @Test - public void buildMergedConfigWithMetaAnnotationAndClasses() { + void buildMergedConfigWithMetaAnnotationAndClasses() { buildMergedConfigWithMetaAnnotationAndClasses(Dog.class); buildMergedConfigWithMetaAnnotationAndClasses(WorkingDog.class); buildMergedConfigWithMetaAnnotationAndClasses(GermanShepherd.class); @@ -104,7 +104,7 @@ public class BootstrapTestUtilsMergedConfigTests extends AbstractContextConfigur } @Test - public void buildMergedConfigWithLocalAnnotationAndClasses() { + void buildMergedConfigWithLocalAnnotationAndClasses() { Class testClass = ClassesFoo.class; MergedContextConfiguration mergedConfig = buildMergedContextConfiguration(testClass); @@ -117,7 +117,7 @@ public class BootstrapTestUtilsMergedConfigTests extends AbstractContextConfigur * Stack Overflow. */ @Test - public void buildMergedConfigWithAtWebAppConfigurationWithAnnotationAndClassesOnSuperclass() { + void buildMergedConfigWithAtWebAppConfigurationWithAnnotationAndClassesOnSuperclass() { Class webTestClass = WebClassesFoo.class; Class standardTestClass = ClassesFoo.class; WebMergedContextConfiguration webMergedConfig = (WebMergedContextConfiguration) buildMergedContextConfiguration(webTestClass); @@ -135,7 +135,7 @@ public class BootstrapTestUtilsMergedConfigTests extends AbstractContextConfigur } @Test - public void buildMergedConfigWithLocalAnnotationAndOverriddenContextLoaderAndLocations() { + void buildMergedConfigWithLocalAnnotationAndOverriddenContextLoaderAndLocations() { Class testClass = PropertiesLocationsFoo.class; Class expectedContextLoaderClass = GenericPropertiesContextLoader.class; MergedContextConfiguration mergedConfig = buildMergedContextConfiguration(testClass); @@ -145,7 +145,7 @@ public class BootstrapTestUtilsMergedConfigTests extends AbstractContextConfigur } @Test - public void buildMergedConfigWithLocalAnnotationAndOverriddenContextLoaderAndClasses() { + void buildMergedConfigWithLocalAnnotationAndOverriddenContextLoaderAndClasses() { Class testClass = PropertiesClassesFoo.class; Class expectedContextLoaderClass = GenericPropertiesContextLoader.class; MergedContextConfiguration mergedConfig = buildMergedContextConfiguration(testClass); @@ -155,7 +155,7 @@ public class BootstrapTestUtilsMergedConfigTests extends AbstractContextConfigur } @Test - public void buildMergedConfigWithLocalAndInheritedAnnotationsAndLocations() { + void buildMergedConfigWithLocalAndInheritedAnnotationsAndLocations() { Class testClass = LocationsBar.class; String[] expectedLocations = array("/foo.xml", "/bar.xml"); MergedContextConfiguration mergedConfig = buildMergedContextConfiguration(testClass); @@ -165,7 +165,7 @@ public class BootstrapTestUtilsMergedConfigTests extends AbstractContextConfigur } @Test - public void buildMergedConfigWithLocalAndInheritedAnnotationsAndClasses() { + void buildMergedConfigWithLocalAndInheritedAnnotationsAndClasses() { Class testClass = ClassesBar.class; Class[] expectedClasses = array(FooConfig.class, BarConfig.class); MergedContextConfiguration mergedConfig = buildMergedContextConfiguration(testClass); @@ -175,7 +175,7 @@ public class BootstrapTestUtilsMergedConfigTests extends AbstractContextConfigur } @Test - public void buildMergedConfigWithAnnotationsAndOverriddenLocations() { + void buildMergedConfigWithAnnotationsAndOverriddenLocations() { Class testClass = OverriddenLocationsBar.class; String[] expectedLocations = array("/bar.xml"); MergedContextConfiguration mergedConfig = buildMergedContextConfiguration(testClass); @@ -185,7 +185,7 @@ public class BootstrapTestUtilsMergedConfigTests extends AbstractContextConfigur } @Test - public void buildMergedConfigWithAnnotationsAndOverriddenClasses() { + void buildMergedConfigWithAnnotationsAndOverriddenClasses() { Class testClass = OverriddenClassesBar.class; Class[] expectedClasses = array(BarConfig.class); MergedContextConfiguration mergedConfig = buildMergedContextConfiguration(testClass); diff --git a/spring-test/src/test/java/org/springframework/test/context/support/ContextLoaderUtilsConfigurationAttributesTests.java b/spring-test/src/test/java/org/springframework/test/context/support/ContextLoaderUtilsConfigurationAttributesTests.java index 5a82f43fac..6420c1aaa7 100644 --- a/spring-test/src/test/java/org/springframework/test/context/support/ContextLoaderUtilsConfigurationAttributesTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/support/ContextLoaderUtilsConfigurationAttributesTests.java @@ -18,7 +18,7 @@ package org.springframework.test.context.support; import java.util.List; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.core.annotation.AnnotationConfigurationException; import org.springframework.test.context.ContextConfiguration; @@ -35,7 +35,7 @@ import static org.springframework.test.context.support.ContextLoaderUtils.resolv * @author Sam Brannen * @since 3.1 */ -public class ContextLoaderUtilsConfigurationAttributesTests extends AbstractContextConfigurationUtilsTests { +class ContextLoaderUtilsConfigurationAttributesTests extends AbstractContextConfigurationUtilsTests { private void assertLocationsFooAttributes(ContextConfigurationAttributes attributes) { assertAttributes(attributes, LocationsFoo.class, new String[] { "/foo.xml" }, EMPTY_CLASS_ARRAY, @@ -58,7 +58,7 @@ public class ContextLoaderUtilsConfigurationAttributesTests extends AbstractCont } @Test - public void resolveConfigAttributesWithConflictingLocations() { + void resolveConfigAttributesWithConflictingLocations() { assertThatExceptionOfType(AnnotationConfigurationException.class).isThrownBy(() -> resolveContextConfigurationAttributes(ConflictingLocations.class)) .withMessageStartingWith("Different @AliasFor mirror values") @@ -68,7 +68,7 @@ public class ContextLoaderUtilsConfigurationAttributesTests extends AbstractCont } @Test - public void resolveConfigAttributesWithBareAnnotations() { + void resolveConfigAttributesWithBareAnnotations() { Class testClass = BareAnnotations.class; List attributesList = resolveContextConfigurationAttributes(testClass); assertThat(attributesList).isNotNull(); @@ -78,7 +78,7 @@ public class ContextLoaderUtilsConfigurationAttributesTests extends AbstractCont } @Test - public void resolveConfigAttributesWithLocalAnnotationAndLocations() { + void resolveConfigAttributesWithLocalAnnotationAndLocations() { List attributesList = resolveContextConfigurationAttributes(LocationsFoo.class); assertThat(attributesList).isNotNull(); assertThat(attributesList.size()).isEqualTo(1); @@ -86,7 +86,7 @@ public class ContextLoaderUtilsConfigurationAttributesTests extends AbstractCont } @Test - public void resolveConfigAttributesWithMetaAnnotationAndLocations() { + void resolveConfigAttributesWithMetaAnnotationAndLocations() { Class testClass = MetaLocationsFoo.class; List attributesList = resolveContextConfigurationAttributes(testClass); assertThat(attributesList).isNotNull(); @@ -96,7 +96,7 @@ public class ContextLoaderUtilsConfigurationAttributesTests extends AbstractCont } @Test - public void resolveConfigAttributesWithMetaAnnotationAndLocationsAndOverrides() { + void resolveConfigAttributesWithMetaAnnotationAndLocationsAndOverrides() { Class testClass = MetaLocationsFooWithOverrides.class; List attributesList = resolveContextConfigurationAttributes(testClass); assertThat(attributesList).isNotNull(); @@ -106,7 +106,7 @@ public class ContextLoaderUtilsConfigurationAttributesTests extends AbstractCont } @Test - public void resolveConfigAttributesWithMetaAnnotationAndLocationsAndOverriddenAttributes() { + void resolveConfigAttributesWithMetaAnnotationAndLocationsAndOverriddenAttributes() { Class testClass = MetaLocationsFooWithOverriddenAttributes.class; List attributesList = resolveContextConfigurationAttributes(testClass); assertThat(attributesList).isNotNull(); @@ -116,7 +116,7 @@ public class ContextLoaderUtilsConfigurationAttributesTests extends AbstractCont } @Test - public void resolveConfigAttributesWithMetaAnnotationAndLocationsInClassHierarchy() { + void resolveConfigAttributesWithMetaAnnotationAndLocationsInClassHierarchy() { Class testClass = MetaLocationsBar.class; List attributesList = resolveContextConfigurationAttributes(testClass); assertThat(attributesList).isNotNull(); @@ -128,7 +128,7 @@ public class ContextLoaderUtilsConfigurationAttributesTests extends AbstractCont } @Test - public void resolveConfigAttributesWithLocalAnnotationAndClasses() { + void resolveConfigAttributesWithLocalAnnotationAndClasses() { List attributesList = resolveContextConfigurationAttributes(ClassesFoo.class); assertThat(attributesList).isNotNull(); assertThat(attributesList.size()).isEqualTo(1); @@ -136,7 +136,7 @@ public class ContextLoaderUtilsConfigurationAttributesTests extends AbstractCont } @Test - public void resolveConfigAttributesWithLocalAndInheritedAnnotationsAndLocations() { + void resolveConfigAttributesWithLocalAndInheritedAnnotationsAndLocations() { List attributesList = resolveContextConfigurationAttributes(LocationsBar.class); assertThat(attributesList).isNotNull(); assertThat(attributesList.size()).isEqualTo(2); @@ -145,7 +145,7 @@ public class ContextLoaderUtilsConfigurationAttributesTests extends AbstractCont } @Test - public void resolveConfigAttributesWithLocalAndInheritedAnnotationsAndClasses() { + void resolveConfigAttributesWithLocalAndInheritedAnnotationsAndClasses() { List attributesList = resolveContextConfigurationAttributes(ClassesBar.class); assertThat(attributesList).isNotNull(); assertThat(attributesList.size()).isEqualTo(2); @@ -158,7 +158,7 @@ public class ContextLoaderUtilsConfigurationAttributesTests extends AbstractCont * @since 4.0.4 */ @Test - public void resolveConfigAttributesWithLocationsAndClasses() { + void resolveConfigAttributesWithLocationsAndClasses() { List attributesList = resolveContextConfigurationAttributes(LocationsAndClasses.class); assertThat(attributesList).isNotNull(); assertThat(attributesList.size()).isEqualTo(1); diff --git a/spring-test/src/test/java/org/springframework/test/context/support/ContextLoaderUtilsContextHierarchyTests.java b/spring-test/src/test/java/org/springframework/test/context/support/ContextLoaderUtilsContextHierarchyTests.java index fbd20fe923..cf61b5e870 100644 --- a/spring-test/src/test/java/org/springframework/test/context/support/ContextLoaderUtilsContextHierarchyTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/support/ContextLoaderUtilsContextHierarchyTests.java @@ -22,7 +22,7 @@ import java.util.Iterator; import java.util.List; import java.util.Map; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.context.ApplicationContextInitializer; import org.springframework.context.ConfigurableApplicationContext; @@ -43,7 +43,7 @@ import static org.springframework.test.context.support.ContextLoaderUtils.resolv * @author Sam Brannen * @since 3.2.2 */ -public class ContextLoaderUtilsContextHierarchyTests extends AbstractContextConfigurationUtilsTests { +class ContextLoaderUtilsContextHierarchyTests extends AbstractContextConfigurationUtilsTests { private void debugConfigAttributes(List configAttributesList) { // for (ContextConfigurationAttributes configAttributes : configAttributesList) { @@ -52,19 +52,19 @@ public class ContextLoaderUtilsContextHierarchyTests extends AbstractContextConf } @Test - public void resolveContextHierarchyAttributesForSingleTestClassWithContextConfigurationAndContextHierarchy() { + void resolveContextHierarchyAttributesForSingleTestClassWithContextConfigurationAndContextHierarchy() { assertThatIllegalStateException().isThrownBy(() -> resolveContextHierarchyAttributes(SingleTestClassWithContextConfigurationAndContextHierarchy.class)); } @Test - public void resolveContextHierarchyAttributesForSingleTestClassWithContextConfigurationAndContextHierarchyOnSingleMetaAnnotation() { + void resolveContextHierarchyAttributesForSingleTestClassWithContextConfigurationAndContextHierarchyOnSingleMetaAnnotation() { assertThatIllegalStateException().isThrownBy(() -> resolveContextHierarchyAttributes(SingleTestClassWithContextConfigurationAndContextHierarchyOnSingleMetaAnnotation.class)); } @Test - public void resolveContextHierarchyAttributesForSingleTestClassWithImplicitSingleLevelContextHierarchy() { + void resolveContextHierarchyAttributesForSingleTestClassWithImplicitSingleLevelContextHierarchy() { List> hierarchyAttributes = resolveContextHierarchyAttributes(BareAnnotations.class); assertThat(hierarchyAttributes.size()).isEqualTo(1); List configAttributesList = hierarchyAttributes.get(0); @@ -73,7 +73,7 @@ public class ContextLoaderUtilsContextHierarchyTests extends AbstractContextConf } @Test - public void resolveContextHierarchyAttributesForSingleTestClassWithSingleLevelContextHierarchy() { + void resolveContextHierarchyAttributesForSingleTestClassWithSingleLevelContextHierarchy() { List> hierarchyAttributes = resolveContextHierarchyAttributes(SingleTestClassWithSingleLevelContextHierarchy.class); assertThat(hierarchyAttributes.size()).isEqualTo(1); List configAttributesList = hierarchyAttributes.get(0); @@ -82,7 +82,7 @@ public class ContextLoaderUtilsContextHierarchyTests extends AbstractContextConf } @Test - public void resolveContextHierarchyAttributesForSingleTestClassWithSingleLevelContextHierarchyFromMetaAnnotation() { + void resolveContextHierarchyAttributesForSingleTestClassWithSingleLevelContextHierarchyFromMetaAnnotation() { Class testClass = SingleTestClassWithSingleLevelContextHierarchyFromMetaAnnotation.class; List> hierarchyAttributes = resolveContextHierarchyAttributes(testClass); assertThat(hierarchyAttributes.size()).isEqualTo(1); @@ -96,7 +96,7 @@ public class ContextLoaderUtilsContextHierarchyTests extends AbstractContextConf } @Test - public void resolveContextHierarchyAttributesForSingleTestClassWithTripleLevelContextHierarchy() { + void resolveContextHierarchyAttributesForSingleTestClassWithTripleLevelContextHierarchy() { Class testClass = SingleTestClassWithTripleLevelContextHierarchy.class; List> hierarchyAttributes = resolveContextHierarchyAttributes(testClass); assertThat(hierarchyAttributes.size()).isEqualTo(1); @@ -114,7 +114,7 @@ public class ContextLoaderUtilsContextHierarchyTests extends AbstractContextConf } @Test - public void resolveContextHierarchyAttributesForTestClassHierarchyWithSingleLevelContextHierarchies() { + void resolveContextHierarchyAttributesForTestClassHierarchyWithSingleLevelContextHierarchies() { List> hierarchyAttributes = resolveContextHierarchyAttributes(TestClass3WithSingleLevelContextHierarchy.class); assertThat(hierarchyAttributes.size()).isEqualTo(3); @@ -135,7 +135,7 @@ public class ContextLoaderUtilsContextHierarchyTests extends AbstractContextConf } @Test - public void resolveContextHierarchyAttributesForTestClassHierarchyWithSingleLevelContextHierarchiesAndMetaAnnotations() { + void resolveContextHierarchyAttributesForTestClassHierarchyWithSingleLevelContextHierarchiesAndMetaAnnotations() { List> hierarchyAttributes = resolveContextHierarchyAttributes(TestClass3WithSingleLevelContextHierarchyFromMetaAnnotation.class); assertThat(hierarchyAttributes.size()).isEqualTo(3); @@ -181,27 +181,27 @@ public class ContextLoaderUtilsContextHierarchyTests extends AbstractContextConf } @Test - public void resolveContextHierarchyAttributesForTestClassHierarchyWithBareContextConfigurationInSuperclass() { + void resolveContextHierarchyAttributesForTestClassHierarchyWithBareContextConfigurationInSuperclass() { assertOneTwo(resolveContextHierarchyAttributes(TestClass2WithBareContextConfigurationInSuperclass.class)); } @Test - public void resolveContextHierarchyAttributesForTestClassHierarchyWithBareContextConfigurationInSubclass() { + void resolveContextHierarchyAttributesForTestClassHierarchyWithBareContextConfigurationInSubclass() { assertOneTwo(resolveContextHierarchyAttributes(TestClass2WithBareContextConfigurationInSubclass.class)); } @Test - public void resolveContextHierarchyAttributesForTestClassHierarchyWithBareMetaContextConfigWithOverridesInSuperclass() { + void resolveContextHierarchyAttributesForTestClassHierarchyWithBareMetaContextConfigWithOverridesInSuperclass() { assertOneTwo(resolveContextHierarchyAttributes(TestClass2WithBareMetaContextConfigWithOverridesInSuperclass.class)); } @Test - public void resolveContextHierarchyAttributesForTestClassHierarchyWithBareMetaContextConfigWithOverridesInSubclass() { + void resolveContextHierarchyAttributesForTestClassHierarchyWithBareMetaContextConfigWithOverridesInSubclass() { assertOneTwo(resolveContextHierarchyAttributes(TestClass2WithBareMetaContextConfigWithOverridesInSubclass.class)); } @Test - public void resolveContextHierarchyAttributesForTestClassHierarchyWithMultiLevelContextHierarchies() { + void resolveContextHierarchyAttributesForTestClassHierarchyWithMultiLevelContextHierarchies() { List> hierarchyAttributes = resolveContextHierarchyAttributes(TestClass3WithMultiLevelContextHierarchy.class); assertThat(hierarchyAttributes.size()).isEqualTo(3); @@ -226,7 +226,7 @@ public class ContextLoaderUtilsContextHierarchyTests extends AbstractContextConf } @Test - public void buildContextHierarchyMapForTestClassHierarchyWithMultiLevelContextHierarchies() { + void buildContextHierarchyMapForTestClassHierarchyWithMultiLevelContextHierarchies() { Map> map = buildContextHierarchyMap(TestClass3WithMultiLevelContextHierarchy.class); assertThat(map).hasSize(3).containsKeys("alpha", "beta", "gamma"); @@ -249,7 +249,7 @@ public class ContextLoaderUtilsContextHierarchyTests extends AbstractContextConf } @Test - public void buildContextHierarchyMapForTestClassHierarchyWithMultiLevelContextHierarchiesAndUnnamedConfig() { + void buildContextHierarchyMapForTestClassHierarchyWithMultiLevelContextHierarchiesAndUnnamedConfig() { Map> map = buildContextHierarchyMap(TestClass3WithMultiLevelContextHierarchyAndUnnamedConfig.class); String level1 = GENERATED_CONTEXT_HIERARCHY_LEVEL_PREFIX + 1; @@ -282,7 +282,7 @@ public class ContextLoaderUtilsContextHierarchyTests extends AbstractContextConf } @Test - public void buildContextHierarchyMapForTestClassHierarchyWithMultiLevelContextHierarchiesAndPartiallyNamedConfig() { + void buildContextHierarchyMapForTestClassHierarchyWithMultiLevelContextHierarchiesAndPartiallyNamedConfig() { Map> map = buildContextHierarchyMap(TestClass2WithMultiLevelContextHierarchyAndPartiallyNamedConfig.class); String level1 = "parent"; @@ -317,12 +317,12 @@ public class ContextLoaderUtilsContextHierarchyTests extends AbstractContextConf } @Test - public void buildContextHierarchyMapForSingleTestClassWithMultiLevelContextHierarchyWithEmptyContextConfig() { + void buildContextHierarchyMapForSingleTestClassWithMultiLevelContextHierarchyWithEmptyContextConfig() { assertContextConfigEntriesAreNotUnique(SingleTestClassWithMultiLevelContextHierarchyWithEmptyContextConfig.class); } @Test - public void buildContextHierarchyMapForSingleTestClassWithMultiLevelContextHierarchyWithDuplicatedContextConfig() { + void buildContextHierarchyMapForSingleTestClassWithMultiLevelContextHierarchyWithDuplicatedContextConfig() { assertContextConfigEntriesAreNotUnique(SingleTestClassWithMultiLevelContextHierarchyWithDuplicatedContextConfig.class); } @@ -330,7 +330,7 @@ public class ContextLoaderUtilsContextHierarchyTests extends AbstractContextConf * Used to reproduce bug reported in https://jira.spring.io/browse/SPR-10997 */ @Test - public void buildContextHierarchyMapForTestClassHierarchyWithMultiLevelContextHierarchiesAndOverriddenInitializers() { + void buildContextHierarchyMapForTestClassHierarchyWithMultiLevelContextHierarchiesAndOverriddenInitializers() { Map> map = buildContextHierarchyMap(TestClass2WithMultiLevelContextHierarchyWithOverriddenInitializers.class); assertThat(map).hasSize(2).containsKeys("alpha", "beta"); diff --git a/spring-test/src/test/java/org/springframework/test/context/support/CustomizedGenericXmlContextLoaderTests.java b/spring-test/src/test/java/org/springframework/test/context/support/CustomizedGenericXmlContextLoaderTests.java index 56f39e1628..db9d4af159 100644 --- a/spring-test/src/test/java/org/springframework/test/context/support/CustomizedGenericXmlContextLoaderTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/support/CustomizedGenericXmlContextLoaderTests.java @@ -16,7 +16,7 @@ package org.springframework.test.context.support; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.context.support.GenericApplicationContext; @@ -34,13 +34,12 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Sam Brannen * @since 2.5 */ -public class CustomizedGenericXmlContextLoaderTests { +class CustomizedGenericXmlContextLoaderTests { @Test - public void customizeContext() throws Exception { - - final StringBuilder builder = new StringBuilder(); - final String expectedContents = "customizeContext() was called"; + void customizeContext() throws Exception { + StringBuilder builder = new StringBuilder(); + String expectedContents = "customizeContext() was called"; new GenericXmlContextLoader() { diff --git a/spring-test/src/test/java/org/springframework/test/context/support/DelegatingSmartContextLoaderTests.java b/spring-test/src/test/java/org/springframework/test/context/support/DelegatingSmartContextLoaderTests.java index 7f301cc8e9..e6ea430105 100644 --- a/spring-test/src/test/java/org/springframework/test/context/support/DelegatingSmartContextLoaderTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/support/DelegatingSmartContextLoaderTests.java @@ -16,7 +16,7 @@ package org.springframework.test.context.support; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.context.ApplicationContext; import org.springframework.context.ConfigurableApplicationContext; @@ -38,7 +38,7 @@ import static org.assertj.core.api.Assertions.assertThatIllegalStateException; * @author Sam Brannen * @since 3.1 */ -public class DelegatingSmartContextLoaderTests { +class DelegatingSmartContextLoaderTests { private static final String[] EMPTY_STRING_ARRAY = new String[0]; private static final Class[] EMPTY_CLASS_ARRAY = new Class[0]; @@ -53,7 +53,7 @@ public class DelegatingSmartContextLoaderTests { // --- SmartContextLoader - processContextConfiguration() ------------------ @Test - public void processContextConfigurationWithDefaultXmlConfigGeneration() { + void processContextConfigurationWithDefaultXmlConfigGeneration() { ContextConfigurationAttributes configAttributes = new ContextConfigurationAttributes( XmlTestCase.class, EMPTY_STRING_ARRAY, EMPTY_CLASS_ARRAY, true, null, true, ContextLoader.class); loader.processContextConfiguration(configAttributes); @@ -62,7 +62,7 @@ public class DelegatingSmartContextLoaderTests { } @Test - public void processContextConfigurationWithDefaultConfigurationClassGeneration() { + void processContextConfigurationWithDefaultConfigurationClassGeneration() { ContextConfigurationAttributes configAttributes = new ContextConfigurationAttributes( ConfigClassTestCase.class, EMPTY_STRING_ARRAY, EMPTY_CLASS_ARRAY, true, null, true, ContextLoader.class); loader.processContextConfiguration(configAttributes); @@ -71,7 +71,7 @@ public class DelegatingSmartContextLoaderTests { } @Test - public void processContextConfigurationWithDefaultXmlConfigAndConfigurationClassGeneration() { + void processContextConfigurationWithDefaultXmlConfigAndConfigurationClassGeneration() { ContextConfigurationAttributes configAttributes = new ContextConfigurationAttributes( ImproperDuplicateDefaultXmlAndConfigClassTestCase.class, EMPTY_STRING_ARRAY, EMPTY_CLASS_ARRAY, true, null, true, ContextLoader.class); @@ -81,7 +81,7 @@ public class DelegatingSmartContextLoaderTests { } @Test - public void processContextConfigurationWithLocation() { + void processContextConfigurationWithLocation() { String[] locations = new String[] {"classpath:/foo.xml"}; ContextConfigurationAttributes configAttributes = new ContextConfigurationAttributes( getClass(), locations, EMPTY_CLASS_ARRAY, true, null, true, ContextLoader.class); @@ -91,7 +91,7 @@ public class DelegatingSmartContextLoaderTests { } @Test - public void processContextConfigurationWithConfigurationClass() { + void processContextConfigurationWithConfigurationClass() { Class[] classes = new Class[] {getClass()}; ContextConfigurationAttributes configAttributes = new ContextConfigurationAttributes( getClass(), EMPTY_STRING_ARRAY, classes, true, null, true, ContextLoader.class); @@ -103,13 +103,13 @@ public class DelegatingSmartContextLoaderTests { // --- SmartContextLoader - loadContext() ---------------------------------- @Test - public void loadContextWithNullConfig() throws Exception { + void loadContextWithNullConfig() throws Exception { assertThatIllegalArgumentException().isThrownBy(() -> loader.loadContext((MergedContextConfiguration) null)); } @Test - public void loadContextWithoutLocationsAndConfigurationClasses() throws Exception { + void loadContextWithoutLocationsAndConfigurationClasses() throws Exception { MergedContextConfiguration mergedConfig = new MergedContextConfiguration( getClass(), EMPTY_STRING_ARRAY, EMPTY_CLASS_ARRAY, EMPTY_STRING_ARRAY, loader); assertThatIllegalStateException().isThrownBy(() -> @@ -122,7 +122,7 @@ public class DelegatingSmartContextLoaderTests { * @since 4.1 */ @Test - public void loadContextWithLocationsAndConfigurationClasses() throws Exception { + void loadContextWithLocationsAndConfigurationClasses() throws Exception { MergedContextConfiguration mergedConfig = new MergedContextConfiguration(getClass(), new String[] {"test.xml"}, new Class[] {getClass()}, EMPTY_STRING_ARRAY, loader); assertThatIllegalStateException().isThrownBy(() -> @@ -143,7 +143,7 @@ public class DelegatingSmartContextLoaderTests { } @Test - public void loadContextWithXmlConfig() throws Exception { + void loadContextWithXmlConfig() throws Exception { MergedContextConfiguration mergedConfig = new MergedContextConfiguration( XmlTestCase.class, new String[] {"classpath:/org/springframework/test/context/support/DelegatingSmartContextLoaderTests$XmlTestCase-context.xml"}, @@ -152,7 +152,7 @@ public class DelegatingSmartContextLoaderTests { } @Test - public void loadContextWithConfigurationClass() throws Exception { + void loadContextWithConfigurationClass() throws Exception { MergedContextConfiguration mergedConfig = new MergedContextConfiguration(ConfigClassTestCase.class, EMPTY_STRING_ARRAY, new Class[] {ConfigClassTestCase.Config.class}, EMPTY_STRING_ARRAY, loader); assertApplicationContextLoadsAndContainsFooString(mergedConfig); @@ -161,13 +161,13 @@ public class DelegatingSmartContextLoaderTests { // --- ContextLoader ------------------------------------------------------- @Test - public void processLocations() { + void processLocations() { assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> loader.processLocations(getClass(), EMPTY_STRING_ARRAY)); } @Test - public void loadContextFromLocations() throws Exception { + void loadContextFromLocations() throws Exception { assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> loader.loadContext(EMPTY_STRING_ARRAY)); } diff --git a/spring-test/src/test/java/org/springframework/test/context/support/DirtiesContextTestExecutionListenerTests.java b/spring-test/src/test/java/org/springframework/test/context/support/DirtiesContextTestExecutionListenerTests.java index 59eb7298eb..d142372eb2 100644 --- a/spring-test/src/test/java/org/springframework/test/context/support/DirtiesContextTestExecutionListenerTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/support/DirtiesContextTestExecutionListenerTests.java @@ -19,7 +19,7 @@ package org.springframework.test.context.support; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.mockito.BDDMockito; import org.springframework.test.annotation.DirtiesContext; @@ -48,7 +48,7 @@ import static org.springframework.test.annotation.DirtiesContext.MethodMode.BEFO * @author Sam Brannen * @since 4.0 */ -public class DirtiesContextTestExecutionListenerTests { +class DirtiesContextTestExecutionListenerTests { private final TestExecutionListener beforeListener = new DirtiesContextBeforeModesTestExecutionListener(); private final TestExecutionListener afterListener = new DirtiesContextTestExecutionListener(); @@ -56,7 +56,7 @@ public class DirtiesContextTestExecutionListenerTests { @Test - public void beforeAndAfterTestMethodForDirtiesContextDeclaredLocallyOnMethodWithBeforeMethodMode() throws Exception { + void beforeAndAfterTestMethodForDirtiesContextDeclaredLocallyOnMethodWithBeforeMethodMode() throws Exception { Class clazz = getClass(); BDDMockito.> given(testContext.getTestClass()).willReturn(clazz); given(testContext.getTestMethod()).willReturn( @@ -70,7 +70,7 @@ public class DirtiesContextTestExecutionListenerTests { } @Test - public void beforeAndAfterTestMethodForDirtiesContextDeclaredLocallyOnMethodWithAfterMethodMode() throws Exception { + void beforeAndAfterTestMethodForDirtiesContextDeclaredLocallyOnMethodWithAfterMethodMode() throws Exception { Class clazz = getClass(); BDDMockito.> given(testContext.getTestClass()).willReturn(clazz); given(testContext.getTestMethod()).willReturn( @@ -84,7 +84,7 @@ public class DirtiesContextTestExecutionListenerTests { } @Test - public void beforeAndAfterTestMethodForDirtiesContextDeclaredOnMethodViaMetaAnnotationWithAfterMethodMode() + void beforeAndAfterTestMethodForDirtiesContextDeclaredOnMethodViaMetaAnnotationWithAfterMethodMode() throws Exception { Class clazz = getClass(); BDDMockito.> given(testContext.getTestClass()).willReturn(clazz); @@ -99,7 +99,7 @@ public class DirtiesContextTestExecutionListenerTests { } @Test - public void beforeAndAfterTestMethodForDirtiesContextDeclaredLocallyOnClassBeforeEachTestMethod() throws Exception { + void beforeAndAfterTestMethodForDirtiesContextDeclaredLocallyOnClassBeforeEachTestMethod() throws Exception { Class clazz = DirtiesContextDeclaredLocallyBeforeEachTestMethod.class; BDDMockito.> given(testContext.getTestClass()).willReturn(clazz); given(testContext.getTestMethod()).willReturn(clazz.getDeclaredMethod("clean")); @@ -112,7 +112,7 @@ public class DirtiesContextTestExecutionListenerTests { } @Test - public void beforeAndAfterTestMethodForDirtiesContextDeclaredLocallyOnClassAfterEachTestMethod() throws Exception { + void beforeAndAfterTestMethodForDirtiesContextDeclaredLocallyOnClassAfterEachTestMethod() throws Exception { Class clazz = DirtiesContextDeclaredLocallyAfterEachTestMethod.class; BDDMockito.> given(testContext.getTestClass()).willReturn(clazz); given(testContext.getTestMethod()).willReturn(clazz.getDeclaredMethod("clean")); @@ -125,7 +125,7 @@ public class DirtiesContextTestExecutionListenerTests { } @Test - public void beforeAndAfterTestMethodForDirtiesContextDeclaredViaMetaAnnotationOnClassAfterEachTestMethod() + void beforeAndAfterTestMethodForDirtiesContextDeclaredViaMetaAnnotationOnClassAfterEachTestMethod() throws Exception { Class clazz = DirtiesContextDeclaredViaMetaAnnotationAfterEachTestMethod.class; BDDMockito.> given(testContext.getTestClass()).willReturn(clazz); @@ -139,7 +139,7 @@ public class DirtiesContextTestExecutionListenerTests { } @Test - public void beforeAndAfterTestMethodForDirtiesContextDeclaredLocallyOnClassBeforeClass() throws Exception { + void beforeAndAfterTestMethodForDirtiesContextDeclaredLocallyOnClassBeforeClass() throws Exception { Class clazz = DirtiesContextDeclaredLocallyBeforeClass.class; BDDMockito.> given(testContext.getTestClass()).willReturn(clazz); given(testContext.getTestMethod()).willReturn(clazz.getDeclaredMethod("clean")); @@ -151,7 +151,7 @@ public class DirtiesContextTestExecutionListenerTests { } @Test - public void beforeAndAfterTestMethodForDirtiesContextDeclaredLocallyOnClassAfterClass() throws Exception { + void beforeAndAfterTestMethodForDirtiesContextDeclaredLocallyOnClassAfterClass() throws Exception { Class clazz = DirtiesContextDeclaredLocallyAfterClass.class; BDDMockito.> given(testContext.getTestClass()).willReturn(clazz); given(testContext.getTestMethod()).willReturn(clazz.getDeclaredMethod("clean")); @@ -163,7 +163,7 @@ public class DirtiesContextTestExecutionListenerTests { } @Test - public void beforeAndAfterTestMethodForDirtiesContextDeclaredViaMetaAnnotationOnClassAfterClass() throws Exception { + void beforeAndAfterTestMethodForDirtiesContextDeclaredViaMetaAnnotationOnClassAfterClass() throws Exception { Class clazz = DirtiesContextDeclaredViaMetaAnnotationAfterClass.class; BDDMockito.> given(testContext.getTestClass()).willReturn(clazz); given(testContext.getTestMethod()).willReturn(clazz.getDeclaredMethod("clean")); @@ -175,7 +175,7 @@ public class DirtiesContextTestExecutionListenerTests { } @Test - public void beforeAndAfterTestMethodForDirtiesContextViaMetaAnnotationWithOverrides() throws Exception { + void beforeAndAfterTestMethodForDirtiesContextViaMetaAnnotationWithOverrides() throws Exception { Class clazz = DirtiesContextViaMetaAnnotationWithOverrides.class; BDDMockito.> given(testContext.getTestClass()).willReturn(clazz); given(testContext.getTestMethod()).willReturn(clazz.getDeclaredMethod("clean")); @@ -190,7 +190,7 @@ public class DirtiesContextTestExecutionListenerTests { // ------------------------------------------------------------------------- @Test - public void beforeAndAfterTestClassForDirtiesContextDeclaredLocallyOnMethod() throws Exception { + void beforeAndAfterTestClassForDirtiesContextDeclaredLocallyOnMethod() throws Exception { Class clazz = getClass(); BDDMockito.> given(testContext.getTestClass()).willReturn(clazz); beforeListener.beforeTestClass(testContext); @@ -201,7 +201,7 @@ public class DirtiesContextTestExecutionListenerTests { } @Test - public void beforeAndAfterTestClassForDirtiesContextDeclaredLocallyOnClassBeforeEachTestMethod() throws Exception { + void beforeAndAfterTestClassForDirtiesContextDeclaredLocallyOnClassBeforeEachTestMethod() throws Exception { Class clazz = DirtiesContextDeclaredLocallyBeforeEachTestMethod.class; BDDMockito.> given(testContext.getTestClass()).willReturn(clazz); beforeListener.beforeTestClass(testContext); @@ -212,7 +212,7 @@ public class DirtiesContextTestExecutionListenerTests { } @Test - public void beforeAndAfterTestClassForDirtiesContextDeclaredLocallyOnClassAfterEachTestMethod() throws Exception { + void beforeAndAfterTestClassForDirtiesContextDeclaredLocallyOnClassAfterEachTestMethod() throws Exception { Class clazz = DirtiesContextDeclaredLocallyAfterEachTestMethod.class; BDDMockito.> given(testContext.getTestClass()).willReturn(clazz); beforeListener.beforeTestClass(testContext); @@ -223,7 +223,7 @@ public class DirtiesContextTestExecutionListenerTests { } @Test - public void beforeAndAfterTestClassForDirtiesContextDeclaredViaMetaAnnotationOnClassAfterEachTestMethod() + void beforeAndAfterTestClassForDirtiesContextDeclaredViaMetaAnnotationOnClassAfterEachTestMethod() throws Exception { Class clazz = DirtiesContextDeclaredViaMetaAnnotationAfterEachTestMethod.class; BDDMockito.> given(testContext.getTestClass()).willReturn(clazz); @@ -235,7 +235,7 @@ public class DirtiesContextTestExecutionListenerTests { } @Test - public void beforeAndAfterTestClassForDirtiesContextDeclaredLocallyOnClassBeforeClass() throws Exception { + void beforeAndAfterTestClassForDirtiesContextDeclaredLocallyOnClassBeforeClass() throws Exception { Class clazz = DirtiesContextDeclaredLocallyBeforeClass.class; BDDMockito.> given(testContext.getTestClass()).willReturn(clazz); beforeListener.beforeTestClass(testContext); @@ -247,7 +247,7 @@ public class DirtiesContextTestExecutionListenerTests { } @Test - public void beforeAndAfterTestClassForDirtiesContextDeclaredLocallyOnClassAfterClass() throws Exception { + void beforeAndAfterTestClassForDirtiesContextDeclaredLocallyOnClassAfterClass() throws Exception { Class clazz = DirtiesContextDeclaredLocallyAfterClass.class; BDDMockito.> given(testContext.getTestClass()).willReturn(clazz); beforeListener.beforeTestClass(testContext); @@ -259,7 +259,7 @@ public class DirtiesContextTestExecutionListenerTests { } @Test - public void beforeAndAfterTestClassForDirtiesContextDeclaredViaMetaAnnotationOnClassAfterClass() throws Exception { + void beforeAndAfterTestClassForDirtiesContextDeclaredViaMetaAnnotationOnClassAfterClass() throws Exception { Class clazz = DirtiesContextDeclaredViaMetaAnnotationAfterClass.class; BDDMockito.> given(testContext.getTestClass()).willReturn(clazz); beforeListener.beforeTestClass(testContext); @@ -271,7 +271,7 @@ public class DirtiesContextTestExecutionListenerTests { } @Test - public void beforeAndAfterTestClassForDirtiesContextDeclaredViaMetaAnnotationWithOverrides() throws Exception { + void beforeAndAfterTestClassForDirtiesContextDeclaredViaMetaAnnotationWithOverrides() throws Exception { Class clazz = DirtiesContextViaMetaAnnotationWithOverrides.class; BDDMockito.> given(testContext.getTestClass()).willReturn(clazz); beforeListener.beforeTestClass(testContext); @@ -282,7 +282,7 @@ public class DirtiesContextTestExecutionListenerTests { } @Test - public void beforeAndAfterTestClassForDirtiesContextDeclaredViaMetaAnnotationWithOverridenAttributes() + void beforeAndAfterTestClassForDirtiesContextDeclaredViaMetaAnnotationWithOverridenAttributes() throws Exception { Class clazz = DirtiesContextViaMetaAnnotationWithOverridenAttributes.class; BDDMockito.> given(testContext.getTestClass()).willReturn(clazz); diff --git a/spring-test/src/test/java/org/springframework/test/context/support/GenericPropertiesContextLoaderTests.java b/spring-test/src/test/java/org/springframework/test/context/support/GenericPropertiesContextLoaderTests.java index 83d3dd8e33..88492e8fb6 100644 --- a/spring-test/src/test/java/org/springframework/test/context/support/GenericPropertiesContextLoaderTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/support/GenericPropertiesContextLoaderTests.java @@ -16,7 +16,7 @@ package org.springframework.test.context.support; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.test.context.MergedContextConfiguration; @@ -28,18 +28,18 @@ import static org.assertj.core.api.Assertions.assertThatIllegalStateException; * @author Sam Brannen * @since 4.0.4 */ -public class GenericPropertiesContextLoaderTests { +class GenericPropertiesContextLoaderTests { private static final String[] EMPTY_STRING_ARRAY = new String[0]; @Test - public void configMustNotContainAnnotatedClasses() throws Exception { + void configMustNotContainAnnotatedClasses() throws Exception { GenericPropertiesContextLoader loader = new GenericPropertiesContextLoader(); MergedContextConfiguration mergedConfig = new MergedContextConfiguration(getClass(), EMPTY_STRING_ARRAY, new Class[] { getClass() }, EMPTY_STRING_ARRAY, loader); - assertThatIllegalStateException().isThrownBy(() -> - loader.loadContext(mergedConfig)) + assertThatIllegalStateException() + .isThrownBy(() -> loader.loadContext(mergedConfig)) .withMessageContaining("does not support annotated classes"); } diff --git a/spring-test/src/test/java/org/springframework/test/context/support/GenericXmlContextLoaderResourceLocationsTests.java b/spring-test/src/test/java/org/springframework/test/context/support/GenericXmlContextLoaderResourceLocationsTests.java index 9a0f6369f6..9c9c5f7065 100644 --- a/spring-test/src/test/java/org/springframework/test/context/support/GenericXmlContextLoaderResourceLocationsTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/support/GenericXmlContextLoaderResourceLocationsTests.java @@ -21,10 +21,8 @@ import java.util.Collection; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameters; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.springframework.core.annotation.AnnotationUtils; import org.springframework.test.context.ContextConfiguration; @@ -35,7 +33,7 @@ import org.springframework.util.ObjectUtils; import static org.assertj.core.api.Assertions.assertThat; /** - * JUnit 4 based unit test which verifies proper + * Unit test which verifies proper * {@link ContextLoader#processLocations(Class, String...) processing} of * {@code resource locations} by a {@link GenericXmlContextLoader} * configured via {@link ContextConfiguration @ContextConfiguration}. @@ -47,17 +45,12 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Sam Brannen * @since 2.5 */ -@RunWith(Parameterized.class) -public class GenericXmlContextLoaderResourceLocationsTests { +class GenericXmlContextLoaderResourceLocationsTests { private static final Log logger = LogFactory.getLog(GenericXmlContextLoaderResourceLocationsTests.class); - protected final Class testClass; - protected final String[] expectedLocations; - - @Parameters(name = "{0}") - public static Collection contextConfigurationLocationsData() { + static Collection contextConfigurationLocationsData() { @ContextConfiguration class ClasspathNonExistentDefaultLocationsTestCase { } @@ -115,27 +108,25 @@ public class GenericXmlContextLoaderResourceLocationsTests { }); } - public GenericXmlContextLoaderResourceLocationsTests(final String testClassName, final String[] expectedLocations) throws Exception { - this.testClass = ClassUtils.forName(getClass().getName() + "$1" + testClassName, getClass().getClassLoader()); - this.expectedLocations = expectedLocations; - } - @Test - public void assertContextConfigurationLocations() throws Exception { + @ParameterizedTest(name = "{0}") + @MethodSource("contextConfigurationLocationsData") + void assertContextConfigurationLocations(String testClassName, String[] expectedLocations) throws Exception { + Class testClass = ClassUtils.forName(getClass().getName() + "$1" + testClassName, getClass().getClassLoader()); - final ContextConfiguration contextConfig = this.testClass.getAnnotation(ContextConfiguration.class); + final ContextConfiguration contextConfig = testClass.getAnnotation(ContextConfiguration.class); final ContextLoader contextLoader = new GenericXmlContextLoader(); final String[] configuredLocations = (String[]) AnnotationUtils.getValue(contextConfig); - final String[] processedLocations = contextLoader.processLocations(this.testClass, configuredLocations); + final String[] processedLocations = contextLoader.processLocations(testClass, configuredLocations); if (logger.isDebugEnabled()) { logger.debug("----------------------------------------------------------------------"); logger.debug("Configured locations: " + ObjectUtils.nullSafeToString(configuredLocations)); - logger.debug("Expected locations: " + ObjectUtils.nullSafeToString(this.expectedLocations)); + logger.debug("Expected locations: " + ObjectUtils.nullSafeToString(expectedLocations)); logger.debug("Processed locations: " + ObjectUtils.nullSafeToString(processedLocations)); } - assertThat(processedLocations).as("Verifying locations for test [" + this.testClass + "].").isEqualTo(this.expectedLocations); + assertThat(processedLocations).as("Verifying locations for test [" + testClass + "].").isEqualTo(expectedLocations); } } diff --git a/spring-test/src/test/java/org/springframework/test/context/support/GenericXmlContextLoaderTests.java b/spring-test/src/test/java/org/springframework/test/context/support/GenericXmlContextLoaderTests.java index eeaf3f1f64..0b3960fd5c 100644 --- a/spring-test/src/test/java/org/springframework/test/context/support/GenericXmlContextLoaderTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/support/GenericXmlContextLoaderTests.java @@ -16,7 +16,7 @@ package org.springframework.test.context.support; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.test.context.MergedContextConfiguration; @@ -29,18 +29,18 @@ import static org.assertj.core.api.Assertions.assertThatIllegalStateException; * @since 4.0.4 * @see GenericXmlContextLoaderResourceLocationsTests */ -public class GenericXmlContextLoaderTests { +class GenericXmlContextLoaderTests { private static final String[] EMPTY_STRING_ARRAY = new String[0]; @Test - public void configMustNotContainAnnotatedClasses() throws Exception { + void configMustNotContainAnnotatedClasses() throws Exception { GenericXmlContextLoader loader = new GenericXmlContextLoader(); MergedContextConfiguration mergedConfig = new MergedContextConfiguration(getClass(), EMPTY_STRING_ARRAY, new Class[] { getClass() }, EMPTY_STRING_ARRAY, loader); - assertThatIllegalStateException().isThrownBy(() -> - loader.loadContext(mergedConfig)) + assertThatIllegalStateException() + .isThrownBy(() -> loader.loadContext(mergedConfig)) .withMessageContaining("does not support annotated classes"); } diff --git a/spring-test/src/test/java/org/springframework/test/context/support/TestConstructorUtilsTests.java b/spring-test/src/test/java/org/springframework/test/context/support/TestConstructorUtilsTests.java index 2b65cb5136..860001b4a9 100644 --- a/spring-test/src/test/java/org/springframework/test/context/support/TestConstructorUtilsTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/support/TestConstructorUtilsTests.java @@ -18,8 +18,8 @@ package org.springframework.test.context.support; import java.lang.reflect.Constructor; -import org.junit.After; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.SpringProperties; @@ -35,42 +35,42 @@ import static org.springframework.test.context.TestConstructor.AutowireMode.ANNO * @author Sam Brannen * @since 5.2 */ -public class TestConstructorUtilsTests { +class TestConstructorUtilsTests { - @After - public void clearGlobalFlag() { + @AfterEach + void clearGlobalFlag() { setGlobalFlag(null); } @Test - public void notAutowirable() throws Exception { + void notAutowirable() throws Exception { assertNotAutowirable(NotAutowirableTestCase.class); } @Test - public void autowiredAnnotation() throws Exception { + void autowiredAnnotation() throws Exception { assertAutowirable(AutowiredAnnotationTestCase.class); } @Test - public void testConstructorAnnotation() throws Exception { + void testConstructorAnnotation() throws Exception { assertAutowirable(TestConstructorAnnotationTestCase.class); } @Test - public void automaticallyAutowired() throws Exception { + void automaticallyAutowired() throws Exception { setGlobalFlag(); assertAutowirable(AutomaticallyAutowiredTestCase.class); } @Test - public void automaticallyAutowiredButOverriddenLocally() throws Exception { + void automaticallyAutowiredButOverriddenLocally() throws Exception { setGlobalFlag(); assertNotAutowirable(TestConstructorAnnotationOverridesGlobalFlagTestCase.class); } @Test - public void globalFlagVariations() throws Exception { + void globalFlagVariations() throws Exception { Class testClass = AutomaticallyAutowiredTestCase.class; setGlobalFlag(ALL.name()); diff --git a/spring-test/src/test/java/org/springframework/test/context/support/TestPropertySourceUtilsTests.java b/spring-test/src/test/java/org/springframework/test/context/support/TestPropertySourceUtilsTests.java index 420081c3b4..cf859b3111 100644 --- a/spring-test/src/test/java/org/springframework/test/context/support/TestPropertySourceUtilsTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/support/TestPropertySourceUtilsTests.java @@ -20,7 +20,7 @@ import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.util.Map; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.core.annotation.AnnotationConfigurationException; @@ -50,7 +50,7 @@ import static org.springframework.test.context.support.TestPropertySourceUtils.c * @author Sam Brannen * @since 4.1 */ -public class TestPropertySourceUtilsTests { +class TestPropertySourceUtilsTests { private static final String[] EMPTY_STRING_ARRAY = new String[0]; @@ -60,7 +60,7 @@ public class TestPropertySourceUtilsTests { @Test - public void emptyAnnotation() { + void emptyAnnotation() { assertThatIllegalStateException() .isThrownBy(() -> buildMergedTestPropertySources(EmptyPropertySources.class)) .withMessageStartingWith("Could not detect default properties file for test class") @@ -70,7 +70,7 @@ public class TestPropertySourceUtilsTests { } @Test - public void extendedEmptyAnnotation() { + void extendedEmptyAnnotation() { assertThatIllegalStateException() .isThrownBy(() -> buildMergedTestPropertySources(ExtendedEmptyPropertySources.class)) .withMessageStartingWith("Could not detect default properties file for test") @@ -80,7 +80,7 @@ public class TestPropertySourceUtilsTests { } @Test - public void repeatedTestPropertySourcesWithConflictingInheritLocationsFlags() { + void repeatedTestPropertySourcesWithConflictingInheritLocationsFlags() { assertThatIllegalArgumentException() .isThrownBy(() -> buildMergedTestPropertySources(RepeatedPropertySourcesWithConflictingInheritLocationsFlags.class)) .withMessage("@TestPropertySource on RepeatedPropertySourcesWithConflictingInheritLocationsFlags and " + @@ -89,7 +89,7 @@ public class TestPropertySourceUtilsTests { } @Test - public void repeatedTestPropertySourcesWithConflictingInheritPropertiesFlags() { + void repeatedTestPropertySourcesWithConflictingInheritPropertiesFlags() { assertThatIllegalArgumentException() .isThrownBy(() -> buildMergedTestPropertySources(RepeatedPropertySourcesWithConflictingInheritPropertiesFlags.class)) .withMessage("@TestPropertySource on RepeatedPropertySourcesWithConflictingInheritPropertiesFlags and " + @@ -98,92 +98,92 @@ public class TestPropertySourceUtilsTests { } @Test - public void value() { + void value() { assertMergedTestPropertySources(ValuePropertySources.class, asArray("classpath:/value.xml"), EMPTY_STRING_ARRAY); } @Test - public void locationsAndValueAttributes() { + void locationsAndValueAttributes() { assertThatExceptionOfType(AnnotationConfigurationException.class) .isThrownBy(() -> buildMergedTestPropertySources(LocationsAndValuePropertySources.class)); } @Test - public void locationsAndProperties() { + void locationsAndProperties() { assertMergedTestPropertySources(LocationsAndPropertiesPropertySources.class, asArray("classpath:/foo1.xml", "classpath:/foo2.xml"), asArray("k1a=v1a", "k1b: v1b")); } @Test - public void inheritedLocationsAndProperties() { + void inheritedLocationsAndProperties() { assertMergedTestPropertySources(InheritedPropertySources.class, asArray("classpath:/foo1.xml", "classpath:/foo2.xml"), asArray("k1a=v1a", "k1b: v1b")); } @Test - public void extendedLocationsAndProperties() { + void extendedLocationsAndProperties() { assertMergedTestPropertySources(ExtendedPropertySources.class, asArray("classpath:/foo1.xml", "classpath:/foo2.xml", "classpath:/bar1.xml", "classpath:/bar2.xml"), asArray("k1a=v1a", "k1b: v1b", "k2a v2a", "k2b: v2b")); } @Test - public void overriddenLocations() { + void overriddenLocations() { assertMergedTestPropertySources(OverriddenLocationsPropertySources.class, asArray("classpath:/baz.properties"), asArray("k1a=v1a", "k1b: v1b", "key = value")); } @Test - public void overriddenProperties() { + void overriddenProperties() { assertMergedTestPropertySources(OverriddenPropertiesPropertySources.class, asArray("classpath:/foo1.xml", "classpath:/foo2.xml", "classpath:/baz.properties"), KEY_VALUE_PAIR); } @Test - public void overriddenLocationsAndProperties() { + void overriddenLocationsAndProperties() { assertMergedTestPropertySources(OverriddenLocationsAndPropertiesPropertySources.class, asArray("classpath:/baz.properties"), KEY_VALUE_PAIR); } @Test - public void addPropertiesFilesToEnvironmentWithNullContext() { + void addPropertiesFilesToEnvironmentWithNullContext() { assertThatIllegalArgumentException() .isThrownBy(() -> addPropertiesFilesToEnvironment((ConfigurableApplicationContext) null, FOO_LOCATIONS)) .withMessageContaining("'context' must not be null"); } @Test - public void addPropertiesFilesToEnvironmentWithContextAndNullLocations() { + void addPropertiesFilesToEnvironmentWithContextAndNullLocations() { assertThatIllegalArgumentException() .isThrownBy(() -> addPropertiesFilesToEnvironment(mock(ConfigurableApplicationContext.class), (String[]) null)) .withMessageContaining("'locations' must not be null"); } @Test - public void addPropertiesFilesToEnvironmentWithNullEnvironment() { + void addPropertiesFilesToEnvironmentWithNullEnvironment() { assertThatIllegalArgumentException() .isThrownBy(() -> addPropertiesFilesToEnvironment((ConfigurableEnvironment) null, mock(ResourceLoader.class), FOO_LOCATIONS)) .withMessageContaining("'environment' must not be null"); } @Test - public void addPropertiesFilesToEnvironmentWithEnvironmentLocationsAndNullResourceLoader() { + void addPropertiesFilesToEnvironmentWithEnvironmentLocationsAndNullResourceLoader() { assertThatIllegalArgumentException() .isThrownBy(() -> addPropertiesFilesToEnvironment(new MockEnvironment(), null, FOO_LOCATIONS)) .withMessageContaining("'resourceLoader' must not be null"); } @Test - public void addPropertiesFilesToEnvironmentWithEnvironmentAndNullLocations() { + void addPropertiesFilesToEnvironmentWithEnvironmentAndNullLocations() { assertThatIllegalArgumentException() .isThrownBy(() -> addPropertiesFilesToEnvironment(new MockEnvironment(), mock(ResourceLoader.class), (String[]) null)) .withMessageContaining("'locations' must not be null"); } @Test - public void addPropertiesFilesToEnvironmentWithSinglePropertyFromVirtualFile() { + void addPropertiesFilesToEnvironmentWithSinglePropertyFromVirtualFile() { ConfigurableEnvironment environment = new MockEnvironment(); MutablePropertySources propertySources = environment.getPropertySources(); @@ -201,42 +201,42 @@ public class TestPropertySourceUtilsTests { } @Test - public void addInlinedPropertiesToEnvironmentWithNullContext() { + void addInlinedPropertiesToEnvironmentWithNullContext() { assertThatIllegalArgumentException() .isThrownBy(() -> addInlinedPropertiesToEnvironment((ConfigurableApplicationContext) null, KEY_VALUE_PAIR)) .withMessageContaining("'context' must not be null"); } @Test - public void addInlinedPropertiesToEnvironmentWithContextAndNullInlinedProperties() { + void addInlinedPropertiesToEnvironmentWithContextAndNullInlinedProperties() { assertThatIllegalArgumentException() .isThrownBy(() -> addInlinedPropertiesToEnvironment(mock(ConfigurableApplicationContext.class), (String[]) null)) .withMessageContaining("'inlinedProperties' must not be null"); } @Test - public void addInlinedPropertiesToEnvironmentWithNullEnvironment() { + void addInlinedPropertiesToEnvironmentWithNullEnvironment() { assertThatIllegalArgumentException() .isThrownBy(() -> addInlinedPropertiesToEnvironment((ConfigurableEnvironment) null, KEY_VALUE_PAIR)) .withMessageContaining("'environment' must not be null"); } @Test - public void addInlinedPropertiesToEnvironmentWithEnvironmentAndNullInlinedProperties() { + void addInlinedPropertiesToEnvironmentWithEnvironmentAndNullInlinedProperties() { assertThatIllegalArgumentException() .isThrownBy(() -> addInlinedPropertiesToEnvironment(new MockEnvironment(), (String[]) null)) .withMessageContaining("'inlinedProperties' must not be null"); } @Test - public void addInlinedPropertiesToEnvironmentWithMalformedUnicodeInValue() { + void addInlinedPropertiesToEnvironmentWithMalformedUnicodeInValue() { assertThatIllegalStateException() .isThrownBy(() -> addInlinedPropertiesToEnvironment(new MockEnvironment(), asArray("key = \\uZZZZ"))) .withMessageContaining("Failed to load test environment property"); } @Test - public void addInlinedPropertiesToEnvironmentWithMultipleKeyValuePairsInSingleInlinedProperty() { + void addInlinedPropertiesToEnvironmentWithMultipleKeyValuePairsInSingleInlinedProperty() { assertThatIllegalStateException() .isThrownBy(() -> addInlinedPropertiesToEnvironment(new MockEnvironment(), asArray("a=b\nx=y"))) .withMessageContaining("Failed to load exactly one test environment property"); @@ -244,7 +244,7 @@ public class TestPropertySourceUtilsTests { @Test @SuppressWarnings("rawtypes") - public void addInlinedPropertiesToEnvironmentWithEmptyProperty() { + void addInlinedPropertiesToEnvironmentWithEmptyProperty() { ConfigurableEnvironment environment = new MockEnvironment(); MutablePropertySources propertySources = environment.getPropertySources(); propertySources.remove(MockPropertySource.MOCK_PROPERTIES_PROPERTY_SOURCE_NAME); @@ -255,7 +255,7 @@ public class TestPropertySourceUtilsTests { } @Test - public void convertInlinedPropertiesToMapWithNullInlinedProperties() { + void convertInlinedPropertiesToMapWithNullInlinedProperties() { assertThatIllegalArgumentException() .isThrownBy(() -> convertInlinedPropertiesToMap((String[]) null)) .withMessageContaining("'inlinedProperties' must not be null"); diff --git a/spring-test/src/test/java/org/springframework/test/context/testng/transaction/programmatic/ProgrammaticTxMgmtTestNGTests.java b/spring-test/src/test/java/org/springframework/test/context/testng/transaction/programmatic/ProgrammaticTxMgmtTestNGTests.java index e6d74c801a..5f9366e32f 100644 --- a/spring-test/src/test/java/org/springframework/test/context/testng/transaction/programmatic/ProgrammaticTxMgmtTestNGTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/testng/transaction/programmatic/ProgrammaticTxMgmtTestNGTests.java @@ -35,7 +35,6 @@ import org.springframework.test.context.testng.AbstractTransactionalTestNGSpring import org.springframework.test.context.transaction.AfterTransaction; import org.springframework.test.context.transaction.BeforeTransaction; import org.springframework.test.context.transaction.TestTransaction; -import org.springframework.test.context.transaction.programmatic.ProgrammaticTxMgmtTests; import org.springframework.transaction.PlatformTransactionManager; import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Transactional; @@ -45,8 +44,9 @@ import static org.assertj.core.api.Assertions.fail; import static org.springframework.test.transaction.TransactionAssert.assertThatTransaction; /** - * This class is a copy of the JUnit-based {@link ProgrammaticTxMgmtTests} class - * that has been modified to run with TestNG. + * This class is a copy of the JUnit-based + * {@link org.springframework.test.context.transaction.programmatic.ProgrammaticTxMgmtTests} + * class that has been modified to run with TestNG. * * @author Sam Brannen * @since 4.1 @@ -54,12 +54,12 @@ import static org.springframework.test.transaction.TransactionAssert.assertThatT @ContextConfiguration public class ProgrammaticTxMgmtTestNGTests extends AbstractTransactionalTestNGSpringContextTests { - private String method; + private String methodName; @Override public void run(IHookCallBack callBack, ITestResult testResult) { - this.method = testResult.getMethod().getMethodName(); + this.methodName = testResult.getMethod().getMethodName(); super.run(callBack, testResult); } @@ -71,7 +71,7 @@ public class ProgrammaticTxMgmtTestNGTests extends AbstractTransactionalTestNGSp @AfterTransaction public void afterTransaction() { - switch (method) { + switch (this.methodName) { case "commitTxAndStartNewTx": case "commitTxButDoNotStartNewTx": { assertUsers("Dogbert"); @@ -88,7 +88,7 @@ public class ProgrammaticTxMgmtTestNGTests extends AbstractTransactionalTestNGSp break; } default: { - fail("missing 'after transaction' assertion for test method: " + method); + fail("missing 'after transaction' assertion for test method: " + this.methodName); } } } diff --git a/spring-test/src/test/java/org/springframework/test/context/transaction/PrimaryTransactionManagerTests.java b/spring-test/src/test/java/org/springframework/test/context/transaction/PrimaryTransactionManagerTests.java index 247b60208d..95e477d4c4 100644 --- a/spring-test/src/test/java/org/springframework/test/context/transaction/PrimaryTransactionManagerTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/transaction/PrimaryTransactionManagerTests.java @@ -18,8 +18,7 @@ package org.springframework.test.context.transaction; import javax.sql.DataSource; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; @@ -31,8 +30,7 @@ import org.springframework.jdbc.datasource.DataSourceTransactionManager; import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder; import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator; import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import org.springframework.test.jdbc.JdbcTestUtils; import org.springframework.transaction.PlatformTransactionManager; import org.springframework.transaction.annotation.EnableTransactionManagement; @@ -49,33 +47,31 @@ import static org.springframework.test.transaction.TransactionAssert.assertThatT * @since 4.3 * @see org.springframework.test.context.jdbc.PrimaryDataSourceTests */ -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration +@SpringJUnitConfig @DirtiesContext -public final class PrimaryTransactionManagerTests { +final class PrimaryTransactionManagerTests { private JdbcTemplate jdbcTemplate; @Autowired - public void setDataSource(DataSource dataSource1) { + void setDataSource(DataSource dataSource1) { this.jdbcTemplate = new JdbcTemplate(dataSource1); } - @BeforeTransaction - public void beforeTransaction() { + void beforeTransaction() { assertNumUsers(0); } @AfterTransaction - public void afterTransaction() { + void afterTransaction() { assertNumUsers(0); } @Test @Transactional - public void transactionalTest() { + void transactionalTest() { assertThatTransaction().isActive(); ClassPathResource resource = new ClassPathResource("/org/springframework/test/context/jdbc/data.sql"); @@ -95,17 +91,17 @@ public final class PrimaryTransactionManagerTests { @Primary @Bean - public PlatformTransactionManager primaryTransactionManager() { + PlatformTransactionManager primaryTransactionManager() { return new DataSourceTransactionManager(dataSource1()); } @Bean - public PlatformTransactionManager additionalTransactionManager() { + PlatformTransactionManager additionalTransactionManager() { return new DataSourceTransactionManager(dataSource2()); } @Bean - public DataSource dataSource1() { + DataSource dataSource1() { return new EmbeddedDatabaseBuilder() .generateUniqueName(true) .addScript("classpath:/org/springframework/test/context/jdbc/schema.sql") @@ -113,7 +109,7 @@ public final class PrimaryTransactionManagerTests { } @Bean - public DataSource dataSource2() { + DataSource dataSource2() { return new EmbeddedDatabaseBuilder().generateUniqueName(true).build(); } } diff --git a/spring-test/src/test/java/org/springframework/test/context/transaction/TransactionalTestExecutionListenerTests.java b/spring-test/src/test/java/org/springframework/test/context/transaction/TransactionalTestExecutionListenerTests.java index caeb9c10d6..23b961e6ef 100644 --- a/spring-test/src/test/java/org/springframework/test/context/transaction/TransactionalTestExecutionListenerTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/transaction/TransactionalTestExecutionListenerTests.java @@ -19,8 +19,8 @@ package org.springframework.test.context.transaction; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; -import org.junit.After; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Test; import org.mockito.BDDMockito; import org.springframework.beans.BeanUtils; @@ -47,7 +47,7 @@ import static org.springframework.transaction.annotation.Propagation.REQUIRED; * @author Sam Brannen * @since 4.0 */ -public class TransactionalTestExecutionListenerTests { +class TransactionalTestExecutionListenerTests { private final PlatformTransactionManager tm = mock(PlatformTransactionManager.class); @@ -61,15 +61,16 @@ public class TransactionalTestExecutionListenerTests { private final TestContext testContext = mock(TestContext.class); - @After - public void cleanUpThreadLocalStateForSubsequentTestClassesInSuite() { + @AfterEach + void cleanUpThreadLocalStateForSubsequentTestClassesInSuite() { TransactionContextHolder.removeCurrentTransactionContext(); } @Test // SPR-13895 - public void transactionalTestWithoutTransactionManager() throws Exception { + void transactionalTestWithoutTransactionManager() throws Exception { TransactionalTestExecutionListener listener = new TransactionalTestExecutionListener() { + @Override protected PlatformTransactionManager getTransactionManager(TestContext testContext, String qualifier) { return null; } @@ -90,17 +91,17 @@ public class TransactionalTestExecutionListenerTests { } @Test - public void beforeTestMethodWithTransactionalDeclaredOnClassLocally() throws Exception { + void beforeTestMethodWithTransactionalDeclaredOnClassLocally() throws Exception { assertBeforeTestMethodWithTransactionalTestMethod(TransactionalDeclaredOnClassLocallyTestCase.class); } @Test - public void beforeTestMethodWithTransactionalDeclaredOnClassViaMetaAnnotation() throws Exception { + void beforeTestMethodWithTransactionalDeclaredOnClassViaMetaAnnotation() throws Exception { assertBeforeTestMethodWithTransactionalTestMethod(TransactionalDeclaredOnClassViaMetaAnnotationTestCase.class); } @Test - public void beforeTestMethodWithTransactionalDeclaredOnClassViaMetaAnnotationWithOverride() throws Exception { + void beforeTestMethodWithTransactionalDeclaredOnClassViaMetaAnnotationWithOverride() throws Exception { // Note: not actually invoked within a transaction since the test class is // annotated with @MetaTxWithOverride(propagation = NOT_SUPPORTED) assertBeforeTestMethodWithTransactionalTestMethod( @@ -108,7 +109,7 @@ public class TransactionalTestExecutionListenerTests { } @Test - public void beforeTestMethodWithTransactionalDeclaredOnMethodViaMetaAnnotationWithOverride() throws Exception { + void beforeTestMethodWithTransactionalDeclaredOnMethodViaMetaAnnotationWithOverride() throws Exception { // Note: not actually invoked within a transaction since the method is // annotated with @MetaTxWithOverride(propagation = NOT_SUPPORTED) assertBeforeTestMethodWithTransactionalTestMethod( @@ -117,87 +118,87 @@ public class TransactionalTestExecutionListenerTests { } @Test - public void beforeTestMethodWithTransactionalDeclaredOnMethodLocally() throws Exception { + void beforeTestMethodWithTransactionalDeclaredOnMethodLocally() throws Exception { assertBeforeTestMethod(TransactionalDeclaredOnMethodLocallyTestCase.class); } @Test - public void beforeTestMethodWithTransactionalDeclaredOnMethodViaMetaAnnotation() throws Exception { + void beforeTestMethodWithTransactionalDeclaredOnMethodViaMetaAnnotation() throws Exception { assertBeforeTestMethod(TransactionalDeclaredOnMethodViaMetaAnnotationTestCase.class); } @Test - public void beforeTestMethodWithBeforeTransactionDeclaredLocally() throws Exception { + void beforeTestMethodWithBeforeTransactionDeclaredLocally() throws Exception { assertBeforeTestMethod(BeforeTransactionDeclaredLocallyTestCase.class); } @Test - public void beforeTestMethodWithBeforeTransactionDeclaredViaMetaAnnotation() throws Exception { + void beforeTestMethodWithBeforeTransactionDeclaredViaMetaAnnotation() throws Exception { assertBeforeTestMethod(BeforeTransactionDeclaredViaMetaAnnotationTestCase.class); } @Test - public void afterTestMethodWithAfterTransactionDeclaredLocally() throws Exception { + void afterTestMethodWithAfterTransactionDeclaredLocally() throws Exception { assertAfterTestMethod(AfterTransactionDeclaredLocallyTestCase.class); } @Test - public void afterTestMethodWithAfterTransactionDeclaredViaMetaAnnotation() throws Exception { + void afterTestMethodWithAfterTransactionDeclaredViaMetaAnnotation() throws Exception { assertAfterTestMethod(AfterTransactionDeclaredViaMetaAnnotationTestCase.class); } @Test - public void beforeTestMethodWithBeforeTransactionDeclaredAsInterfaceDefaultMethod() throws Exception { + void beforeTestMethodWithBeforeTransactionDeclaredAsInterfaceDefaultMethod() throws Exception { assertBeforeTestMethod(BeforeTransactionDeclaredAsInterfaceDefaultMethodTestCase.class); } @Test - public void afterTestMethodWithAfterTransactionDeclaredAsInterfaceDefaultMethod() throws Exception { + void afterTestMethodWithAfterTransactionDeclaredAsInterfaceDefaultMethod() throws Exception { assertAfterTestMethod(AfterTransactionDeclaredAsInterfaceDefaultMethodTestCase.class); } @Test - public void isRollbackWithMissingRollback() throws Exception { + void isRollbackWithMissingRollback() throws Exception { assertIsRollback(MissingRollbackTestCase.class, true); } @Test - public void isRollbackWithEmptyMethodLevelRollback() throws Exception { + void isRollbackWithEmptyMethodLevelRollback() throws Exception { assertIsRollback(EmptyMethodLevelRollbackTestCase.class, true); } @Test - public void isRollbackWithMethodLevelRollbackWithExplicitValue() throws Exception { + void isRollbackWithMethodLevelRollbackWithExplicitValue() throws Exception { assertIsRollback(MethodLevelRollbackWithExplicitValueTestCase.class, false); } @Test - public void isRollbackWithMethodLevelRollbackViaMetaAnnotation() throws Exception { + void isRollbackWithMethodLevelRollbackViaMetaAnnotation() throws Exception { assertIsRollback(MethodLevelRollbackViaMetaAnnotationTestCase.class, false); } @Test - public void isRollbackWithEmptyClassLevelRollback() throws Exception { + void isRollbackWithEmptyClassLevelRollback() throws Exception { assertIsRollback(EmptyClassLevelRollbackTestCase.class, true); } @Test - public void isRollbackWithClassLevelRollbackWithExplicitValue() throws Exception { + void isRollbackWithClassLevelRollbackWithExplicitValue() throws Exception { assertIsRollback(ClassLevelRollbackWithExplicitValueTestCase.class, false); } @Test - public void isRollbackWithClassLevelRollbackViaMetaAnnotation() throws Exception { + void isRollbackWithClassLevelRollbackViaMetaAnnotation() throws Exception { assertIsRollback(ClassLevelRollbackViaMetaAnnotationTestCase.class, false); } @Test - public void isRollbackWithClassLevelRollbackWithExplicitValueOnTestInterface() throws Exception { + void isRollbackWithClassLevelRollbackWithExplicitValueOnTestInterface() throws Exception { assertIsRollback(ClassLevelRollbackWithExplicitValueOnTestInterfaceTestCase.class, false); } @Test - public void isRollbackWithClassLevelRollbackViaMetaAnnotationOnTestInterface() throws Exception { + void isRollbackWithClassLevelRollbackViaMetaAnnotationOnTestInterface() throws Exception { assertIsRollback(ClassLevelRollbackViaMetaAnnotationOnTestInterfaceTestCase.class, false); } diff --git a/spring-test/src/test/java/org/springframework/test/context/transaction/ejb/AbstractEjbTxDaoTests.java b/spring-test/src/test/java/org/springframework/test/context/transaction/ejb/AbstractEjbTxDaoTests.java index 2f1f0f1342..a3afc5e129 100644 --- a/spring-test/src/test/java/org/springframework/test/context/transaction/ejb/AbstractEjbTxDaoTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/transaction/ejb/AbstractEjbTxDaoTests.java @@ -20,15 +20,16 @@ import javax.ejb.EJB; import javax.persistence.EntityManager; import javax.persistence.PersistenceContext; -import org.junit.After; -import org.junit.FixMethodOrder; -import org.junit.Test; -import org.junit.runners.MethodSorters; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.MethodOrderer; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestMethodOrder; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.annotation.DirtiesContext.ClassMode; -import org.springframework.test.context.junit4.AbstractTransactionalJUnit4SpringContextTests; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import org.springframework.test.context.transaction.ejb.dao.TestEntityDao; +import org.springframework.transaction.annotation.Transactional; import static org.assertj.core.api.Assertions.assertThat; @@ -40,9 +41,11 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Xavier Detant * @since 4.0.1 */ -@FixMethodOrder(MethodSorters.NAME_ASCENDING) +@SpringJUnitConfig +@Transactional @DirtiesContext(classMode = ClassMode.AFTER_CLASS) -public abstract class AbstractEjbTxDaoTests extends AbstractTransactionalJUnit4SpringContextTests { +@TestMethodOrder(MethodOrderer.Alphanumeric.class) +abstract class AbstractEjbTxDaoTests { protected static final String TEST_NAME = "test-name"; @@ -54,13 +57,13 @@ public abstract class AbstractEjbTxDaoTests extends AbstractTransactionalJUnit4S @Test - public void test1InitialState() { + void test1InitialState() { int count = dao.getCount(TEST_NAME); assertThat(count).as("New TestEntity should have count=0.").isEqualTo(0); } @Test - public void test2IncrementCount1() { + void test2IncrementCount1() { int count = dao.incrementCount(TEST_NAME); assertThat(count).as("Expected count=1 after first increment.").isEqualTo(1); } @@ -71,7 +74,7 @@ public abstract class AbstractEjbTxDaoTests extends AbstractTransactionalJUnit4S * expected that the previous increment has been persisted in the database. */ @Test - public void test3IncrementCount2() { + void test3IncrementCount2() { int count = dao.getCount(TEST_NAME); assertThat(count).as("Expected count=1 after test2IncrementCount1().").isEqualTo(1); @@ -79,8 +82,8 @@ public abstract class AbstractEjbTxDaoTests extends AbstractTransactionalJUnit4S assertThat(count).as("Expected count=2 now.").isEqualTo(2); } - @After - public void synchronizePersistenceContext() { + @AfterEach + void synchronizePersistenceContext() { em.flush(); } diff --git a/spring-test/src/test/java/org/springframework/test/context/transaction/ejb/CommitForRequiredEjbTxDaoTests.java b/spring-test/src/test/java/org/springframework/test/context/transaction/ejb/CommitForRequiredEjbTxDaoTests.java index 237cebd38d..803b0031ee 100644 --- a/spring-test/src/test/java/org/springframework/test/context/transaction/ejb/CommitForRequiredEjbTxDaoTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/transaction/ejb/CommitForRequiredEjbTxDaoTests.java @@ -32,7 +32,7 @@ import org.springframework.test.context.transaction.ejb.dao.RequiredEjbTxTestEnt */ @ContextConfiguration("required-tx-config.xml") @Commit -public class CommitForRequiredEjbTxDaoTests extends AbstractEjbTxDaoTests { +class CommitForRequiredEjbTxDaoTests extends AbstractEjbTxDaoTests { /* test methods in superclass */ diff --git a/spring-test/src/test/java/org/springframework/test/context/transaction/ejb/CommitForRequiresNewEjbTxDaoTests.java b/spring-test/src/test/java/org/springframework/test/context/transaction/ejb/CommitForRequiresNewEjbTxDaoTests.java index a726008be0..dfe40f9a94 100644 --- a/spring-test/src/test/java/org/springframework/test/context/transaction/ejb/CommitForRequiresNewEjbTxDaoTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/transaction/ejb/CommitForRequiresNewEjbTxDaoTests.java @@ -32,7 +32,7 @@ import org.springframework.test.context.transaction.ejb.dao.RequiresNewEjbTxTest */ @ContextConfiguration("requires-new-tx-config.xml") @Commit -public class CommitForRequiresNewEjbTxDaoTests extends AbstractEjbTxDaoTests { +class CommitForRequiresNewEjbTxDaoTests extends AbstractEjbTxDaoTests { /* test methods in superclass */ diff --git a/spring-test/src/test/java/org/springframework/test/context/transaction/ejb/RollbackForRequiredEjbTxDaoTests.java b/spring-test/src/test/java/org/springframework/test/context/transaction/ejb/RollbackForRequiredEjbTxDaoTests.java index b7788323b6..a7c9c1672c 100644 --- a/spring-test/src/test/java/org/springframework/test/context/transaction/ejb/RollbackForRequiredEjbTxDaoTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/transaction/ejb/RollbackForRequiredEjbTxDaoTests.java @@ -16,9 +16,7 @@ package org.springframework.test.context.transaction.ejb; -import org.junit.FixMethodOrder; -import org.junit.Test; -import org.junit.runners.MethodSorters; +import org.junit.jupiter.api.Test; import org.springframework.test.annotation.Rollback; import org.springframework.test.context.transaction.TransactionalTestExecutionListener; @@ -36,27 +34,8 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Sam Brannen * @since 4.0.1 */ -@FixMethodOrder(MethodSorters.NAME_ASCENDING) @Rollback -public class RollbackForRequiredEjbTxDaoTests extends CommitForRequiredEjbTxDaoTests { - - /** - * Redeclared to ensure test method execution order. Simply delegates to super. - */ - @Test - @Override - public void test1InitialState() { - super.test1InitialState(); - } - - /** - * Redeclared to ensure test method execution order. Simply delegates to super. - */ - @Test - @Override - public void test2IncrementCount1() { - super.test2IncrementCount1(); - } +class RollbackForRequiredEjbTxDaoTests extends CommitForRequiredEjbTxDaoTests { /** * Overrides parent implementation in order to change expectations to align with @@ -66,7 +45,7 @@ public class RollbackForRequiredEjbTxDaoTests extends CommitForRequiredEjbTxDaoT */ @Test @Override - public void test3IncrementCount2() { + void test3IncrementCount2() { int count = dao.getCount(TEST_NAME); // Expecting count=0 after test2IncrementCount1() since REQUIRED transactions // participate in the existing transaction (if present), which in this case is the diff --git a/spring-test/src/test/java/org/springframework/test/context/transaction/ejb/RollbackForRequiresNewEjbTxDaoTests.java b/spring-test/src/test/java/org/springframework/test/context/transaction/ejb/RollbackForRequiresNewEjbTxDaoTests.java index 4b44c8872b..4958c41002 100644 --- a/spring-test/src/test/java/org/springframework/test/context/transaction/ejb/RollbackForRequiresNewEjbTxDaoTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/transaction/ejb/RollbackForRequiresNewEjbTxDaoTests.java @@ -35,7 +35,7 @@ import org.springframework.test.context.transaction.TransactionalTestExecutionLi * @since 4.0.1 */ @Rollback -public class RollbackForRequiresNewEjbTxDaoTests extends CommitForRequiresNewEjbTxDaoTests { +class RollbackForRequiresNewEjbTxDaoTests extends CommitForRequiresNewEjbTxDaoTests { /* test methods in superclass */ diff --git a/spring-test/src/test/java/org/springframework/test/context/transaction/programmatic/ProgrammaticTxMgmtTests.java b/spring-test/src/test/java/org/springframework/test/context/transaction/programmatic/ProgrammaticTxMgmtTests.java index 74012a21e9..b6900deeee 100644 --- a/spring-test/src/test/java/org/springframework/test/context/transaction/programmatic/ProgrammaticTxMgmtTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/transaction/programmatic/ProgrammaticTxMgmtTests.java @@ -21,10 +21,9 @@ import java.util.Collections; import java.util.List; import javax.sql.DataSource; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TestName; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInfo; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationContext; @@ -37,8 +36,7 @@ import org.springframework.jdbc.datasource.DataSourceTransactionManager; import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder; import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator; import org.springframework.test.annotation.Commit; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import org.springframework.test.context.transaction.AfterTransaction; import org.springframework.test.context.transaction.BeforeTransaction; import org.springframework.test.context.transaction.TestTransaction; @@ -48,6 +46,7 @@ import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Transactional; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatIllegalStateException; import static org.assertj.core.api.Assertions.fail; import static org.springframework.test.transaction.TransactionAssert.assertThatTransaction; @@ -58,38 +57,36 @@ import static org.springframework.test.transaction.TransactionAssert.assertThatT * @author Sam Brannen * @since 4.1 */ -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration +@SpringJUnitConfig @Transactional -public class ProgrammaticTxMgmtTests { +class ProgrammaticTxMgmtTests { - private String sqlScriptEncoding; - - protected JdbcTemplate jdbcTemplate; + String sqlScriptEncoding; + JdbcTemplate jdbcTemplate; + String methodName; @Autowired - protected ApplicationContext applicationContext; - - @Rule - public TestName testName = new TestName(); - + ApplicationContext applicationContext; @Autowired - public void setDataSource(DataSource dataSource) { + void setDataSource(DataSource dataSource) { this.jdbcTemplate = new JdbcTemplate(dataSource); } + @BeforeEach + void trackTestName(TestInfo testInfo) { + this.methodName = testInfo.getTestMethod().get().getName(); + } @BeforeTransaction - public void beforeTransaction() { + void beforeTransaction() { deleteFromTables("user"); executeSqlScript("classpath:/org/springframework/test/context/jdbc/data.sql", false); } @AfterTransaction - public void afterTransaction() { - String method = testName.getMethodName(); - switch (method) { + void afterTransaction() { + switch (this.methodName) { case "commitTxAndStartNewTx": case "commitTxButDoNotStartNewTx": { assertUsers("Dogbert"); @@ -106,54 +103,54 @@ public class ProgrammaticTxMgmtTests { break; } default: { - fail("missing 'after transaction' assertion for test method: " + method); + fail("missing 'after transaction' assertion for test method: " + this.methodName); } } } @Test @Transactional(propagation = Propagation.NOT_SUPPORTED) - public void isActiveWithNonExistentTransactionContext() { + void isActiveWithNonExistentTransactionContext() { assertThat(TestTransaction.isActive()).isFalse(); } - @Test(expected = IllegalStateException.class) + @Test @Transactional(propagation = Propagation.NOT_SUPPORTED) - public void flagForRollbackWithNonExistentTransactionContext() { - TestTransaction.flagForRollback(); - } - - @Test(expected = IllegalStateException.class) - @Transactional(propagation = Propagation.NOT_SUPPORTED) - public void flagForCommitWithNonExistentTransactionContext() { - TestTransaction.flagForCommit(); - } - - @Test(expected = IllegalStateException.class) - @Transactional(propagation = Propagation.NOT_SUPPORTED) - public void isFlaggedForRollbackWithNonExistentTransactionContext() { - TestTransaction.isFlaggedForRollback(); - } - - @Test(expected = IllegalStateException.class) - @Transactional(propagation = Propagation.NOT_SUPPORTED) - public void startTxWithNonExistentTransactionContext() { - TestTransaction.start(); - } - - @Test(expected = IllegalStateException.class) - public void startTxWithExistingTransaction() { - TestTransaction.start(); - } - - @Test(expected = IllegalStateException.class) - @Transactional(propagation = Propagation.NOT_SUPPORTED) - public void endTxWithNonExistentTransactionContext() { - TestTransaction.end(); + void flagForRollbackWithNonExistentTransactionContext() { + assertThatIllegalStateException().isThrownBy(TestTransaction::flagForRollback); } @Test - public void commitTxAndStartNewTx() { + @Transactional(propagation = Propagation.NOT_SUPPORTED) + void flagForCommitWithNonExistentTransactionContext() { + assertThatIllegalStateException().isThrownBy(TestTransaction::flagForCommit); + } + + @Test + @Transactional(propagation = Propagation.NOT_SUPPORTED) + void isFlaggedForRollbackWithNonExistentTransactionContext() { + assertThatIllegalStateException().isThrownBy(TestTransaction::isFlaggedForRollback); + } + + @Test + @Transactional(propagation = Propagation.NOT_SUPPORTED) + void startTxWithNonExistentTransactionContext() { + assertThatIllegalStateException().isThrownBy(TestTransaction::start); + } + + @Test + void startTxWithExistingTransaction() { + assertThatIllegalStateException().isThrownBy(TestTransaction::start); + } + + @Test + @Transactional(propagation = Propagation.NOT_SUPPORTED) + void endTxWithNonExistentTransactionContext() { + assertThatIllegalStateException().isThrownBy(TestTransaction::end); + } + + @Test + void commitTxAndStartNewTx() { assertThatTransaction().isActive(); assertThat(TestTransaction.isActive()).isTrue(); assertUsers("Dilbert"); @@ -177,7 +174,7 @@ public class ProgrammaticTxMgmtTests { } @Test - public void commitTxButDoNotStartNewTx() { + void commitTxButDoNotStartNewTx() { assertThatTransaction().isActive(); assertThat(TestTransaction.isActive()).isTrue(); assertUsers("Dilbert"); @@ -197,7 +194,7 @@ public class ProgrammaticTxMgmtTests { } @Test - public void rollbackTxAndStartNewTx() { + void rollbackTxAndStartNewTx() { assertThatTransaction().isActive(); assertThat(TestTransaction.isActive()).isTrue(); assertUsers("Dilbert"); @@ -222,7 +219,7 @@ public class ProgrammaticTxMgmtTests { } @Test - public void rollbackTxButDoNotStartNewTx() { + void rollbackTxButDoNotStartNewTx() { assertThatTransaction().isActive(); assertThat(TestTransaction.isActive()).isTrue(); assertUsers("Dilbert"); @@ -239,7 +236,7 @@ public class ProgrammaticTxMgmtTests { @Test @Commit - public void rollbackTxAndStartNewTxWithDefaultCommitSemantics() { + void rollbackTxAndStartNewTxWithDefaultCommitSemantics() { assertThatTransaction().isActive(); assertThat(TestTransaction.isActive()).isTrue(); assertUsers("Dilbert"); @@ -286,12 +283,12 @@ public class ProgrammaticTxMgmtTests { static class Config { @Bean - public PlatformTransactionManager transactionManager() { + PlatformTransactionManager transactionManager() { return new DataSourceTransactionManager(dataSource()); } @Bean - public DataSource dataSource() { + DataSource dataSource() { return new EmbeddedDatabaseBuilder()// .generateUniqueName(true)// .addScript("classpath:/org/springframework/test/context/jdbc/schema.sql") // diff --git a/spring-test/src/test/java/org/springframework/test/context/web/AbstractBasicWacTests.java b/spring-test/src/test/java/org/springframework/test/context/web/AbstractBasicWacTests.java index ea5c162882..64df24956f 100644 --- a/spring-test/src/test/java/org/springframework/test/context/web/AbstractBasicWacTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/web/AbstractBasicWacTests.java @@ -27,7 +27,7 @@ import org.springframework.mock.web.MockHttpServletRequest; import org.springframework.mock.web.MockHttpServletResponse; import org.springframework.mock.web.MockHttpSession; import org.springframework.mock.web.MockServletContext; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit4.SpringRunner; import org.springframework.web.context.ServletContextAware; import org.springframework.web.context.WebApplicationContext; import org.springframework.web.context.request.ServletWebRequest; @@ -38,7 +38,7 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Sam Brannen * @since 3.2 */ -@RunWith(SpringJUnit4ClassRunner.class) +@RunWith(SpringRunner.class) @WebAppConfiguration public abstract class AbstractBasicWacTests implements ServletContextAware { diff --git a/spring-test/src/test/java/org/springframework/test/context/web/AnnotationConfigWebContextLoaderTests.java b/spring-test/src/test/java/org/springframework/test/context/web/AnnotationConfigWebContextLoaderTests.java index cbf8e29fa7..221f84c29e 100644 --- a/spring-test/src/test/java/org/springframework/test/context/web/AnnotationConfigWebContextLoaderTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/web/AnnotationConfigWebContextLoaderTests.java @@ -16,7 +16,7 @@ package org.springframework.test.context.web; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThatIllegalStateException; @@ -26,20 +26,20 @@ import static org.assertj.core.api.Assertions.assertThatIllegalStateException; * @author Sam Brannen * @since 4.0.4 */ -public class AnnotationConfigWebContextLoaderTests { +class AnnotationConfigWebContextLoaderTests { private static final String[] EMPTY_STRING_ARRAY = new String[0]; private static final Class[] EMPTY_CLASS_ARRAY = new Class[0]; @Test - public void configMustNotContainLocations() throws Exception { + void configMustNotContainLocations() throws Exception { AnnotationConfigWebContextLoader loader = new AnnotationConfigWebContextLoader(); WebMergedContextConfiguration mergedConfig = new WebMergedContextConfiguration(getClass(), new String[] { "config.xml" }, EMPTY_CLASS_ARRAY, null, EMPTY_STRING_ARRAY, EMPTY_STRING_ARRAY, EMPTY_STRING_ARRAY, "resource/path", loader, null, null); - assertThatIllegalStateException().isThrownBy(() -> - loader.loadContext(mergedConfig)) + assertThatIllegalStateException() + .isThrownBy(() -> loader.loadContext(mergedConfig)) .withMessageContaining("does not support resource locations"); } diff --git a/spring-test/src/test/java/org/springframework/test/context/web/GenericXmlWebContextLoaderTests.java b/spring-test/src/test/java/org/springframework/test/context/web/GenericXmlWebContextLoaderTests.java index 5dada698b5..e6fc82e65b 100644 --- a/spring-test/src/test/java/org/springframework/test/context/web/GenericXmlWebContextLoaderTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/web/GenericXmlWebContextLoaderTests.java @@ -16,7 +16,7 @@ package org.springframework.test.context.web; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThatIllegalStateException; @@ -26,19 +26,19 @@ import static org.assertj.core.api.Assertions.assertThatIllegalStateException; * @author Sam Brannen * @since 4.0.4 */ -public class GenericXmlWebContextLoaderTests { +class GenericXmlWebContextLoaderTests { private static final String[] EMPTY_STRING_ARRAY = new String[0]; @Test - public void configMustNotContainAnnotatedClasses() throws Exception { + void configMustNotContainAnnotatedClasses() throws Exception { GenericXmlWebContextLoader loader = new GenericXmlWebContextLoader(); WebMergedContextConfiguration mergedConfig = new WebMergedContextConfiguration(getClass(), EMPTY_STRING_ARRAY, new Class[] { getClass() }, null, EMPTY_STRING_ARRAY, EMPTY_STRING_ARRAY, EMPTY_STRING_ARRAY, "resource/path", loader, null, null); - assertThatIllegalStateException().isThrownBy(() -> - loader.loadContext(mergedConfig)) + assertThatIllegalStateException() + .isThrownBy(() -> loader.loadContext(mergedConfig)) .withMessageContaining("does not support annotated classes"); } diff --git a/spring-test/src/test/java/org/springframework/test/context/web/MetaAnnotationConfigWacTests.java b/spring-test/src/test/java/org/springframework/test/context/web/MetaAnnotationConfigWacTests.java index 2954dfc5b3..373780b076 100644 --- a/spring-test/src/test/java/org/springframework/test/context/web/MetaAnnotationConfigWacTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/web/MetaAnnotationConfigWacTests.java @@ -18,13 +18,13 @@ package org.springframework.test.context.web; import java.io.File; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.mock.web.MockServletContext; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.web.context.WebApplicationContext; import static org.assertj.core.api.Assertions.assertThat; @@ -37,27 +37,27 @@ import static org.assertj.core.api.Assertions.assertThat; * @since 4.0 * @see WebTestConfiguration */ -@RunWith(SpringJUnit4ClassRunner.class) +@ExtendWith(SpringExtension.class) @WebTestConfiguration -public class MetaAnnotationConfigWacTests { +class MetaAnnotationConfigWacTests { @Autowired - protected WebApplicationContext wac; + WebApplicationContext wac; @Autowired - protected MockServletContext mockServletContext; + MockServletContext mockServletContext; @Autowired - protected String foo; + String foo; @Test - public void fooEnigmaAutowired() { + void fooEnigmaAutowired() { assertThat(foo).isEqualTo("enigma"); } @Test - public void basicWacFeatures() throws Exception { + void basicWacFeatures() throws Exception { assertThat(wac.getServletContext()).as("ServletContext should be set in the WAC.").isNotNull(); assertThat(mockServletContext).as("ServletContext should have been autowired from the WAC.").isNotNull(); diff --git a/spring-test/src/test/java/org/springframework/test/context/web/RequestAndSessionScopedBeansWacTests.java b/spring-test/src/test/java/org/springframework/test/context/web/RequestAndSessionScopedBeansWacTests.java index 457bb260da..ea37de37fd 100644 --- a/spring-test/src/test/java/org/springframework/test/context/web/RequestAndSessionScopedBeansWacTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/web/RequestAndSessionScopedBeansWacTests.java @@ -16,14 +16,12 @@ package org.springframework.test.context.web; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.mock.web.MockHttpServletRequest; import org.springframework.mock.web.MockHttpSession; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.web.SpringJUnitWebConfig; import org.springframework.tests.sample.beans.TestBean; import org.springframework.web.context.WebApplicationContext; @@ -36,25 +34,23 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Sam Brannen * @since 3.2 */ -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration -@WebAppConfiguration -public class RequestAndSessionScopedBeansWacTests { +@SpringJUnitWebConfig +class RequestAndSessionScopedBeansWacTests { @Autowired - private WebApplicationContext wac; + WebApplicationContext wac; @Autowired - private MockHttpServletRequest request; + MockHttpServletRequest request; @Autowired - private MockHttpSession session; + MockHttpSession session; @Test - public void requestScope() throws Exception { - final String beanName = "requestScopedTestBean"; - final String contextPath = "/path"; + void requestScope() throws Exception { + String beanName = "requestScopedTestBean"; + String contextPath = "/path"; assertThat(request.getAttribute(beanName)).isNull(); @@ -67,8 +63,8 @@ public class RequestAndSessionScopedBeansWacTests { } @Test - public void sessionScope() throws Exception { - final String beanName = "sessionScopedTestBean"; + void sessionScope() throws Exception { + String beanName = "sessionScopedTestBean"; assertThat(session.getAttribute(beanName)).isNull(); diff --git a/spring-test/src/test/java/org/springframework/test/context/web/ServletTestExecutionListenerJUnitIntegrationTests.java b/spring-test/src/test/java/org/springframework/test/context/web/ServletTestExecutionListenerJUnitIntegrationTests.java index f1acb92aa7..a1d09a257d 100644 --- a/spring-test/src/test/java/org/springframework/test/context/web/ServletTestExecutionListenerJUnitIntegrationTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/web/ServletTestExecutionListenerJUnitIntegrationTests.java @@ -16,14 +16,12 @@ package org.springframework.test.context.web; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Configuration; import org.springframework.mock.web.MockHttpServletRequest; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.web.SpringJUnitWebConfig; import org.springframework.web.context.request.RequestContextHolder; import org.springframework.web.context.request.ServletRequestAttributes; @@ -36,10 +34,8 @@ import static org.assertj.core.api.Assertions.assertThat; * @since 3.2.9 * @see org.springframework.test.context.testng.web.ServletTestExecutionListenerTestNGIntegrationTests */ -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration -@WebAppConfiguration -public class ServletTestExecutionListenerJUnitIntegrationTests { +@SpringJUnitWebConfig +class ServletTestExecutionListenerJUnitIntegrationTests { @Configuration static class Config { @@ -57,7 +53,7 @@ public class ServletTestExecutionListenerJUnitIntegrationTests { * @see #ensureMocksAreReinjectedBetweenTests_2 */ @Test - public void ensureMocksAreReinjectedBetweenTests_1() { + void ensureMocksAreReinjectedBetweenTests_1() { assertInjectedServletRequestEqualsRequestInRequestContextHolder(); } @@ -67,7 +63,7 @@ public class ServletTestExecutionListenerJUnitIntegrationTests { * @see #ensureMocksAreReinjectedBetweenTests_1 */ @Test - public void ensureMocksAreReinjectedBetweenTests_2() { + void ensureMocksAreReinjectedBetweenTests_2() { assertInjectedServletRequestEqualsRequestInRequestContextHolder(); } diff --git a/spring-test/src/test/java/org/springframework/test/context/web/ServletTestExecutionListenerTests.java b/spring-test/src/test/java/org/springframework/test/context/web/ServletTestExecutionListenerTests.java index b2b3488d9b..36704a66d7 100644 --- a/spring-test/src/test/java/org/springframework/test/context/web/ServletTestExecutionListenerTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/web/ServletTestExecutionListenerTests.java @@ -16,8 +16,8 @@ package org.springframework.test.context.web; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.BDDMockito; import org.springframework.context.ApplicationContext; @@ -45,7 +45,7 @@ import static org.springframework.test.context.web.ServletTestExecutionListener. * @author Phillip Webb * @since 3.2.6 */ -public class ServletTestExecutionListenerTests { +class ServletTestExecutionListenerTests { private static final String SET_UP_OUTSIDE_OF_STEL = "setUpOutsideOfStel"; @@ -55,8 +55,8 @@ public class ServletTestExecutionListenerTests { private final ServletTestExecutionListener listener = new ServletTestExecutionListener(); - @Before - public void setUp() { + @BeforeEach + void setUp() { given(wac.getServletContext()).willReturn(mockServletContext); given(testContext.getApplicationContext()).willReturn(wac); @@ -71,7 +71,7 @@ public class ServletTestExecutionListenerTests { } @Test - public void standardApplicationContext() throws Exception { + void standardApplicationContext() throws Exception { BDDMockito.> given(testContext.getTestClass()).willReturn(getClass()); given(testContext.getApplicationContext()).willReturn(mock(ApplicationContext.class)); @@ -89,7 +89,7 @@ public class ServletTestExecutionListenerTests { } @Test - public void legacyWebTestCaseWithoutExistingRequestAttributes() throws Exception { + void legacyWebTestCaseWithoutExistingRequestAttributes() throws Exception { BDDMockito.> given(testContext.getTestClass()).willReturn(LegacyWebTestCase.class); RequestContextHolder.resetRequestAttributes(); @@ -112,7 +112,7 @@ public class ServletTestExecutionListenerTests { } @Test - public void legacyWebTestCaseWithPresetRequestAttributes() throws Exception { + void legacyWebTestCaseWithPresetRequestAttributes() throws Exception { BDDMockito.> given(testContext.getTestClass()).willReturn(LegacyWebTestCase.class); listener.beforeTestClass(testContext); @@ -134,7 +134,7 @@ public class ServletTestExecutionListenerTests { } @Test - public void atWebAppConfigTestCaseWithoutExistingRequestAttributes() throws Exception { + void atWebAppConfigTestCaseWithoutExistingRequestAttributes() throws Exception { BDDMockito.> given(testContext.getTestClass()).willReturn(AtWebAppConfigWebTestCase.class); RequestContextHolder.resetRequestAttributes(); @@ -145,7 +145,7 @@ public class ServletTestExecutionListenerTests { } @Test - public void atWebAppConfigTestCaseWithPresetRequestAttributes() throws Exception { + void atWebAppConfigTestCaseWithPresetRequestAttributes() throws Exception { BDDMockito.> given(testContext.getTestClass()).willReturn(AtWebAppConfigWebTestCase.class); listener.beforeTestClass(testContext); @@ -158,7 +158,7 @@ public class ServletTestExecutionListenerTests { * @since 4.3 */ @Test - public void activateListenerWithoutExistingRequestAttributes() throws Exception { + void activateListenerWithoutExistingRequestAttributes() throws Exception { BDDMockito.> given(testContext.getTestClass()).willReturn(NoAtWebAppConfigWebTestCase.class); given(testContext.getAttribute(ServletTestExecutionListener.ACTIVATE_LISTENER)).willReturn(true); diff --git a/spring-test/src/test/java/org/springframework/test/context/web/WebAppConfigurationBootstrapWithTests.java b/spring-test/src/test/java/org/springframework/test/context/web/WebAppConfigurationBootstrapWithTests.java index 73bf25dc84..2904a46048 100644 --- a/spring-test/src/test/java/org/springframework/test/context/web/WebAppConfigurationBootstrapWithTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/web/WebAppConfigurationBootstrapWithTests.java @@ -16,16 +16,14 @@ package org.springframework.test.context.web; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Configuration; import org.springframework.core.io.Resource; import org.springframework.test.context.BootstrapWith; -import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.MergedContextConfiguration; -import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.context.junit.jupiter.web.SpringJUnitWebConfig; import org.springframework.test.context.web.WebAppConfigurationBootstrapWithTests.CustomWebTestContextBootstrapper; import org.springframework.web.context.WebApplicationContext; @@ -39,18 +37,16 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Phillip Webb * @since 4.3 */ -@RunWith(SpringRunner.class) -@ContextConfiguration -@WebAppConfiguration +@SpringJUnitWebConfig @BootstrapWith(CustomWebTestContextBootstrapper.class) -public class WebAppConfigurationBootstrapWithTests { +class WebAppConfigurationBootstrapWithTests { @Autowired WebApplicationContext wac; @Test - public void webApplicationContextIsLoaded() { + void webApplicationContextIsLoaded() { // from: src/test/webapp/resources/Spring.js Resource resource = wac.getResource("/resources/Spring.js"); assertThat(resource).isNotNull(); diff --git a/spring-test/src/test/java/org/springframework/test/context/web/WebContextLoaderTestSuite.java b/spring-test/src/test/java/org/springframework/test/context/web/WebContextLoaderTestSuite.java deleted file mode 100644 index 8a57a6d1c0..0000000000 --- a/spring-test/src/test/java/org/springframework/test/context/web/WebContextLoaderTestSuite.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright 2002-2012 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.test.context.web; - -import org.junit.runner.RunWith; -import org.junit.runners.Suite; -import org.junit.runners.Suite.SuiteClasses; - -import org.springframework.test.context.ContextLoader; -import org.springframework.web.context.WebApplicationContext; - -/** - * Convenience test suite for integration tests that verify support for - * {@link WebApplicationContext} {@linkplain ContextLoader context loaders} - * in the TestContext framework. - * - * @author Sam Brannen - * @since 3.2 - */ -@RunWith(Suite.class) -// Note: the following 'multi-line' layout is for enhanced code readability. -@SuiteClasses({// -BasicXmlWacTests.class,// - BasicAnnotationConfigWacTests.class,// - RequestAndSessionScopedBeansWacTests.class // -}) -public class WebContextLoaderTestSuite { -} diff --git a/spring-test/src/test/java/org/springframework/test/context/web/socket/WebSocketServletServerContainerFactoryBeanTests.java b/spring-test/src/test/java/org/springframework/test/context/web/socket/WebSocketServletServerContainerFactoryBeanTests.java index 1d580d3a35..42fecb9d3a 100644 --- a/spring-test/src/test/java/org/springframework/test/context/web/socket/WebSocketServletServerContainerFactoryBeanTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/web/socket/WebSocketServletServerContainerFactoryBeanTests.java @@ -18,13 +18,12 @@ package org.springframework.test.context.web.socket; import javax.websocket.server.ServerContainer; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.context.junit.jupiter.web.SpringJUnitWebConfig; import org.springframework.test.context.web.WebAppConfiguration; import org.springframework.web.socket.config.annotation.EnableWebSocket; import org.springframework.web.socket.server.standard.ServletServerContainerFactoryBean; @@ -39,16 +38,11 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Sam Brannen * @since 4.3.1 */ -@RunWith(SpringRunner.class) -@WebAppConfiguration -public class WebSocketServletServerContainerFactoryBeanTests { - - @Autowired - ServerContainer serverContainer; - +@SpringJUnitWebConfig +class WebSocketServletServerContainerFactoryBeanTests { @Test - public void servletServerContainerFactoryBeanSupport() { + void servletServerContainerFactoryBeanSupport(@Autowired ServerContainer serverContainer) { assertThat(serverContainer.getDefaultMaxTextMessageBufferSize()).isEqualTo(42); } diff --git a/spring-test/src/test/java/org/springframework/test/jdbc/JdbcTestUtilsTests.java b/spring-test/src/test/java/org/springframework/test/jdbc/JdbcTestUtilsTests.java index 23c7201aae..0a6727dd18 100644 --- a/spring-test/src/test/java/org/springframework/test/jdbc/JdbcTestUtilsTests.java +++ b/spring-test/src/test/java/org/springframework/test/jdbc/JdbcTestUtilsTests.java @@ -16,10 +16,10 @@ package org.springframework.test.jdbc; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; import org.springframework.jdbc.core.JdbcTemplate; @@ -33,29 +33,29 @@ import static org.mockito.BDDMockito.given; * @since 2.5.4 * @see JdbcTestUtilsIntegrationTests */ -@RunWith(MockitoJUnitRunner.class) -public class JdbcTestUtilsTests { +@ExtendWith(MockitoExtension.class) +class JdbcTestUtilsTests { @Mock private JdbcTemplate jdbcTemplate; @Test - public void deleteWithoutWhereClause() throws Exception { + void deleteWithoutWhereClause() throws Exception { given(jdbcTemplate.update("DELETE FROM person")).willReturn(10); int deleted = JdbcTestUtils.deleteFromTableWhere(jdbcTemplate, "person", null); assertThat(deleted).isEqualTo(10); } @Test - public void deleteWithWhereClause() throws Exception { + void deleteWithWhereClause() throws Exception { given(jdbcTemplate.update("DELETE FROM person WHERE name = 'Bob' and age > 25")).willReturn(10); int deleted = JdbcTestUtils.deleteFromTableWhere(jdbcTemplate, "person", "name = 'Bob' and age > 25"); assertThat(deleted).isEqualTo(10); } @Test - public void deleteWithWhereClauseAndArguments() throws Exception { + void deleteWithWhereClauseAndArguments() throws Exception { given(jdbcTemplate.update("DELETE FROM person WHERE name = ? and age > ?", "Bob", 25)).willReturn(10); int deleted = JdbcTestUtils.deleteFromTableWhere(jdbcTemplate, "person", "name = ? and age > ?", "Bob", 25); assertThat(deleted).isEqualTo(10); diff --git a/spring-test/src/test/java/org/springframework/test/util/AopTestUtilsTests.java b/spring-test/src/test/java/org/springframework/test/util/AopTestUtilsTests.java index a124770192..6c43a66e5f 100644 --- a/spring-test/src/test/java/org/springframework/test/util/AopTestUtilsTests.java +++ b/spring-test/src/test/java/org/springframework/test/util/AopTestUtilsTests.java @@ -16,7 +16,7 @@ package org.springframework.test.util; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.aop.framework.ProxyFactory; import org.springframework.aop.support.AopUtils; @@ -32,91 +32,91 @@ import static org.springframework.test.util.AopTestUtils.getUltimateTargetObject * @author Sam Brannen * @since 4.2 */ -public class AopTestUtilsTests { +class AopTestUtilsTests { private final FooImpl foo = new FooImpl(); @Test - public void getTargetObjectForNull() { + void getTargetObjectForNull() { assertThatIllegalArgumentException().isThrownBy(() -> getTargetObject(null)); } @Test - public void getTargetObjectForNonProxiedObject() { + void getTargetObjectForNonProxiedObject() { Foo target = getTargetObject(foo); assertThat(target).isSameAs(foo); } @Test - public void getTargetObjectWrappedInSingleJdkDynamicProxy() { + void getTargetObjectWrappedInSingleJdkDynamicProxy() { Foo target = getTargetObject(jdkProxy(foo)); assertThat(target).isSameAs(foo); } @Test - public void getTargetObjectWrappedInSingleCglibProxy() { + void getTargetObjectWrappedInSingleCglibProxy() { Foo target = getTargetObject(cglibProxy(foo)); assertThat(target).isSameAs(foo); } @Test - public void getTargetObjectWrappedInDoubleJdkDynamicProxy() { + void getTargetObjectWrappedInDoubleJdkDynamicProxy() { Foo target = getTargetObject(jdkProxy(jdkProxy(foo))); assertThat(target).isNotSameAs(foo); } @Test - public void getTargetObjectWrappedInDoubleCglibProxy() { + void getTargetObjectWrappedInDoubleCglibProxy() { Foo target = getTargetObject(cglibProxy(cglibProxy(foo))); assertThat(target).isNotSameAs(foo); } @Test - public void getUltimateTargetObjectForNull() { + void getUltimateTargetObjectForNull() { assertThatIllegalArgumentException().isThrownBy(() -> getUltimateTargetObject(null)); } @Test - public void getUltimateTargetObjectForNonProxiedObject() { + void getUltimateTargetObjectForNonProxiedObject() { Foo target = getUltimateTargetObject(foo); assertThat(target).isSameAs(foo); } @Test - public void getUltimateTargetObjectWrappedInSingleJdkDynamicProxy() { + void getUltimateTargetObjectWrappedInSingleJdkDynamicProxy() { Foo target = getUltimateTargetObject(jdkProxy(foo)); assertThat(target).isSameAs(foo); } @Test - public void getUltimateTargetObjectWrappedInSingleCglibProxy() { + void getUltimateTargetObjectWrappedInSingleCglibProxy() { Foo target = getUltimateTargetObject(cglibProxy(foo)); assertThat(target).isSameAs(foo); } @Test - public void getUltimateTargetObjectWrappedInDoubleJdkDynamicProxy() { + void getUltimateTargetObjectWrappedInDoubleJdkDynamicProxy() { Foo target = getUltimateTargetObject(jdkProxy(jdkProxy(foo))); assertThat(target).isSameAs(foo); } @Test - public void getUltimateTargetObjectWrappedInDoubleCglibProxy() { + void getUltimateTargetObjectWrappedInDoubleCglibProxy() { Foo target = getUltimateTargetObject(cglibProxy(cglibProxy(foo))); assertThat(target).isSameAs(foo); } @Test - public void getUltimateTargetObjectWrappedInCglibProxyWrappedInJdkDynamicProxy() { + void getUltimateTargetObjectWrappedInCglibProxyWrappedInJdkDynamicProxy() { Foo target = getUltimateTargetObject(jdkProxy(cglibProxy(foo))); assertThat(target).isSameAs(foo); } @Test - public void getUltimateTargetObjectWrappedInCglibProxyWrappedInDoubleJdkDynamicProxy() { + void getUltimateTargetObjectWrappedInCglibProxyWrappedInDoubleJdkDynamicProxy() { Foo target = getUltimateTargetObject(jdkProxy(jdkProxy(cglibProxy(foo)))); assertThat(target).isSameAs(foo); } diff --git a/spring-test/src/test/java/org/springframework/test/util/JsonPathExpectationsHelperTests.java b/spring-test/src/test/java/org/springframework/test/util/JsonPathExpectationsHelperTests.java index bd4673c1f1..e6e9b2ba1f 100644 --- a/spring-test/src/test/java/org/springframework/test/util/JsonPathExpectationsHelperTests.java +++ b/spring-test/src/test/java/org/springframework/test/util/JsonPathExpectationsHelperTests.java @@ -16,7 +16,7 @@ package org.springframework.test.util; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThatExceptionOfType; import static org.hamcrest.core.Is.is; @@ -28,7 +28,7 @@ import static org.hamcrest.core.Is.is; * @author Sam Brannen * @since 3.2 */ -public class JsonPathExpectationsHelperTests { +class JsonPathExpectationsHelperTests { private static final String CONTENT = "{" + // "'str': 'foo', " + // @@ -52,27 +52,27 @@ public class JsonPathExpectationsHelperTests { @Test - public void exists() throws Exception { + void exists() throws Exception { new JsonPathExpectationsHelper("$.str").exists(CONTENT); } @Test - public void existsForAnEmptyArray() throws Exception { + void existsForAnEmptyArray() throws Exception { new JsonPathExpectationsHelper("$.emptyArray").exists(CONTENT); } @Test - public void existsForAnEmptyMap() throws Exception { + void existsForAnEmptyMap() throws Exception { new JsonPathExpectationsHelper("$.emptyMap").exists(CONTENT); } @Test - public void existsForIndefinatePathWithResults() throws Exception { + void existsForIndefinatePathWithResults() throws Exception { new JsonPathExpectationsHelper("$.familyMembers[?(@.name == 'Bart')]").exists(SIMPSONS); } @Test - public void existsForIndefinatePathWithEmptyResults() throws Exception { + void existsForIndefinatePathWithEmptyResults() throws Exception { String expression = "$.familyMembers[?(@.name == 'Dilbert')]"; assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> new JsonPathExpectationsHelper(expression).exists(SIMPSONS)) @@ -80,12 +80,12 @@ public class JsonPathExpectationsHelperTests { } @Test - public void doesNotExist() throws Exception { + void doesNotExist() throws Exception { new JsonPathExpectationsHelper("$.bogus").doesNotExist(CONTENT); } @Test - public void doesNotExistForAnEmptyArray() throws Exception { + void doesNotExistForAnEmptyArray() throws Exception { String expression = "$.emptyArray"; assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> new JsonPathExpectationsHelper(expression).doesNotExist(CONTENT)) @@ -93,7 +93,7 @@ public class JsonPathExpectationsHelperTests { } @Test - public void doesNotExistForAnEmptyMap() throws Exception { + void doesNotExistForAnEmptyMap() throws Exception { String expression = "$.emptyMap"; assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> new JsonPathExpectationsHelper(expression).doesNotExist(CONTENT)) @@ -101,7 +101,7 @@ public class JsonPathExpectationsHelperTests { } @Test - public void doesNotExistForIndefinatePathWithResults() throws Exception { + void doesNotExistForIndefinatePathWithResults() throws Exception { String expression = "$.familyMembers[?(@.name == 'Bart')]"; assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> new JsonPathExpectationsHelper(expression).doesNotExist(SIMPSONS)) @@ -109,32 +109,32 @@ public class JsonPathExpectationsHelperTests { } @Test - public void doesNotExistForIndefinatePathWithEmptyResults() throws Exception { + void doesNotExistForIndefinatePathWithEmptyResults() throws Exception { new JsonPathExpectationsHelper("$.familyMembers[?(@.name == 'Dilbert')]").doesNotExist(SIMPSONS); } @Test - public void assertValueIsEmptyForAnEmptyString() throws Exception { + void assertValueIsEmptyForAnEmptyString() throws Exception { new JsonPathExpectationsHelper("$.emptyString").assertValueIsEmpty(CONTENT); } @Test - public void assertValueIsEmptyForAnEmptyArray() throws Exception { + void assertValueIsEmptyForAnEmptyArray() throws Exception { new JsonPathExpectationsHelper("$.emptyArray").assertValueIsEmpty(CONTENT); } @Test - public void assertValueIsEmptyForAnEmptyMap() throws Exception { + void assertValueIsEmptyForAnEmptyMap() throws Exception { new JsonPathExpectationsHelper("$.emptyMap").assertValueIsEmpty(CONTENT); } @Test - public void assertValueIsEmptyForIndefinatePathWithEmptyResults() throws Exception { + void assertValueIsEmptyForIndefinatePathWithEmptyResults() throws Exception { new JsonPathExpectationsHelper("$.familyMembers[?(@.name == 'Dilbert')]").assertValueIsEmpty(SIMPSONS); } @Test - public void assertValueIsEmptyForIndefinatePathWithResults() throws Exception { + void assertValueIsEmptyForIndefinatePathWithResults() throws Exception { String expression = "$.familyMembers[?(@.name == 'Bart')]"; assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> new JsonPathExpectationsHelper(expression).assertValueIsEmpty(SIMPSONS)) @@ -142,7 +142,7 @@ public class JsonPathExpectationsHelperTests { } @Test - public void assertValueIsEmptyForWhitespace() throws Exception { + void assertValueIsEmptyForWhitespace() throws Exception { String expression = "$.whitespace"; assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> new JsonPathExpectationsHelper(expression).assertValueIsEmpty(CONTENT)) @@ -150,37 +150,37 @@ public class JsonPathExpectationsHelperTests { } @Test - public void assertValueIsNotEmptyForString() throws Exception { + void assertValueIsNotEmptyForString() throws Exception { new JsonPathExpectationsHelper("$.str").assertValueIsNotEmpty(CONTENT); } @Test - public void assertValueIsNotEmptyForNumber() throws Exception { + void assertValueIsNotEmptyForNumber() throws Exception { new JsonPathExpectationsHelper("$.num").assertValueIsNotEmpty(CONTENT); } @Test - public void assertValueIsNotEmptyForBoolean() throws Exception { + void assertValueIsNotEmptyForBoolean() throws Exception { new JsonPathExpectationsHelper("$.bool").assertValueIsNotEmpty(CONTENT); } @Test - public void assertValueIsNotEmptyForArray() throws Exception { + void assertValueIsNotEmptyForArray() throws Exception { new JsonPathExpectationsHelper("$.arr").assertValueIsNotEmpty(CONTENT); } @Test - public void assertValueIsNotEmptyForMap() throws Exception { + void assertValueIsNotEmptyForMap() throws Exception { new JsonPathExpectationsHelper("$.colorMap").assertValueIsNotEmpty(CONTENT); } @Test - public void assertValueIsNotEmptyForIndefinatePathWithResults() throws Exception { + void assertValueIsNotEmptyForIndefinatePathWithResults() throws Exception { new JsonPathExpectationsHelper("$.familyMembers[?(@.name == 'Bart')]").assertValueIsNotEmpty(SIMPSONS); } @Test - public void assertValueIsNotEmptyForIndefinatePathWithEmptyResults() throws Exception { + void assertValueIsNotEmptyForIndefinatePathWithEmptyResults() throws Exception { String expression = "$.familyMembers[?(@.name == 'Dilbert')]"; assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> new JsonPathExpectationsHelper(expression).assertValueIsNotEmpty(SIMPSONS)) @@ -188,7 +188,7 @@ public class JsonPathExpectationsHelperTests { } @Test - public void assertValueIsNotEmptyForAnEmptyString() throws Exception { + void assertValueIsNotEmptyForAnEmptyString() throws Exception { String expression = "$.emptyString"; assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> new JsonPathExpectationsHelper(expression).assertValueIsNotEmpty(CONTENT)) @@ -196,7 +196,7 @@ public class JsonPathExpectationsHelperTests { } @Test - public void assertValueIsNotEmptyForAnEmptyArray() throws Exception { + void assertValueIsNotEmptyForAnEmptyArray() throws Exception { String expression = "$.emptyArray"; assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> new JsonPathExpectationsHelper(expression).assertValueIsNotEmpty(CONTENT)) @@ -204,7 +204,7 @@ public class JsonPathExpectationsHelperTests { } @Test - public void assertValueIsNotEmptyForAnEmptyMap() throws Exception { + void assertValueIsNotEmptyForAnEmptyMap() throws Exception { String expression = "$.emptyMap"; assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> new JsonPathExpectationsHelper(expression).assertValueIsNotEmpty(CONTENT)) @@ -212,22 +212,22 @@ public class JsonPathExpectationsHelperTests { } @Test - public void hasJsonPath() { + void hasJsonPath() { new JsonPathExpectationsHelper("$.abc").hasJsonPath("{\"abc\": \"123\"}"); } @Test - public void hasJsonPathWithNull() { + void hasJsonPathWithNull() { new JsonPathExpectationsHelper("$.abc").hasJsonPath("{\"abc\": null}"); } @Test - public void hasJsonPathForIndefinatePathWithResults() { + void hasJsonPathForIndefinatePathWithResults() { new JsonPathExpectationsHelper("$.familyMembers[?(@.name == 'Bart')]").hasJsonPath(SIMPSONS); } @Test - public void hasJsonPathForIndefinatePathWithEmptyResults() { + void hasJsonPathForIndefinatePathWithEmptyResults() { String expression = "$.familyMembers[?(@.name == 'Dilbert')]"; assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> new JsonPathExpectationsHelper(expression).hasJsonPath(SIMPSONS)) @@ -235,23 +235,23 @@ public class JsonPathExpectationsHelperTests { } @Test // SPR-16339 - public void doesNotHaveJsonPath() { + void doesNotHaveJsonPath() { new JsonPathExpectationsHelper("$.abc").doesNotHaveJsonPath("{}"); } @Test // SPR-16339 - public void doesNotHaveJsonPathWithNull() { + void doesNotHaveJsonPathWithNull() { assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> new JsonPathExpectationsHelper("$.abc").doesNotHaveJsonPath("{\"abc\": null}")); } @Test - public void doesNotHaveJsonPathForIndefinatePathWithEmptyResults() { + void doesNotHaveJsonPathForIndefinatePathWithEmptyResults() { new JsonPathExpectationsHelper("$.familyMembers[?(@.name == 'Dilbert')]").doesNotHaveJsonPath(SIMPSONS); } @Test - public void doesNotHaveEmptyPathForIndefinatePathWithResults() { + void doesNotHaveEmptyPathForIndefinatePathWithResults() { String expression = "$.familyMembers[?(@.name == 'Bart')]"; assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> new JsonPathExpectationsHelper(expression).doesNotHaveJsonPath(SIMPSONS)) @@ -259,32 +259,32 @@ public class JsonPathExpectationsHelperTests { } @Test - public void assertValue() throws Exception { + void assertValue() throws Exception { new JsonPathExpectationsHelper("$.num").assertValue(CONTENT, 5); } @Test // SPR-14498 - public void assertValueWithNumberConversion() throws Exception { + void assertValueWithNumberConversion() throws Exception { new JsonPathExpectationsHelper("$.num").assertValue(CONTENT, 5.0); } @Test // SPR-14498 - public void assertValueWithNumberConversionAndMatcher() throws Exception { + void assertValueWithNumberConversionAndMatcher() throws Exception { new JsonPathExpectationsHelper("$.num").assertValue(CONTENT, is(5.0), Double.class); } @Test - public void assertValueIsString() throws Exception { + void assertValueIsString() throws Exception { new JsonPathExpectationsHelper("$.str").assertValueIsString(CONTENT); } @Test - public void assertValueIsStringForAnEmptyString() throws Exception { + void assertValueIsStringForAnEmptyString() throws Exception { new JsonPathExpectationsHelper("$.emptyString").assertValueIsString(CONTENT); } @Test - public void assertValueIsStringForNonString() throws Exception { + void assertValueIsStringForNonString() throws Exception { String expression = "$.bool"; assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> new JsonPathExpectationsHelper(expression).assertValueIsString(CONTENT)) @@ -292,12 +292,12 @@ public class JsonPathExpectationsHelperTests { } @Test - public void assertValueIsNumber() throws Exception { + void assertValueIsNumber() throws Exception { new JsonPathExpectationsHelper("$.num").assertValueIsNumber(CONTENT); } @Test - public void assertValueIsNumberForNonNumber() throws Exception { + void assertValueIsNumberForNonNumber() throws Exception { String expression = "$.bool"; assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> new JsonPathExpectationsHelper(expression).assertValueIsNumber(CONTENT)) @@ -305,12 +305,12 @@ public class JsonPathExpectationsHelperTests { } @Test - public void assertValueIsBoolean() throws Exception { + void assertValueIsBoolean() throws Exception { new JsonPathExpectationsHelper("$.bool").assertValueIsBoolean(CONTENT); } @Test - public void assertValueIsBooleanForNonBoolean() throws Exception { + void assertValueIsBooleanForNonBoolean() throws Exception { String expression = "$.num"; assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> new JsonPathExpectationsHelper(expression).assertValueIsBoolean(CONTENT)) @@ -318,17 +318,17 @@ public class JsonPathExpectationsHelperTests { } @Test - public void assertValueIsArray() throws Exception { + void assertValueIsArray() throws Exception { new JsonPathExpectationsHelper("$.arr").assertValueIsArray(CONTENT); } @Test - public void assertValueIsArrayForAnEmptyArray() throws Exception { + void assertValueIsArrayForAnEmptyArray() throws Exception { new JsonPathExpectationsHelper("$.emptyArray").assertValueIsArray(CONTENT); } @Test - public void assertValueIsArrayForNonArray() throws Exception { + void assertValueIsArrayForNonArray() throws Exception { String expression = "$.str"; assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> new JsonPathExpectationsHelper(expression).assertValueIsArray(CONTENT)) @@ -336,17 +336,17 @@ public class JsonPathExpectationsHelperTests { } @Test - public void assertValueIsMap() throws Exception { + void assertValueIsMap() throws Exception { new JsonPathExpectationsHelper("$.colorMap").assertValueIsMap(CONTENT); } @Test - public void assertValueIsMapForAnEmptyMap() throws Exception { + void assertValueIsMapForAnEmptyMap() throws Exception { new JsonPathExpectationsHelper("$.emptyMap").assertValueIsMap(CONTENT); } @Test - public void assertValueIsMapForNonMap() throws Exception { + void assertValueIsMapForNonMap() throws Exception { String expression = "$.str"; assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> new JsonPathExpectationsHelper(expression).assertValueIsMap(CONTENT)) diff --git a/spring-test/src/test/java/org/springframework/test/util/MetaAnnotationUtilsTests.java b/spring-test/src/test/java/org/springframework/test/util/MetaAnnotationUtilsTests.java index f07624edb3..c0a7e22209 100644 --- a/spring-test/src/test/java/org/springframework/test/util/MetaAnnotationUtilsTests.java +++ b/spring-test/src/test/java/org/springframework/test/util/MetaAnnotationUtilsTests.java @@ -23,7 +23,7 @@ import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.core.annotation.AnnotationUtils; import org.springframework.core.annotation.Order; @@ -45,7 +45,7 @@ import static org.springframework.test.util.MetaAnnotationUtils.findAnnotationDe * @since 4.0 * @see OverriddenMetaAnnotationAttributesTests */ -public class MetaAnnotationUtilsTests { +class MetaAnnotationUtilsTests { private void assertAtComponentOnComposedAnnotation( Class rootDeclaringClass, String name, Class composedAnnotationType) { @@ -105,20 +105,20 @@ public class MetaAnnotationUtilsTests { } @Test - public void findAnnotationDescriptorWithNoAnnotationPresent() { + void findAnnotationDescriptorWithNoAnnotationPresent() { assertThat(findAnnotationDescriptor(NonAnnotatedInterface.class, Transactional.class)).isNull(); assertThat(findAnnotationDescriptor(NonAnnotatedClass.class, Transactional.class)).isNull(); } @Test - public void findAnnotationDescriptorWithInheritedAnnotationOnClass() { + void findAnnotationDescriptorWithInheritedAnnotationOnClass() { // Note: @Transactional is inherited assertThat(findAnnotationDescriptor(InheritedAnnotationClass.class, Transactional.class).getRootDeclaringClass()).isEqualTo(InheritedAnnotationClass.class); assertThat(findAnnotationDescriptor(SubInheritedAnnotationClass.class, Transactional.class).getRootDeclaringClass()).isEqualTo(InheritedAnnotationClass.class); } @Test - public void findAnnotationDescriptorWithInheritedAnnotationOnInterface() { + void findAnnotationDescriptorWithInheritedAnnotationOnInterface() { // Note: @Transactional is inherited Transactional rawAnnotation = InheritedAnnotationInterface.class.getAnnotation(Transactional.class); @@ -143,14 +143,14 @@ public class MetaAnnotationUtilsTests { } @Test - public void findAnnotationDescriptorForNonInheritedAnnotationOnClass() { + void findAnnotationDescriptorForNonInheritedAnnotationOnClass() { // Note: @Order is not inherited. assertThat(findAnnotationDescriptor(NonInheritedAnnotationClass.class, Order.class).getRootDeclaringClass()).isEqualTo(NonInheritedAnnotationClass.class); assertThat(findAnnotationDescriptor(SubNonInheritedAnnotationClass.class, Order.class).getRootDeclaringClass()).isEqualTo(NonInheritedAnnotationClass.class); } @Test - public void findAnnotationDescriptorForNonInheritedAnnotationOnInterface() { + void findAnnotationDescriptorForNonInheritedAnnotationOnInterface() { // Note: @Order is not inherited. Order rawAnnotation = NonInheritedAnnotationInterface.class.getAnnotation(Order.class); @@ -169,12 +169,12 @@ public class MetaAnnotationUtilsTests { } @Test - public void findAnnotationDescriptorWithMetaComponentAnnotation() { + void findAnnotationDescriptorWithMetaComponentAnnotation() { assertAtComponentOnComposedAnnotation(HasMetaComponentAnnotation.class, "meta1", Meta1.class); } @Test - public void findAnnotationDescriptorWithLocalAndMetaComponentAnnotation() { + void findAnnotationDescriptorWithLocalAndMetaComponentAnnotation() { Class annotationType = Component.class; AnnotationDescriptor descriptor = findAnnotationDescriptor( HasLocalAndMetaComponentAnnotation.class, annotationType); @@ -186,12 +186,12 @@ public class MetaAnnotationUtilsTests { } @Test - public void findAnnotationDescriptorForInterfaceWithMetaAnnotation() { + void findAnnotationDescriptorForInterfaceWithMetaAnnotation() { assertAtComponentOnComposedAnnotation(InterfaceWithMetaAnnotation.class, "meta1", Meta1.class); } @Test - public void findAnnotationDescriptorForClassWithMetaAnnotatedInterface() { + void findAnnotationDescriptorForClassWithMetaAnnotatedInterface() { Component rawAnnotation = AnnotationUtils.findAnnotation(ClassWithMetaAnnotatedInterface.class, Component.class); AnnotationDescriptor descriptor = findAnnotationDescriptor(ClassWithMetaAnnotatedInterface.class, Component.class); @@ -204,7 +204,7 @@ public class MetaAnnotationUtilsTests { } @Test - public void findAnnotationDescriptorForClassWithLocalMetaAnnotationAndAnnotatedSuperclass() { + void findAnnotationDescriptorForClassWithLocalMetaAnnotationAndAnnotatedSuperclass() { AnnotationDescriptor descriptor = findAnnotationDescriptor( MetaAnnotatedAndSuperAnnotatedContextConfigClass.class, ContextConfiguration.class); @@ -219,12 +219,12 @@ public class MetaAnnotationUtilsTests { } @Test - public void findAnnotationDescriptorForClassWithLocalMetaAnnotationAndMetaAnnotatedInterface() { + void findAnnotationDescriptorForClassWithLocalMetaAnnotationAndMetaAnnotatedInterface() { assertAtComponentOnComposedAnnotation(ClassWithLocalMetaAnnotationAndMetaAnnotatedInterface.class, "meta2", Meta2.class); } @Test - public void findAnnotationDescriptorForSubClassWithLocalMetaAnnotationAndMetaAnnotatedInterface() { + void findAnnotationDescriptorForSubClassWithLocalMetaAnnotationAndMetaAnnotatedInterface() { assertAtComponentOnComposedAnnotation(SubClassWithLocalMetaAnnotationAndMetaAnnotatedInterface.class, ClassWithLocalMetaAnnotationAndMetaAnnotatedInterface.class, "meta2", Meta2.class); } @@ -233,7 +233,7 @@ public class MetaAnnotationUtilsTests { * @since 4.0.3 */ @Test - public void findAnnotationDescriptorOnMetaMetaAnnotatedClass() { + void findAnnotationDescriptorOnMetaMetaAnnotatedClass() { Class startClass = MetaMetaAnnotatedClass.class; assertAtComponentOnComposedAnnotation(startClass, startClass, Meta2.class, "meta2", MetaMeta.class); } @@ -242,7 +242,7 @@ public class MetaAnnotationUtilsTests { * @since 4.0.3 */ @Test - public void findAnnotationDescriptorOnMetaMetaMetaAnnotatedClass() { + void findAnnotationDescriptorOnMetaMetaMetaAnnotatedClass() { Class startClass = MetaMetaMetaAnnotatedClass.class; assertAtComponentOnComposedAnnotation(startClass, startClass, Meta2.class, "meta2", MetaMetaMeta.class); } @@ -251,7 +251,7 @@ public class MetaAnnotationUtilsTests { * @since 4.0.3 */ @Test - public void findAnnotationDescriptorOnAnnotatedClassWithMissingTargetMetaAnnotation() { + void findAnnotationDescriptorOnAnnotatedClassWithMissingTargetMetaAnnotation() { // InheritedAnnotationClass is NOT annotated or meta-annotated with @Component AnnotationDescriptor descriptor = findAnnotationDescriptor( InheritedAnnotationClass.class, Component.class); @@ -262,7 +262,7 @@ public class MetaAnnotationUtilsTests { * @since 4.0.3 */ @Test - public void findAnnotationDescriptorOnMetaCycleAnnotatedClassWithMissingTargetMetaAnnotation() { + void findAnnotationDescriptorOnMetaCycleAnnotatedClassWithMissingTargetMetaAnnotation() { AnnotationDescriptor descriptor = findAnnotationDescriptor( MetaCycleAnnotatedClass.class, Component.class); assertThat(descriptor).as("Should not find @Component on MetaCycleAnnotatedClass").isNull(); @@ -272,14 +272,14 @@ public class MetaAnnotationUtilsTests { @Test @SuppressWarnings("unchecked") - public void findAnnotationDescriptorForTypesWithNoAnnotationPresent() { + void findAnnotationDescriptorForTypesWithNoAnnotationPresent() { assertThat(findAnnotationDescriptorForTypes(NonAnnotatedInterface.class, Transactional.class, Component.class)).isNull(); assertThat(findAnnotationDescriptorForTypes(NonAnnotatedClass.class, Transactional.class, Order.class)).isNull(); } @Test @SuppressWarnings("unchecked") - public void findAnnotationDescriptorForTypesWithInheritedAnnotationOnClass() { + void findAnnotationDescriptorForTypesWithInheritedAnnotationOnClass() { // Note: @Transactional is inherited assertThat(findAnnotationDescriptorForTypes(InheritedAnnotationClass.class, Transactional.class).getRootDeclaringClass()).isEqualTo(InheritedAnnotationClass.class); assertThat(findAnnotationDescriptorForTypes(SubInheritedAnnotationClass.class, Transactional.class).getRootDeclaringClass()).isEqualTo(InheritedAnnotationClass.class); @@ -287,7 +287,7 @@ public class MetaAnnotationUtilsTests { @Test @SuppressWarnings("unchecked") - public void findAnnotationDescriptorForTypesWithInheritedAnnotationOnInterface() { + void findAnnotationDescriptorForTypesWithInheritedAnnotationOnInterface() { // Note: @Transactional is inherited Transactional rawAnnotation = InheritedAnnotationInterface.class.getAnnotation(Transactional.class); @@ -313,7 +313,7 @@ public class MetaAnnotationUtilsTests { @Test @SuppressWarnings("unchecked") - public void findAnnotationDescriptorForTypesForNonInheritedAnnotationOnClass() { + void findAnnotationDescriptorForTypesForNonInheritedAnnotationOnClass() { // Note: @Order is not inherited. assertThat(findAnnotationDescriptorForTypes(NonInheritedAnnotationClass.class, Order.class).getRootDeclaringClass()).isEqualTo(NonInheritedAnnotationClass.class); assertThat(findAnnotationDescriptorForTypes(SubNonInheritedAnnotationClass.class, Order.class).getRootDeclaringClass()).isEqualTo(NonInheritedAnnotationClass.class); @@ -321,7 +321,7 @@ public class MetaAnnotationUtilsTests { @Test @SuppressWarnings("unchecked") - public void findAnnotationDescriptorForTypesForNonInheritedAnnotationOnInterface() { + void findAnnotationDescriptorForTypesForNonInheritedAnnotationOnInterface() { // Note: @Order is not inherited. Order rawAnnotation = NonInheritedAnnotationInterface.class.getAnnotation(Order.class); @@ -341,7 +341,7 @@ public class MetaAnnotationUtilsTests { @Test @SuppressWarnings("unchecked") - public void findAnnotationDescriptorForTypesWithLocalAndMetaComponentAnnotation() { + void findAnnotationDescriptorForTypesWithLocalAndMetaComponentAnnotation() { Class annotationType = Component.class; UntypedAnnotationDescriptor descriptor = findAnnotationDescriptorForTypes( HasLocalAndMetaComponentAnnotation.class, Transactional.class, annotationType, Order.class); @@ -352,14 +352,14 @@ public class MetaAnnotationUtilsTests { } @Test - public void findAnnotationDescriptorForTypesWithMetaComponentAnnotation() { + void findAnnotationDescriptorForTypesWithMetaComponentAnnotation() { Class startClass = HasMetaComponentAnnotation.class; assertAtComponentOnComposedAnnotationForMultipleCandidateTypes(startClass, "meta1", Meta1.class); } @Test @SuppressWarnings("unchecked") - public void findAnnotationDescriptorForTypesWithMetaAnnotationWithDefaultAttributes() { + void findAnnotationDescriptorForTypesWithMetaAnnotationWithDefaultAttributes() { Class startClass = MetaConfigWithDefaultAttributesTestCase.class; Class annotationType = ContextConfiguration.class; @@ -377,7 +377,7 @@ public class MetaAnnotationUtilsTests { @Test @SuppressWarnings("unchecked") - public void findAnnotationDescriptorForTypesWithMetaAnnotationWithOverriddenAttributes() { + void findAnnotationDescriptorForTypesWithMetaAnnotationWithOverriddenAttributes() { Class startClass = MetaConfigWithOverriddenAttributesTestCase.class; Class annotationType = ContextConfiguration.class; @@ -394,14 +394,14 @@ public class MetaAnnotationUtilsTests { } @Test - public void findAnnotationDescriptorForTypesForInterfaceWithMetaAnnotation() { + void findAnnotationDescriptorForTypesForInterfaceWithMetaAnnotation() { Class startClass = InterfaceWithMetaAnnotation.class; assertAtComponentOnComposedAnnotationForMultipleCandidateTypes(startClass, "meta1", Meta1.class); } @Test @SuppressWarnings("unchecked") - public void findAnnotationDescriptorForTypesForClassWithMetaAnnotatedInterface() { + void findAnnotationDescriptorForTypesForClassWithMetaAnnotatedInterface() { Component rawAnnotation = AnnotationUtils.findAnnotation(ClassWithMetaAnnotatedInterface.class, Component.class); UntypedAnnotationDescriptor descriptor = findAnnotationDescriptorForTypes( @@ -415,13 +415,13 @@ public class MetaAnnotationUtilsTests { } @Test - public void findAnnotationDescriptorForTypesForClassWithLocalMetaAnnotationAndMetaAnnotatedInterface() { + void findAnnotationDescriptorForTypesForClassWithLocalMetaAnnotationAndMetaAnnotatedInterface() { Class startClass = ClassWithLocalMetaAnnotationAndMetaAnnotatedInterface.class; assertAtComponentOnComposedAnnotationForMultipleCandidateTypes(startClass, "meta2", Meta2.class); } @Test - public void findAnnotationDescriptorForTypesForSubClassWithLocalMetaAnnotationAndMetaAnnotatedInterface() { + void findAnnotationDescriptorForTypesForSubClassWithLocalMetaAnnotationAndMetaAnnotatedInterface() { assertAtComponentOnComposedAnnotationForMultipleCandidateTypes( SubClassWithLocalMetaAnnotationAndMetaAnnotatedInterface.class, ClassWithLocalMetaAnnotationAndMetaAnnotatedInterface.class, "meta2", Meta2.class); @@ -431,7 +431,7 @@ public class MetaAnnotationUtilsTests { * @since 4.0.3 */ @Test - public void findAnnotationDescriptorForTypesOnMetaMetaAnnotatedClass() { + void findAnnotationDescriptorForTypesOnMetaMetaAnnotatedClass() { Class startClass = MetaMetaAnnotatedClass.class; assertAtComponentOnComposedAnnotationForMultipleCandidateTypes( startClass, startClass, Meta2.class, "meta2", MetaMeta.class); @@ -441,7 +441,7 @@ public class MetaAnnotationUtilsTests { * @since 4.0.3 */ @Test - public void findAnnotationDescriptorForTypesOnMetaMetaMetaAnnotatedClass() { + void findAnnotationDescriptorForTypesOnMetaMetaMetaAnnotatedClass() { Class startClass = MetaMetaMetaAnnotatedClass.class; assertAtComponentOnComposedAnnotationForMultipleCandidateTypes( startClass, startClass, Meta2.class, "meta2", MetaMetaMeta.class); @@ -452,7 +452,7 @@ public class MetaAnnotationUtilsTests { */ @Test @SuppressWarnings("unchecked") - public void findAnnotationDescriptorForTypesOnAnnotatedClassWithMissingTargetMetaAnnotation() { + void findAnnotationDescriptorForTypesOnAnnotatedClassWithMissingTargetMetaAnnotation() { // InheritedAnnotationClass is NOT annotated or meta-annotated with @Component, // @Service, or @Order, but it is annotated with @Transactional. UntypedAnnotationDescriptor descriptor = findAnnotationDescriptorForTypes( @@ -465,7 +465,7 @@ public class MetaAnnotationUtilsTests { */ @Test @SuppressWarnings("unchecked") - public void findAnnotationDescriptorForTypesOnMetaCycleAnnotatedClassWithMissingTargetMetaAnnotation() { + void findAnnotationDescriptorForTypesOnMetaCycleAnnotatedClassWithMissingTargetMetaAnnotation() { UntypedAnnotationDescriptor descriptor = findAnnotationDescriptorForTypes( MetaCycleAnnotatedClass.class, Service.class, Component.class, Order.class); assertThat(descriptor).as("Should not find @Component on MetaCycleAnnotatedClass").isNull(); @@ -581,11 +581,11 @@ public class MetaAnnotationUtilsTests { } @MetaConfig - public class MetaConfigWithDefaultAttributesTestCase { + class MetaConfigWithDefaultAttributesTestCase { } @MetaConfig(classes = MetaAnnotationUtilsTests.class) - public class MetaConfigWithOverriddenAttributesTestCase { + class MetaConfigWithOverriddenAttributesTestCase { } // ------------------------------------------------------------------------- diff --git a/spring-test/src/test/java/org/springframework/test/util/OverriddenMetaAnnotationAttributesTests.java b/spring-test/src/test/java/org/springframework/test/util/OverriddenMetaAnnotationAttributesTests.java index 8c9ebd9dd3..6712df08bc 100644 --- a/spring-test/src/test/java/org/springframework/test/util/OverriddenMetaAnnotationAttributesTests.java +++ b/spring-test/src/test/java/org/springframework/test/util/OverriddenMetaAnnotationAttributesTests.java @@ -19,7 +19,7 @@ package org.springframework.test.util; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.core.annotation.AnnotationAttributes; import org.springframework.test.context.ContextConfiguration; @@ -38,10 +38,10 @@ import static org.springframework.test.util.MetaAnnotationUtils.findAnnotationDe * @since 4.0 * @see MetaAnnotationUtilsTests */ -public class OverriddenMetaAnnotationAttributesTests { +class OverriddenMetaAnnotationAttributesTests { @Test - public void contextConfigurationValue() throws Exception { + void contextConfigurationValue() throws Exception { Class declaringClass = MetaValueConfigTestCase.class; AnnotationDescriptor descriptor = findAnnotationDescriptor(declaringClass, ContextConfiguration.class); @@ -57,7 +57,7 @@ public class OverriddenMetaAnnotationAttributesTests { } @Test - public void overriddenContextConfigurationValue() throws Exception { + void overriddenContextConfigurationValue() throws Exception { Class declaringClass = OverriddenMetaValueConfigTestCase.class; AnnotationDescriptor descriptor = findAnnotationDescriptor(declaringClass, ContextConfiguration.class); @@ -81,7 +81,7 @@ public class OverriddenMetaAnnotationAttributesTests { } @Test - public void contextConfigurationLocationsAndInheritLocations() throws Exception { + void contextConfigurationLocationsAndInheritLocations() throws Exception { Class declaringClass = MetaLocationsConfigTestCase.class; AnnotationDescriptor descriptor = findAnnotationDescriptor(declaringClass, ContextConfiguration.class); @@ -98,7 +98,7 @@ public class OverriddenMetaAnnotationAttributesTests { } @Test - public void overriddenContextConfigurationLocationsAndInheritLocations() throws Exception { + void overriddenContextConfigurationLocationsAndInheritLocations() throws Exception { Class declaringClass = OverriddenMetaLocationsConfigTestCase.class; AnnotationDescriptor descriptor = findAnnotationDescriptor(declaringClass, ContextConfiguration.class); @@ -130,11 +130,11 @@ public class OverriddenMetaAnnotationAttributesTests { } @MetaValueConfig - public static class MetaValueConfigTestCase { + static class MetaValueConfigTestCase { } @MetaValueConfig("bar.xml") - public static class OverriddenMetaValueConfigTestCase { + static class OverriddenMetaValueConfigTestCase { } @ContextConfiguration(locations = "foo.xml", inheritLocations = false) diff --git a/spring-test/src/test/java/org/springframework/test/util/ReflectionTestUtilsTests.java b/spring-test/src/test/java/org/springframework/test/util/ReflectionTestUtilsTests.java index 5a5c9fe5cc..bd000db1ef 100644 --- a/spring-test/src/test/java/org/springframework/test/util/ReflectionTestUtilsTests.java +++ b/spring-test/src/test/java/org/springframework/test/util/ReflectionTestUtilsTests.java @@ -16,9 +16,9 @@ package org.springframework.test.util; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import org.springframework.aop.framework.ProxyFactory; import org.springframework.aop.support.AopUtils; @@ -43,7 +43,7 @@ import static org.springframework.test.util.ReflectionTestUtils.setField; * @author Sam Brannen * @author Juergen Hoeller */ -public class ReflectionTestUtilsTests { +class ReflectionTestUtilsTests { private static final Float PI = Float.valueOf((float) 22 / 7); @@ -54,67 +54,67 @@ public class ReflectionTestUtilsTests { private final LegacyEntity entity = new LegacyEntity(); - @Before - public void resetStaticFields() { + @BeforeEach + void resetStaticFields() { StaticFields.reset(); } @Test - public void setFieldWithNullTargetObject() throws Exception { + void setFieldWithNullTargetObject() throws Exception { assertThatIllegalArgumentException().isThrownBy(() -> setField((Object) null, "id", Long.valueOf(99))) .withMessageStartingWith("Either targetObject or targetClass"); } @Test - public void getFieldWithNullTargetObject() throws Exception { + void getFieldWithNullTargetObject() throws Exception { assertThatIllegalArgumentException().isThrownBy(() -> getField((Object) null, "id")) .withMessageStartingWith("Either targetObject or targetClass"); } @Test - public void setFieldWithNullTargetClass() throws Exception { + void setFieldWithNullTargetClass() throws Exception { assertThatIllegalArgumentException().isThrownBy(() -> setField((Class) null, "id", Long.valueOf(99))) .withMessageStartingWith("Either targetObject or targetClass"); } @Test - public void getFieldWithNullTargetClass() throws Exception { + void getFieldWithNullTargetClass() throws Exception { assertThatIllegalArgumentException().isThrownBy(() -> getField((Class) null, "id")) .withMessageStartingWith("Either targetObject or targetClass"); } @Test - public void setFieldWithNullNameAndNullType() throws Exception { + void setFieldWithNullNameAndNullType() throws Exception { assertThatIllegalArgumentException().isThrownBy(() -> setField(person, null, Long.valueOf(99), null)) .withMessageStartingWith("Either name or type"); } @Test - public void setFieldWithBogusName() throws Exception { + void setFieldWithBogusName() throws Exception { assertThatIllegalArgumentException().isThrownBy(() -> setField(person, "bogus", Long.valueOf(99), long.class)) .withMessageStartingWith("Could not find field 'bogus'"); } @Test - public void setFieldWithWrongType() throws Exception { + void setFieldWithWrongType() throws Exception { assertThatIllegalArgumentException().isThrownBy(() -> setField(person, "id", Long.valueOf(99), String.class)) .withMessageStartingWith("Could not find field"); } @Test - public void setFieldAndGetFieldForStandardUseCases() throws Exception { + void setFieldAndGetFieldForStandardUseCases() throws Exception { assertSetFieldAndGetFieldBehavior(this.person); } @Test - public void setFieldAndGetFieldViaJdkDynamicProxy() throws Exception { + void setFieldAndGetFieldViaJdkDynamicProxy() throws Exception { ProxyFactory pf = new ProxyFactory(this.person); pf.addInterface(Person.class); Person proxy = (Person) pf.getProxy(); @@ -123,7 +123,7 @@ public class ReflectionTestUtilsTests { } @Test - public void setFieldAndGetFieldViaCglibProxy() throws Exception { + void setFieldAndGetFieldViaCglibProxy() throws Exception { ProxyFactory pf = new ProxyFactory(this.person); pf.setProxyTargetClass(true); Person proxy = (Person) pf.getProxy(); @@ -170,7 +170,7 @@ public class ReflectionTestUtilsTests { } @Test - public void setFieldWithNullValuesForNonPrimitives() throws Exception { + void setFieldWithNullValuesForNonPrimitives() throws Exception { // Fields must be non-null to start with setField(person, "name", "Tom"); setField(person, "eyeColor", "blue", String.class); @@ -190,25 +190,22 @@ public class ReflectionTestUtilsTests { } @Test - public void setFieldWithNullValueForPrimitiveLong() throws Exception { - assertThatIllegalArgumentException().isThrownBy(() -> - setField(person, "id", null, long.class)); + void setFieldWithNullValueForPrimitiveLong() throws Exception { + assertThatIllegalArgumentException().isThrownBy(() -> setField(person, "id", null, long.class)); } @Test - public void setFieldWithNullValueForPrimitiveInt() throws Exception { - assertThatIllegalArgumentException().isThrownBy(() -> - setField(person, "age", null, int.class)); + void setFieldWithNullValueForPrimitiveInt() throws Exception { + assertThatIllegalArgumentException().isThrownBy(() -> setField(person, "age", null, int.class)); } @Test - public void setFieldWithNullValueForPrimitiveBoolean() throws Exception { - assertThatIllegalArgumentException().isThrownBy(() -> - setField(person, "likesPets", null, boolean.class)); + void setFieldWithNullValueForPrimitiveBoolean() throws Exception { + assertThatIllegalArgumentException().isThrownBy(() -> setField(person, "likesPets", null, boolean.class)); } @Test - public void setStaticFieldViaClass() throws Exception { + void setStaticFieldViaClass() throws Exception { setField(StaticFields.class, "publicField", "xxx"); setField(StaticFields.class, "privateField", "yyy"); @@ -217,7 +214,7 @@ public class ReflectionTestUtilsTests { } @Test - public void setStaticFieldViaClassWithExplicitType() throws Exception { + void setStaticFieldViaClassWithExplicitType() throws Exception { setField(StaticFields.class, "publicField", "xxx", String.class); setField(StaticFields.class, "privateField", "yyy", String.class); @@ -226,7 +223,7 @@ public class ReflectionTestUtilsTests { } @Test - public void setStaticFieldViaInstance() throws Exception { + void setStaticFieldViaInstance() throws Exception { StaticFields staticFields = new StaticFields(); setField(staticFields, null, "publicField", "xxx", null); setField(staticFields, null, "privateField", "yyy", null); @@ -236,20 +233,20 @@ public class ReflectionTestUtilsTests { } @Test - public void getStaticFieldViaClass() throws Exception { + void getStaticFieldViaClass() throws Exception { assertThat(getField(StaticFields.class, "publicField")).as("public static field").isEqualTo("public"); assertThat(getField(StaticFields.class, "privateField")).as("private static field").isEqualTo("private"); } @Test - public void getStaticFieldViaInstance() throws Exception { + void getStaticFieldViaInstance() throws Exception { StaticFields staticFields = new StaticFields(); assertThat(getField(staticFields, "publicField")).as("public static field").isEqualTo("public"); assertThat(getField(staticFields, "privateField")).as("private static field").isEqualTo("private"); } @Test - public void invokeSetterMethodAndInvokeGetterMethodWithExplicitMethodNames() throws Exception { + void invokeSetterMethodAndInvokeGetterMethodWithExplicitMethodNames() throws Exception { invokeSetterMethod(person, "setId", Long.valueOf(1), long.class); invokeSetterMethod(person, "setName", "Jerry", String.class); invokeSetterMethod(person, "setAge", Integer.valueOf(33), int.class); @@ -273,7 +270,7 @@ public class ReflectionTestUtilsTests { } @Test - public void invokeSetterMethodAndInvokeGetterMethodWithJavaBeanPropertyNames() throws Exception { + void invokeSetterMethodAndInvokeGetterMethodWithJavaBeanPropertyNames() throws Exception { invokeSetterMethod(person, "id", Long.valueOf(99), long.class); invokeSetterMethod(person, "name", "Tom"); invokeSetterMethod(person, "age", Integer.valueOf(42)); @@ -297,7 +294,7 @@ public class ReflectionTestUtilsTests { } @Test - public void invokeSetterMethodWithNullValuesForNonPrimitives() throws Exception { + void invokeSetterMethodWithNullValuesForNonPrimitives() throws Exception { invokeSetterMethod(person, "name", null, String.class); invokeSetterMethod(person, "eyeColor", null, String.class); invokeSetterMethod(person, "favoriteNumber", null, Number.class); @@ -308,47 +305,45 @@ public class ReflectionTestUtilsTests { } @Test - public void invokeSetterMethodWithNullValueForPrimitiveLong() throws Exception { - assertThatIllegalArgumentException().isThrownBy(() -> - invokeSetterMethod(person, "id", null, long.class)); + void invokeSetterMethodWithNullValueForPrimitiveLong() throws Exception { + assertThatIllegalArgumentException().isThrownBy(() -> invokeSetterMethod(person, "id", null, long.class)); } @Test - public void invokeSetterMethodWithNullValueForPrimitiveInt() throws Exception { - assertThatIllegalArgumentException().isThrownBy(() -> - invokeSetterMethod(person, "age", null, int.class)); + void invokeSetterMethodWithNullValueForPrimitiveInt() throws Exception { + assertThatIllegalArgumentException().isThrownBy(() -> invokeSetterMethod(person, "age", null, int.class)); } @Test - public void invokeSetterMethodWithNullValueForPrimitiveBoolean() throws Exception { + void invokeSetterMethodWithNullValueForPrimitiveBoolean() throws Exception { assertThatIllegalArgumentException().isThrownBy(() -> invokeSetterMethod(person, "likesPets", null, boolean.class)); } @Test - public void invokeMethodWithAutoboxingAndUnboxing() { + void invokeMethodWithAutoboxingAndUnboxing() { // IntelliJ IDEA 11 won't accept int assignment here Integer difference = invokeMethod(component, "subtract", 5, 2); assertThat(difference.intValue()).as("subtract(5, 2)").isEqualTo(3); } @Test - @Ignore("[SPR-8644] findMethod() does not currently support var-args") - public void invokeMethodWithPrimitiveVarArgs() { + @Disabled("[SPR-8644] findMethod() does not currently support var-args") + void invokeMethodWithPrimitiveVarArgs() { // IntelliJ IDEA 11 won't accept int assignment here Integer sum = invokeMethod(component, "add", 1, 2, 3, 4); assertThat(sum.intValue()).as("add(1,2,3,4)").isEqualTo(10); } @Test - public void invokeMethodWithPrimitiveVarArgsAsSingleArgument() { + void invokeMethodWithPrimitiveVarArgsAsSingleArgument() { // IntelliJ IDEA 11 won't accept int assignment here Integer sum = invokeMethod(component, "add", new int[] { 1, 2, 3, 4 }); assertThat(sum.intValue()).as("add(1,2,3,4)").isEqualTo(10); } @Test - public void invokeMethodSimulatingLifecycleEvents() { + void invokeMethodSimulatingLifecycleEvents() { assertThat(component.getNumber()).as("number").isNull(); assertThat(component.getText()).as("text").isNull(); @@ -368,61 +363,61 @@ public class ReflectionTestUtilsTests { } @Test - public void invokeInitMethodBeforeAutowiring() { + void invokeInitMethodBeforeAutowiring() { assertThatIllegalStateException().isThrownBy(() -> invokeMethod(component, "init")) .withMessageStartingWith("number must not be null"); } @Test - public void invokeMethodWithIncompatibleArgumentTypes() { + void invokeMethodWithIncompatibleArgumentTypes() { assertThatIllegalStateException().isThrownBy(() -> invokeMethod(component, "subtract", "foo", 2.0)) .withMessageStartingWith("Method not found"); } @Test - public void invokeMethodWithTooFewArguments() { + void invokeMethodWithTooFewArguments() { assertThatIllegalStateException().isThrownBy(() -> invokeMethod(component, "configure", Integer.valueOf(42))) .withMessageStartingWith("Method not found"); } @Test - public void invokeMethodWithTooManyArguments() { + void invokeMethodWithTooManyArguments() { assertThatIllegalStateException().isThrownBy(() -> invokeMethod(component, "configure", Integer.valueOf(42), "enigma", "baz", "quux")) .withMessageStartingWith("Method not found"); } @Test // SPR-14363 - public void getFieldOnLegacyEntityWithSideEffectsInToString() { + void getFieldOnLegacyEntityWithSideEffectsInToString() { Object collaborator = getField(entity, "collaborator"); assertThat(collaborator).isNotNull(); } @Test // SPR-9571 and SPR-14363 - public void setFieldOnLegacyEntityWithSideEffectsInToString() { + void setFieldOnLegacyEntityWithSideEffectsInToString() { String testCollaborator = "test collaborator"; setField(entity, "collaborator", testCollaborator, Object.class); assertThat(entity.toString().contains(testCollaborator)).isTrue(); } @Test // SPR-14363 - public void invokeMethodOnLegacyEntityWithSideEffectsInToString() { + void invokeMethodOnLegacyEntityWithSideEffectsInToString() { invokeMethod(entity, "configure", Integer.valueOf(42), "enigma"); assertThat(entity.getNumber()).as("number should have been configured").isEqualTo(Integer.valueOf(42)); assertThat(entity.getText()).as("text should have been configured").isEqualTo("enigma"); } @Test // SPR-14363 - public void invokeGetterMethodOnLegacyEntityWithSideEffectsInToString() { + void invokeGetterMethodOnLegacyEntityWithSideEffectsInToString() { Object collaborator = invokeGetterMethod(entity, "collaborator"); assertThat(collaborator).isNotNull(); } @Test // SPR-14363 - public void invokeSetterMethodOnLegacyEntityWithSideEffectsInToString() { + void invokeSetterMethodOnLegacyEntityWithSideEffectsInToString() { String testCollaborator = "test collaborator"; invokeSetterMethod(entity, "collaborator", testCollaborator); assertThat(entity.toString().contains(testCollaborator)).isTrue(); diff --git a/spring-test/src/test/java/org/springframework/test/util/XmlExpectationsHelperTests.java b/spring-test/src/test/java/org/springframework/test/util/XmlExpectationsHelperTests.java index df312e611a..7eccad4e24 100644 --- a/spring-test/src/test/java/org/springframework/test/util/XmlExpectationsHelperTests.java +++ b/spring-test/src/test/java/org/springframework/test/util/XmlExpectationsHelperTests.java @@ -16,7 +16,7 @@ package org.springframework.test.util; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThatExceptionOfType; @@ -25,11 +25,10 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType; * * @author Matthew Depue */ -public class XmlExpectationsHelperTests { - +class XmlExpectationsHelperTests { @Test - public void assertXmlEqualForEqual() throws Exception { + void assertXmlEqualForEqual() throws Exception { String control = "f1f2"; String test = "f1f2"; XmlExpectationsHelper xmlHelper = new XmlExpectationsHelper(); @@ -37,7 +36,7 @@ public class XmlExpectationsHelperTests { } @Test - public void assertXmlEqualExceptionForIncorrectValue() throws Exception { + void assertXmlEqualExceptionForIncorrectValue() throws Exception { String control = "f1f2"; String test = "notf1f2"; XmlExpectationsHelper xmlHelper = new XmlExpectationsHelper(); @@ -47,7 +46,7 @@ public class XmlExpectationsHelperTests { } @Test - public void assertXmlEqualForOutOfOrder() throws Exception { + void assertXmlEqualForOutOfOrder() throws Exception { String control = "f1f2"; String test = "f2f1"; XmlExpectationsHelper xmlHelper = new XmlExpectationsHelper(); @@ -55,7 +54,7 @@ public class XmlExpectationsHelperTests { } @Test - public void assertXmlEqualExceptionForMoreEntries() throws Exception { + void assertXmlEqualExceptionForMoreEntries() throws Exception { String control = "f1f2"; String test = "f1f2f3"; XmlExpectationsHelper xmlHelper = new XmlExpectationsHelper(); @@ -66,7 +65,7 @@ public class XmlExpectationsHelperTests { } @Test - public void assertXmlEqualExceptionForLessEntries() throws Exception { + void assertXmlEqualExceptionForLessEntries() throws Exception { String control = "f1f2f3"; String test = "f1f2"; XmlExpectationsHelper xmlHelper = new XmlExpectationsHelper(); diff --git a/spring-test/src/test/java/org/springframework/test/web/client/DefaultRequestExpectationTests.java b/spring-test/src/test/java/org/springframework/test/web/client/DefaultRequestExpectationTests.java index 75bc183d13..2235119151 100644 --- a/spring-test/src/test/java/org/springframework/test/web/client/DefaultRequestExpectationTests.java +++ b/spring-test/src/test/java/org/springframework/test/web/client/DefaultRequestExpectationTests.java @@ -19,7 +19,7 @@ package org.springframework.test.web.client; import java.net.URI; import java.net.URISyntaxException; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.http.HttpMethod; import org.springframework.http.client.ClientHttpRequest; diff --git a/spring-test/src/test/java/org/springframework/test/web/client/MockRestServiceServerTests.java b/spring-test/src/test/java/org/springframework/test/web/client/MockRestServiceServerTests.java index 89c5053af8..ff556a2be1 100644 --- a/spring-test/src/test/java/org/springframework/test/web/client/MockRestServiceServerTests.java +++ b/spring-test/src/test/java/org/springframework/test/web/client/MockRestServiceServerTests.java @@ -18,7 +18,7 @@ package org.springframework.test.web.client; import java.net.SocketException; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.test.web.client.MockRestServiceServer.MockRestServiceServerBuilder; import org.springframework.web.client.RestTemplate; diff --git a/spring-test/src/test/java/org/springframework/test/web/client/SimpleRequestExpectationManagerTests.java b/spring-test/src/test/java/org/springframework/test/web/client/SimpleRequestExpectationManagerTests.java index a98a1c4dd9..33efa8d17f 100644 --- a/spring-test/src/test/java/org/springframework/test/web/client/SimpleRequestExpectationManagerTests.java +++ b/spring-test/src/test/java/org/springframework/test/web/client/SimpleRequestExpectationManagerTests.java @@ -20,7 +20,7 @@ import java.net.SocketException; import java.net.URI; import java.net.URISyntaxException; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.http.HttpMethod; import org.springframework.http.client.ClientHttpRequest; diff --git a/spring-test/src/test/java/org/springframework/test/web/client/UnorderedRequestExpectationManagerTests.java b/spring-test/src/test/java/org/springframework/test/web/client/UnorderedRequestExpectationManagerTests.java index f40c6a6043..f8f4cfa5b0 100644 --- a/spring-test/src/test/java/org/springframework/test/web/client/UnorderedRequestExpectationManagerTests.java +++ b/spring-test/src/test/java/org/springframework/test/web/client/UnorderedRequestExpectationManagerTests.java @@ -19,7 +19,7 @@ package org.springframework.test.web.client; import java.net.URI; import java.net.URISyntaxException; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.http.HttpMethod; import org.springframework.http.client.ClientHttpRequest; diff --git a/spring-test/src/test/java/org/springframework/test/web/client/match/ContentRequestMatchersTests.java b/spring-test/src/test/java/org/springframework/test/web/client/match/ContentRequestMatchersTests.java index 0adb1e4355..97e9abcd77 100644 --- a/spring-test/src/test/java/org/springframework/test/web/client/match/ContentRequestMatchersTests.java +++ b/spring-test/src/test/java/org/springframework/test/web/client/match/ContentRequestMatchersTests.java @@ -18,8 +18,8 @@ package org.springframework.test.web.client.match; import java.nio.charset.StandardCharsets; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.http.MediaType; import org.springframework.mock.http.client.MockClientHttpRequest; @@ -40,7 +40,7 @@ public class ContentRequestMatchersTests { private MockClientHttpRequest request; - @Before + @BeforeEach public void setUp() { this.request = new MockClientHttpRequest(); } diff --git a/spring-test/src/test/java/org/springframework/test/web/client/match/JsonPathRequestMatchersTests.java b/spring-test/src/test/java/org/springframework/test/web/client/match/JsonPathRequestMatchersTests.java index ef0415c696..e639a0956f 100644 --- a/spring-test/src/test/java/org/springframework/test/web/client/match/JsonPathRequestMatchersTests.java +++ b/spring-test/src/test/java/org/springframework/test/web/client/match/JsonPathRequestMatchersTests.java @@ -18,7 +18,7 @@ package org.springframework.test.web.client.match; import java.io.IOException; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.mock.http.client.MockClientHttpRequest; diff --git a/spring-test/src/test/java/org/springframework/test/web/client/match/MockRestRequestMatchersTests.java b/spring-test/src/test/java/org/springframework/test/web/client/match/MockRestRequestMatchersTests.java index 1a7a485230..7e98c4042c 100644 --- a/spring-test/src/test/java/org/springframework/test/web/client/match/MockRestRequestMatchersTests.java +++ b/spring-test/src/test/java/org/springframework/test/web/client/match/MockRestRequestMatchersTests.java @@ -20,7 +20,7 @@ import java.net.URI; import java.util.Arrays; import java.util.Collections; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.http.HttpMethod; import org.springframework.mock.http.client.MockClientHttpRequest; diff --git a/spring-test/src/test/java/org/springframework/test/web/client/match/XpathRequestMatchersTests.java b/spring-test/src/test/java/org/springframework/test/web/client/match/XpathRequestMatchersTests.java index 1fe94cab41..c7d577e9f2 100644 --- a/spring-test/src/test/java/org/springframework/test/web/client/match/XpathRequestMatchersTests.java +++ b/spring-test/src/test/java/org/springframework/test/web/client/match/XpathRequestMatchersTests.java @@ -19,8 +19,8 @@ package org.springframework.test.web.client.match; import java.io.IOException; import org.hamcrest.Matchers; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.mock.http.client.MockClientHttpRequest; @@ -38,7 +38,7 @@ public class XpathRequestMatchersTests { private MockClientHttpRequest request; - @Before + @BeforeEach public void setUp() throws IOException { this.request = new MockClientHttpRequest(); this.request.getBody().write(RESPONSE_CONTENT.getBytes()); diff --git a/spring-test/src/test/java/org/springframework/test/web/client/response/ResponseCreatorsTests.java b/spring-test/src/test/java/org/springframework/test/web/client/response/ResponseCreatorsTests.java index 0586765a64..0465bdebd3 100644 --- a/spring-test/src/test/java/org/springframework/test/web/client/response/ResponseCreatorsTests.java +++ b/spring-test/src/test/java/org/springframework/test/web/client/response/ResponseCreatorsTests.java @@ -18,7 +18,7 @@ package org.springframework.test.web.client.response; import java.net.URI; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; diff --git a/spring-test/src/test/java/org/springframework/test/web/client/samples/MockMvcClientHttpRequestFactoryTests.java b/spring-test/src/test/java/org/springframework/test/web/client/samples/MockMvcClientHttpRequestFactoryTests.java index 3b3c60a4d9..20262f0968 100644 --- a/spring-test/src/test/java/org/springframework/test/web/client/samples/MockMvcClientHttpRequestFactoryTests.java +++ b/spring-test/src/test/java/org/springframework/test/web/client/samples/MockMvcClientHttpRequestFactoryTests.java @@ -16,9 +16,9 @@ package org.springframework.test.web.client.samples; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.ComponentScan; @@ -26,7 +26,7 @@ import org.springframework.context.annotation.Configuration; import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Controller; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.test.context.web.WebAppConfiguration; import org.springframework.test.web.client.MockMvcClientHttpRequestFactory; import org.springframework.test.web.servlet.MockMvc; @@ -51,7 +51,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers. * * @author Rossen Stoyanchev */ -@RunWith(SpringJUnit4ClassRunner.class) +@ExtendWith(SpringExtension.class) @WebAppConfiguration @ContextConfiguration public class MockMvcClientHttpRequestFactoryTests { @@ -62,7 +62,7 @@ public class MockMvcClientHttpRequestFactoryTests { private MockMvc mockMvc; - @Before + @BeforeEach public void setup() { this.mockMvc = MockMvcBuilders.webAppContextSetup(this.wac).alwaysExpect(status().isOk()).build(); } diff --git a/spring-test/src/test/java/org/springframework/test/web/client/samples/SampleAsyncTests.java b/spring-test/src/test/java/org/springframework/test/web/client/samples/SampleAsyncTests.java index c976b1804e..975c46d384 100644 --- a/spring-test/src/test/java/org/springframework/test/web/client/samples/SampleAsyncTests.java +++ b/spring-test/src/test/java/org/springframework/test/web/client/samples/SampleAsyncTests.java @@ -16,7 +16,7 @@ package org.springframework.test.web.client.samples; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.Resource; diff --git a/spring-test/src/test/java/org/springframework/test/web/client/samples/SampleTests.java b/spring-test/src/test/java/org/springframework/test/web/client/samples/SampleTests.java index d05d408cb8..7488fc94e5 100644 --- a/spring-test/src/test/java/org/springframework/test/web/client/samples/SampleTests.java +++ b/spring-test/src/test/java/org/springframework/test/web/client/samples/SampleTests.java @@ -18,8 +18,8 @@ package org.springframework.test.web.client.samples; import java.io.IOException; import java.util.Collections; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.Resource; @@ -57,7 +57,7 @@ public class SampleTests { private RestTemplate restTemplate; - @Before + @BeforeEach public void setup() { this.restTemplate = new RestTemplate(); this.mockServer = MockRestServiceServer.bindTo(this.restTemplate).ignoreExpectOrder(true).build(); diff --git a/spring-test/src/test/java/org/springframework/test/web/client/samples/matchers/ContentRequestMatchersIntegrationTests.java b/spring-test/src/test/java/org/springframework/test/web/client/samples/matchers/ContentRequestMatchersIntegrationTests.java index 16c21ddb99..f2601e1eaf 100644 --- a/spring-test/src/test/java/org/springframework/test/web/client/samples/matchers/ContentRequestMatchersIntegrationTests.java +++ b/spring-test/src/test/java/org/springframework/test/web/client/samples/matchers/ContentRequestMatchersIntegrationTests.java @@ -21,8 +21,8 @@ import java.net.URISyntaxException; import java.util.ArrayList; import java.util.List; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.http.converter.HttpMessageConverter; import org.springframework.http.converter.StringHttpMessageConverter; @@ -51,7 +51,7 @@ public class ContentRequestMatchersIntegrationTests { private RestTemplate restTemplate; - @Before + @BeforeEach public void setup() { List> converters = new ArrayList<>(); converters.add(new StringHttpMessageConverter()); diff --git a/spring-test/src/test/java/org/springframework/test/web/client/samples/matchers/HeaderRequestMatchersIntegrationTests.java b/spring-test/src/test/java/org/springframework/test/web/client/samples/matchers/HeaderRequestMatchersIntegrationTests.java index a87ef35d8e..d3e29e510a 100644 --- a/spring-test/src/test/java/org/springframework/test/web/client/samples/matchers/HeaderRequestMatchersIntegrationTests.java +++ b/spring-test/src/test/java/org/springframework/test/web/client/samples/matchers/HeaderRequestMatchersIntegrationTests.java @@ -21,8 +21,8 @@ import java.net.URISyntaxException; import java.util.ArrayList; import java.util.List; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.http.MediaType; import org.springframework.http.converter.HttpMessageConverter; @@ -52,7 +52,7 @@ public class HeaderRequestMatchersIntegrationTests { private RestTemplate restTemplate; - @Before + @BeforeEach public void setup() { List> converters = new ArrayList<>(); converters.add(new StringHttpMessageConverter()); diff --git a/spring-test/src/test/java/org/springframework/test/web/client/samples/matchers/JsonPathRequestMatchersIntegrationTests.java b/spring-test/src/test/java/org/springframework/test/web/client/samples/matchers/JsonPathRequestMatchersIntegrationTests.java index 40cc10c81c..1ed1d7e1cd 100644 --- a/spring-test/src/test/java/org/springframework/test/web/client/samples/matchers/JsonPathRequestMatchersIntegrationTests.java +++ b/spring-test/src/test/java/org/springframework/test/web/client/samples/matchers/JsonPathRequestMatchersIntegrationTests.java @@ -21,7 +21,7 @@ import java.net.URISyntaxException; import java.util.Arrays; import java.util.Collections; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; import org.springframework.test.web.Person; diff --git a/spring-test/src/test/java/org/springframework/test/web/client/samples/matchers/XmlContentRequestMatchersIntegrationTests.java b/spring-test/src/test/java/org/springframework/test/web/client/samples/matchers/XmlContentRequestMatchersIntegrationTests.java index 16b720eb4e..21915d7975 100644 --- a/spring-test/src/test/java/org/springframework/test/web/client/samples/matchers/XmlContentRequestMatchersIntegrationTests.java +++ b/spring-test/src/test/java/org/springframework/test/web/client/samples/matchers/XmlContentRequestMatchersIntegrationTests.java @@ -27,8 +27,8 @@ import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlElementWrapper; import javax.xml.bind.annotation.XmlRootElement; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.http.converter.HttpMessageConverter; import org.springframework.http.converter.xml.Jaxb2RootElementHttpMessageConverter; @@ -67,7 +67,7 @@ public class XmlContentRequestMatchersIntegrationTests { private PeopleWrapper people; - @Before + @BeforeEach public void setup() { List composers = Arrays.asList( new Person("Johann Sebastian Bach").setSomeDouble(21), diff --git a/spring-test/src/test/java/org/springframework/test/web/client/samples/matchers/XpathRequestMatchersIntegrationTests.java b/spring-test/src/test/java/org/springframework/test/web/client/samples/matchers/XpathRequestMatchersIntegrationTests.java index 3cdfad8add..583a952df8 100644 --- a/spring-test/src/test/java/org/springframework/test/web/client/samples/matchers/XpathRequestMatchersIntegrationTests.java +++ b/spring-test/src/test/java/org/springframework/test/web/client/samples/matchers/XpathRequestMatchersIntegrationTests.java @@ -29,8 +29,8 @@ import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlElementWrapper; import javax.xml.bind.annotation.XmlRootElement; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.http.converter.HttpMessageConverter; import org.springframework.http.converter.xml.Jaxb2RootElementHttpMessageConverter; @@ -67,7 +67,7 @@ public class XpathRequestMatchersIntegrationTests { private PeopleWrapper people; - @Before + @BeforeEach public void setup() { List composers = Arrays.asList( new Person("Johann Sebastian Bach").setSomeDouble(21), diff --git a/spring-test/src/test/java/org/springframework/test/web/reactive/server/ApplicationContextSpecTests.java b/spring-test/src/test/java/org/springframework/test/web/reactive/server/ApplicationContextSpecTests.java index 8704ff3266..6333e8b7a6 100644 --- a/spring-test/src/test/java/org/springframework/test/web/reactive/server/ApplicationContextSpecTests.java +++ b/spring-test/src/test/java/org/springframework/test/web/reactive/server/ApplicationContextSpecTests.java @@ -15,7 +15,7 @@ */ package org.springframework.test.web.reactive.server; -import org.junit.Test; +import org.junit.jupiter.api.Test; import reactor.core.publisher.Mono; import org.springframework.context.ApplicationContext; diff --git a/spring-test/src/test/java/org/springframework/test/web/reactive/server/DefaultControllerSpecTests.java b/spring-test/src/test/java/org/springframework/test/web/reactive/server/DefaultControllerSpecTests.java index e4ca95e682..42cbf3b278 100644 --- a/spring-test/src/test/java/org/springframework/test/web/reactive/server/DefaultControllerSpecTests.java +++ b/spring-test/src/test/java/org/springframework/test/web/reactive/server/DefaultControllerSpecTests.java @@ -18,7 +18,7 @@ package org.springframework.test.web.reactive.server; import java.util.function.Consumer; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.format.FormatterRegistry; import org.springframework.http.ResponseEntity; diff --git a/spring-test/src/test/java/org/springframework/test/web/reactive/server/DefaultRouterFunctionSpecTests.java b/spring-test/src/test/java/org/springframework/test/web/reactive/server/DefaultRouterFunctionSpecTests.java index e17f289c8f..b81d3d3ca3 100644 --- a/spring-test/src/test/java/org/springframework/test/web/reactive/server/DefaultRouterFunctionSpecTests.java +++ b/spring-test/src/test/java/org/springframework/test/web/reactive/server/DefaultRouterFunctionSpecTests.java @@ -15,7 +15,7 @@ */ package org.springframework.test.web.reactive.server; -import org.junit.Test; +import org.junit.jupiter.api.Test; import reactor.core.publisher.Mono; import org.springframework.http.HttpStatus; diff --git a/spring-test/src/test/java/org/springframework/test/web/reactive/server/HeaderAssertionTests.java b/spring-test/src/test/java/org/springframework/test/web/reactive/server/HeaderAssertionTests.java index e5a15ad43b..70ea4d63af 100644 --- a/spring-test/src/test/java/org/springframework/test/web/reactive/server/HeaderAssertionTests.java +++ b/spring-test/src/test/java/org/springframework/test/web/reactive/server/HeaderAssertionTests.java @@ -22,7 +22,7 @@ import java.time.ZoneId; import java.time.ZonedDateTime; import java.util.concurrent.TimeUnit; -import org.junit.Test; +import org.junit.jupiter.api.Test; import reactor.core.publisher.MonoProcessor; import org.springframework.http.CacheControl; diff --git a/spring-test/src/test/java/org/springframework/test/web/reactive/server/HttpHandlerConnectorTests.java b/spring-test/src/test/java/org/springframework/test/web/reactive/server/HttpHandlerConnectorTests.java index 611d6d2374..9bad3a3359 100644 --- a/spring-test/src/test/java/org/springframework/test/web/reactive/server/HttpHandlerConnectorTests.java +++ b/spring-test/src/test/java/org/springframework/test/web/reactive/server/HttpHandlerConnectorTests.java @@ -22,7 +22,7 @@ import java.util.Arrays; import java.util.Collections; import java.util.function.Function; -import org.junit.Test; +import org.junit.jupiter.api.Test; import reactor.core.publisher.Mono; import org.springframework.core.io.buffer.DataBuffer; diff --git a/spring-test/src/test/java/org/springframework/test/web/reactive/server/MockServerSpecTests.java b/spring-test/src/test/java/org/springframework/test/web/reactive/server/MockServerSpecTests.java index 4917372079..b16e7b62ac 100644 --- a/spring-test/src/test/java/org/springframework/test/web/reactive/server/MockServerSpecTests.java +++ b/spring-test/src/test/java/org/springframework/test/web/reactive/server/MockServerSpecTests.java @@ -17,7 +17,7 @@ package org.springframework.test.web.reactive.server; import java.nio.charset.StandardCharsets; -import org.junit.Test; +import org.junit.jupiter.api.Test; import reactor.core.publisher.Mono; import org.springframework.core.io.buffer.DataBuffer; diff --git a/spring-test/src/test/java/org/springframework/test/web/reactive/server/MockServerTests.java b/spring-test/src/test/java/org/springframework/test/web/reactive/server/MockServerTests.java index 517da2a73f..37353fdefd 100644 --- a/spring-test/src/test/java/org/springframework/test/web/reactive/server/MockServerTests.java +++ b/spring-test/src/test/java/org/springframework/test/web/reactive/server/MockServerTests.java @@ -17,7 +17,7 @@ package org.springframework.test.web.reactive.server; import java.util.Arrays; -import org.junit.Test; +import org.junit.jupiter.api.Test; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; diff --git a/spring-test/src/test/java/org/springframework/test/web/reactive/server/StatusAssertionTests.java b/spring-test/src/test/java/org/springframework/test/web/reactive/server/StatusAssertionTests.java index 6f37e867a9..94d02b591e 100644 --- a/spring-test/src/test/java/org/springframework/test/web/reactive/server/StatusAssertionTests.java +++ b/spring-test/src/test/java/org/springframework/test/web/reactive/server/StatusAssertionTests.java @@ -19,7 +19,7 @@ package org.springframework.test.web.reactive.server; import java.net.URI; import java.time.Duration; -import org.junit.Test; +import org.junit.jupiter.api.Test; import reactor.core.publisher.MonoProcessor; import org.springframework.http.HttpMethod; diff --git a/spring-test/src/test/java/org/springframework/test/web/reactive/server/WiretapConnectorTests.java b/spring-test/src/test/java/org/springframework/test/web/reactive/server/WiretapConnectorTests.java index 7898697816..60a3ba15e3 100644 --- a/spring-test/src/test/java/org/springframework/test/web/reactive/server/WiretapConnectorTests.java +++ b/spring-test/src/test/java/org/springframework/test/web/reactive/server/WiretapConnectorTests.java @@ -19,7 +19,7 @@ package org.springframework.test.web.reactive.server; import java.net.URI; import java.time.Duration; -import org.junit.Test; +import org.junit.jupiter.api.Test; import reactor.core.publisher.Mono; import org.springframework.http.HttpMethod; diff --git a/spring-test/src/test/java/org/springframework/test/web/reactive/server/samples/ErrorTests.java b/spring-test/src/test/java/org/springframework/test/web/reactive/server/samples/ErrorTests.java index c85ff0b1af..bf9fb617ae 100644 --- a/spring-test/src/test/java/org/springframework/test/web/reactive/server/samples/ErrorTests.java +++ b/spring-test/src/test/java/org/springframework/test/web/reactive/server/samples/ErrorTests.java @@ -18,7 +18,7 @@ package org.springframework.test.web.reactive.server.samples; import java.nio.charset.StandardCharsets; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; diff --git a/spring-test/src/test/java/org/springframework/test/web/reactive/server/samples/ExchangeMutatorTests.java b/spring-test/src/test/java/org/springframework/test/web/reactive/server/samples/ExchangeMutatorTests.java index ce3a85f92b..f8fc1ea89c 100644 --- a/spring-test/src/test/java/org/springframework/test/web/reactive/server/samples/ExchangeMutatorTests.java +++ b/spring-test/src/test/java/org/springframework/test/web/reactive/server/samples/ExchangeMutatorTests.java @@ -17,8 +17,8 @@ package org.springframework.test.web.reactive.server.samples; import java.security.Principal; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import reactor.core.publisher.Mono; import org.springframework.http.client.reactive.ClientHttpConnector; @@ -43,7 +43,7 @@ public class ExchangeMutatorTests { private WebTestClient webTestClient; - @Before + @BeforeEach public void setUp() throws Exception { this.webTestClient = WebTestClient.bindToController(new TestController()) diff --git a/spring-test/src/test/java/org/springframework/test/web/reactive/server/samples/HeaderAndCookieTests.java b/spring-test/src/test/java/org/springframework/test/web/reactive/server/samples/HeaderAndCookieTests.java index 9e6397fafc..e42dff7c11 100644 --- a/spring-test/src/test/java/org/springframework/test/web/reactive/server/samples/HeaderAndCookieTests.java +++ b/spring-test/src/test/java/org/springframework/test/web/reactive/server/samples/HeaderAndCookieTests.java @@ -16,7 +16,7 @@ package org.springframework.test.web.reactive.server.samples; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; diff --git a/spring-test/src/test/java/org/springframework/test/web/reactive/server/samples/JsonContentTests.java b/spring-test/src/test/java/org/springframework/test/web/reactive/server/samples/JsonContentTests.java index 6725a0a267..ea6c3f4ebf 100644 --- a/spring-test/src/test/java/org/springframework/test/web/reactive/server/samples/JsonContentTests.java +++ b/spring-test/src/test/java/org/springframework/test/web/reactive/server/samples/JsonContentTests.java @@ -18,7 +18,7 @@ package org.springframework.test.web.reactive.server.samples; import java.net.URI; -import org.junit.Test; +import org.junit.jupiter.api.Test; import reactor.core.publisher.Flux; import org.springframework.http.MediaType; diff --git a/spring-test/src/test/java/org/springframework/test/web/reactive/server/samples/ResponseEntityTests.java b/spring-test/src/test/java/org/springframework/test/web/reactive/server/samples/ResponseEntityTests.java index dda30498fb..b78e189a18 100644 --- a/spring-test/src/test/java/org/springframework/test/web/reactive/server/samples/ResponseEntityTests.java +++ b/spring-test/src/test/java/org/springframework/test/web/reactive/server/samples/ResponseEntityTests.java @@ -22,7 +22,7 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Map; -import org.junit.Test; +import org.junit.jupiter.api.Test; import reactor.core.publisher.Flux; import reactor.test.StepVerifier; diff --git a/spring-test/src/test/java/org/springframework/test/web/reactive/server/samples/XmlContentTests.java b/spring-test/src/test/java/org/springframework/test/web/reactive/server/samples/XmlContentTests.java index 08c23635e5..b50d90f921 100644 --- a/spring-test/src/test/java/org/springframework/test/web/reactive/server/samples/XmlContentTests.java +++ b/spring-test/src/test/java/org/springframework/test/web/reactive/server/samples/XmlContentTests.java @@ -25,7 +25,7 @@ import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.http.HttpHeaders; import org.springframework.http.MediaType; diff --git a/spring-test/src/test/java/org/springframework/test/web/reactive/server/samples/bind/ApplicationContextTests.java b/spring-test/src/test/java/org/springframework/test/web/reactive/server/samples/bind/ApplicationContextTests.java index 8e71fc88e6..597921ebed 100644 --- a/spring-test/src/test/java/org/springframework/test/web/reactive/server/samples/bind/ApplicationContextTests.java +++ b/spring-test/src/test/java/org/springframework/test/web/reactive/server/samples/bind/ApplicationContextTests.java @@ -16,8 +16,8 @@ package org.springframework.test.web.reactive.server.samples.bind; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.Bean; @@ -39,7 +39,7 @@ public class ApplicationContextTests { private WebTestClient client; - @Before + @BeforeEach public void setUp() throws Exception { AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); diff --git a/spring-test/src/test/java/org/springframework/test/web/reactive/server/samples/bind/ControllerTests.java b/spring-test/src/test/java/org/springframework/test/web/reactive/server/samples/bind/ControllerTests.java index 0dbddfcae4..5c7c454bfd 100644 --- a/spring-test/src/test/java/org/springframework/test/web/reactive/server/samples/bind/ControllerTests.java +++ b/spring-test/src/test/java/org/springframework/test/web/reactive/server/samples/bind/ControllerTests.java @@ -16,8 +16,8 @@ package org.springframework.test.web.reactive.server.samples.bind; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.test.web.reactive.server.WebTestClient; import org.springframework.web.bind.annotation.GetMapping; @@ -34,7 +34,7 @@ public class ControllerTests { private WebTestClient client; - @Before + @BeforeEach public void setUp() throws Exception { this.client = WebTestClient.bindToController(new TestController()).build(); } diff --git a/spring-test/src/test/java/org/springframework/test/web/reactive/server/samples/bind/HttpServerTests.java b/spring-test/src/test/java/org/springframework/test/web/reactive/server/samples/bind/HttpServerTests.java index 752ffca7c9..f83cfbfc93 100644 --- a/spring-test/src/test/java/org/springframework/test/web/reactive/server/samples/bind/HttpServerTests.java +++ b/spring-test/src/test/java/org/springframework/test/web/reactive/server/samples/bind/HttpServerTests.java @@ -16,9 +16,9 @@ package org.springframework.test.web.reactive.server.samples.bind; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.http.server.reactive.HttpHandler; import org.springframework.http.server.reactive.bootstrap.ReactorHttpServer; @@ -42,7 +42,7 @@ public class HttpServerTests { private WebTestClient client; - @Before + @BeforeEach public void start() throws Exception { HttpHandler httpHandler = RouterFunctions.toHttpHandler( route(GET("/test"), request -> ServerResponse.ok().body("It works!"))); @@ -57,7 +57,7 @@ public class HttpServerTests { .build(); } - @After + @AfterEach public void stop() { this.server.stop(); } diff --git a/spring-test/src/test/java/org/springframework/test/web/reactive/server/samples/bind/RouterFunctionTests.java b/spring-test/src/test/java/org/springframework/test/web/reactive/server/samples/bind/RouterFunctionTests.java index 710ad2355b..0e14c2c3ab 100644 --- a/spring-test/src/test/java/org/springframework/test/web/reactive/server/samples/bind/RouterFunctionTests.java +++ b/spring-test/src/test/java/org/springframework/test/web/reactive/server/samples/bind/RouterFunctionTests.java @@ -16,8 +16,8 @@ package org.springframework.test.web.reactive.server.samples.bind; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.test.web.reactive.server.WebTestClient; import org.springframework.web.reactive.function.server.RouterFunction; @@ -37,7 +37,7 @@ public class RouterFunctionTests { private WebTestClient testClient; - @Before + @BeforeEach public void setUp() throws Exception { RouterFunction route = route(GET("/test"), request -> diff --git a/spring-test/src/test/java/org/springframework/test/web/reactive/server/samples/bind/WebFilterTests.java b/spring-test/src/test/java/org/springframework/test/web/reactive/server/samples/bind/WebFilterTests.java index 5bca558d88..24e760ed6c 100644 --- a/spring-test/src/test/java/org/springframework/test/web/reactive/server/samples/bind/WebFilterTests.java +++ b/spring-test/src/test/java/org/springframework/test/web/reactive/server/samples/bind/WebFilterTests.java @@ -18,7 +18,7 @@ package org.springframework.test.web.reactive.server.samples.bind; import java.nio.charset.StandardCharsets; -import org.junit.Test; +import org.junit.jupiter.api.Test; import reactor.core.publisher.Mono; import org.springframework.core.io.buffer.DataBuffer; diff --git a/spring-test/src/test/java/org/springframework/test/web/servlet/DefaultMvcResultTests.java b/spring-test/src/test/java/org/springframework/test/web/servlet/DefaultMvcResultTests.java index 67c07f6e5d..0bd0aba8c7 100644 --- a/spring-test/src/test/java/org/springframework/test/web/servlet/DefaultMvcResultTests.java +++ b/spring-test/src/test/java/org/springframework/test/web/servlet/DefaultMvcResultTests.java @@ -18,7 +18,7 @@ package org.springframework.test.web.servlet; import java.util.concurrent.CountDownLatch; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.mock.web.MockHttpServletRequest; diff --git a/spring-test/src/test/java/org/springframework/test/web/servlet/MockMvcReuseTests.java b/spring-test/src/test/java/org/springframework/test/web/servlet/MockMvcReuseTests.java index c5744f23e0..92b5cf21fd 100644 --- a/spring-test/src/test/java/org/springframework/test/web/servlet/MockMvcReuseTests.java +++ b/spring-test/src/test/java/org/springframework/test/web/servlet/MockMvcReuseTests.java @@ -16,15 +16,15 @@ package org.springframework.test.web.servlet; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.test.context.web.WebAppConfiguration; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @@ -47,7 +47,7 @@ import static org.springframework.test.web.servlet.setup.MockMvcBuilders.webAppC * @author Rob Winch * @since 4.2 */ -@RunWith(SpringJUnit4ClassRunner.class) +@ExtendWith(SpringExtension.class) @ContextConfiguration @WebAppConfiguration public class MockMvcReuseTests { @@ -63,7 +63,7 @@ public class MockMvcReuseTests { private MockMvc mvc; - @Before + @BeforeEach public void setUp() { this.mvc = webAppContextSetup(this.wac).build(); } diff --git a/spring-test/src/test/java/org/springframework/test/web/servlet/htmlunit/DelegatingWebConnectionTests.java b/spring-test/src/test/java/org/springframework/test/web/servlet/htmlunit/DelegatingWebConnectionTests.java index e069e422af..9065c304c7 100644 --- a/spring-test/src/test/java/org/springframework/test/web/servlet/htmlunit/DelegatingWebConnectionTests.java +++ b/spring-test/src/test/java/org/springframework/test/web/servlet/htmlunit/DelegatingWebConnectionTests.java @@ -26,21 +26,20 @@ import com.gargoylesoftware.htmlunit.WebConnection; import com.gargoylesoftware.htmlunit.WebRequest; import com.gargoylesoftware.htmlunit.WebResponse; import com.gargoylesoftware.htmlunit.WebResponseData; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; import org.springframework.stereotype.Controller; import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.htmlunit.DelegatingWebConnection.DelegateWebConnection; import org.springframework.test.web.servlet.setup.MockMvcBuilders; +import org.springframework.tests.Assume; import org.springframework.tests.TestGroup; -import org.springframework.tests.TestGroups; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.Assume.assumeTrue; import static org.mockito.BDDMockito.given; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyNoMoreInteractions; @@ -51,7 +50,7 @@ import static org.mockito.Mockito.verifyNoMoreInteractions; * @author Rob Winch * @since 4.2 */ -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class DelegatingWebConnectionTests { private DelegatingWebConnection webConnection; @@ -77,7 +76,7 @@ public class DelegatingWebConnectionTests { private WebConnection connection2; - @Before + @BeforeEach public void setup() throws Exception { request = new WebRequest(new URL("http://localhost/")); WebResponseData data = new WebResponseData("".getBytes("UTF-8"), 200, "", Collections.emptyList()); @@ -126,8 +125,7 @@ public class DelegatingWebConnectionTests { @Test public void verifyExampleInClassLevelJavadoc() throws Exception { - assumeTrue("TestGroup " + TestGroup.PERFORMANCE + " is not active.", - TestGroups.isGroupActive(TestGroup.PERFORMANCE)); + Assume.group(TestGroup.PERFORMANCE); WebClient webClient = new WebClient(); diff --git a/spring-test/src/test/java/org/springframework/test/web/servlet/htmlunit/HostRequestMatcherTests.java b/spring-test/src/test/java/org/springframework/test/web/servlet/htmlunit/HostRequestMatcherTests.java index 8e6ee34f40..53ce722f30 100644 --- a/spring-test/src/test/java/org/springframework/test/web/servlet/htmlunit/HostRequestMatcherTests.java +++ b/spring-test/src/test/java/org/springframework/test/web/servlet/htmlunit/HostRequestMatcherTests.java @@ -16,7 +16,7 @@ package org.springframework.test.web.servlet.htmlunit; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * Unit tests for {@link HostRequestMatcher}. diff --git a/spring-test/src/test/java/org/springframework/test/web/servlet/htmlunit/HtmlUnitRequestBuilderTests.java b/spring-test/src/test/java/org/springframework/test/web/servlet/htmlunit/HtmlUnitRequestBuilderTests.java index 4aa4ccac5c..856d1caaa6 100644 --- a/spring-test/src/test/java/org/springframework/test/web/servlet/htmlunit/HtmlUnitRequestBuilderTests.java +++ b/spring-test/src/test/java/org/springframework/test/web/servlet/htmlunit/HtmlUnitRequestBuilderTests.java @@ -35,8 +35,8 @@ import com.gargoylesoftware.htmlunit.WebRequest; import com.gargoylesoftware.htmlunit.util.NameValuePair; import org.apache.commons.io.IOUtils; import org.apache.http.auth.UsernamePasswordCredentials; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.mock.web.MockHttpServletRequest; import org.springframework.mock.web.MockHttpSession; @@ -69,7 +69,7 @@ public class HtmlUnitRequestBuilderTests { private HtmlUnitRequestBuilder requestBuilder; - @Before + @BeforeEach public void setup() throws Exception { webRequest = new WebRequest(new URL("https://example.com/test/this/here")); webRequest.setHttpMethod(HttpMethod.GET); diff --git a/spring-test/src/test/java/org/springframework/test/web/servlet/htmlunit/MockMvcConnectionBuilderSupportTests.java b/spring-test/src/test/java/org/springframework/test/web/servlet/htmlunit/MockMvcConnectionBuilderSupportTests.java index 457cc49639..e85897b678 100644 --- a/spring-test/src/test/java/org/springframework/test/web/servlet/htmlunit/MockMvcConnectionBuilderSupportTests.java +++ b/spring-test/src/test/java/org/springframework/test/web/servlet/htmlunit/MockMvcConnectionBuilderSupportTests.java @@ -24,14 +24,14 @@ import com.gargoylesoftware.htmlunit.WebClient; import com.gargoylesoftware.htmlunit.WebConnection; import com.gargoylesoftware.htmlunit.WebRequest; import com.gargoylesoftware.htmlunit.WebResponse; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Configuration; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.test.context.web.WebAppConfiguration; import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.setup.MockMvcBuilders; @@ -52,7 +52,7 @@ import static org.mockito.Mockito.mock; * @author Rossen Stoyanchev * @since 4.2 */ -@RunWith(SpringJUnit4ClassRunner.class) +@ExtendWith(SpringExtension.class) @ContextConfiguration @WebAppConfiguration @SuppressWarnings("rawtypes") @@ -66,7 +66,7 @@ public class MockMvcConnectionBuilderSupportTests { private WebApplicationContext wac; - @Before + @BeforeEach public void setup() { given(this.client.getWebConnection()).willReturn(mock(WebConnection.class)); this.builder = new MockMvcWebConnectionBuilderSupport(this.wac) {}; diff --git a/spring-test/src/test/java/org/springframework/test/web/servlet/htmlunit/MockMvcWebClientBuilderTests.java b/spring-test/src/test/java/org/springframework/test/web/servlet/htmlunit/MockMvcWebClientBuilderTests.java index 2b63efbf6a..eca06a7a75 100644 --- a/spring-test/src/test/java/org/springframework/test/web/servlet/htmlunit/MockMvcWebClientBuilderTests.java +++ b/spring-test/src/test/java/org/springframework/test/web/servlet/htmlunit/MockMvcWebClientBuilderTests.java @@ -26,14 +26,14 @@ import com.gargoylesoftware.htmlunit.WebClient; import com.gargoylesoftware.htmlunit.WebRequest; import com.gargoylesoftware.htmlunit.WebResponse; import com.gargoylesoftware.htmlunit.util.Cookie; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Configuration; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.test.context.web.WebAppConfiguration; import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.setup.MockMvcBuilders; @@ -60,7 +60,7 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException * @author Rossen Stoyanchev * @since 4.2 */ -@RunWith(SpringRunner.class) +@ExtendWith(SpringExtension.class) @ContextConfiguration @WebAppConfiguration public class MockMvcWebClientBuilderTests { @@ -71,7 +71,7 @@ public class MockMvcWebClientBuilderTests { private MockMvc mockMvc; - @Before + @BeforeEach public void setup() { this.mockMvc = MockMvcBuilders.webAppContextSetup(this.wac).build(); } diff --git a/spring-test/src/test/java/org/springframework/test/web/servlet/htmlunit/MockMvcWebConnectionTests.java b/spring-test/src/test/java/org/springframework/test/web/servlet/htmlunit/MockMvcWebConnectionTests.java index aff8add4c1..051cabaf01 100644 --- a/spring-test/src/test/java/org/springframework/test/web/servlet/htmlunit/MockMvcWebConnectionTests.java +++ b/spring-test/src/test/java/org/springframework/test/web/servlet/htmlunit/MockMvcWebConnectionTests.java @@ -21,7 +21,7 @@ import java.io.IOException; import com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException; import com.gargoylesoftware.htmlunit.Page; import com.gargoylesoftware.htmlunit.WebClient; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.setup.MockMvcBuilders; diff --git a/spring-test/src/test/java/org/springframework/test/web/servlet/htmlunit/MockWebResponseBuilderTests.java b/spring-test/src/test/java/org/springframework/test/web/servlet/htmlunit/MockWebResponseBuilderTests.java index 2519e92c9e..b6781f9ef7 100644 --- a/spring-test/src/test/java/org/springframework/test/web/servlet/htmlunit/MockWebResponseBuilderTests.java +++ b/spring-test/src/test/java/org/springframework/test/web/servlet/htmlunit/MockWebResponseBuilderTests.java @@ -24,8 +24,8 @@ import javax.servlet.http.Cookie; import com.gargoylesoftware.htmlunit.WebRequest; import com.gargoylesoftware.htmlunit.WebResponse; import com.gargoylesoftware.htmlunit.util.NameValuePair; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.mock.web.MockHttpServletResponse; @@ -48,7 +48,7 @@ public class MockWebResponseBuilderTests { private MockWebResponseBuilder responseBuilder; - @Before + @BeforeEach public void setup() throws Exception { this.webRequest = new WebRequest(new URL("http://company.example:80/test/this/here")); this.responseBuilder = new MockWebResponseBuilder(System.currentTimeMillis(), this.webRequest, this.response); diff --git a/spring-test/src/test/java/org/springframework/test/web/servlet/htmlunit/UrlRegexRequestMatcherTests.java b/spring-test/src/test/java/org/springframework/test/web/servlet/htmlunit/UrlRegexRequestMatcherTests.java index 4978ecae14..ba7e3cda66 100644 --- a/spring-test/src/test/java/org/springframework/test/web/servlet/htmlunit/UrlRegexRequestMatcherTests.java +++ b/spring-test/src/test/java/org/springframework/test/web/servlet/htmlunit/UrlRegexRequestMatcherTests.java @@ -16,7 +16,7 @@ package org.springframework.test.web.servlet.htmlunit; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * Unit tests for {@link UrlRegexRequestMatcher}. diff --git a/spring-test/src/test/java/org/springframework/test/web/servlet/htmlunit/webdriver/MockMvcHtmlUnitDriverBuilderTests.java b/spring-test/src/test/java/org/springframework/test/web/servlet/htmlunit/webdriver/MockMvcHtmlUnitDriverBuilderTests.java index 882fa4e6bd..15add530e8 100644 --- a/spring-test/src/test/java/org/springframework/test/web/servlet/htmlunit/webdriver/MockMvcHtmlUnitDriverBuilderTests.java +++ b/spring-test/src/test/java/org/springframework/test/web/servlet/htmlunit/webdriver/MockMvcHtmlUnitDriverBuilderTests.java @@ -20,16 +20,13 @@ import java.io.IOException; import javax.servlet.http.HttpServletRequest; import com.gargoylesoftware.htmlunit.util.Cookie; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.openqa.selenium.htmlunit.HtmlUnitDriver; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Configuration; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.test.context.web.WebAppConfiguration; +import org.springframework.test.context.junit.jupiter.web.SpringJUnitWebConfig; import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.setup.MockMvcBuilders; import org.springframework.tests.Assume; @@ -50,10 +47,8 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException * @author Sam Brannen * @since 4.2 */ -@RunWith(SpringRunner.class) -@ContextConfiguration -@WebAppConfiguration -public class MockMvcHtmlUnitDriverBuilderTests { +@SpringJUnitWebConfig +class MockMvcHtmlUnitDriverBuilderTests { private static final String EXPECTED_BODY = "MockMvcHtmlUnitDriverBuilderTests mvc"; @@ -65,26 +60,26 @@ public class MockMvcHtmlUnitDriverBuilderTests { private HtmlUnitDriver driver; - @Before - public void setup() { + @BeforeEach + void setup() { this.mockMvc = MockMvcBuilders.webAppContextSetup(this.wac).build(); } @Test - public void webAppContextSetupNull() { + void webAppContextSetupNull() { assertThatIllegalArgumentException().isThrownBy(() -> MockMvcHtmlUnitDriverBuilder.webAppContextSetup(null)); } @Test - public void mockMvcSetupNull() { + void mockMvcSetupNull() { assertThatIllegalArgumentException().isThrownBy(() -> MockMvcHtmlUnitDriverBuilder.mockMvcSetup(null)); } @Test - public void mockMvcSetupWithCustomDriverDelegate() throws Exception { + void mockMvcSetupWithCustomDriverDelegate() throws Exception { WebConnectionHtmlUnitDriver otherDriver = new WebConnectionHtmlUnitDriver(); this.driver = MockMvcHtmlUnitDriverBuilder.mockMvcSetup(this.mockMvc).withDelegate(otherDriver).build(); @@ -93,7 +88,7 @@ public class MockMvcHtmlUnitDriverBuilderTests { } @Test - public void mockMvcSetupWithDefaultDriverDelegate() throws Exception { + void mockMvcSetupWithDefaultDriverDelegate() throws Exception { this.driver = MockMvcHtmlUnitDriverBuilder.mockMvcSetup(this.mockMvc).build(); assertMockMvcUsed("http://localhost/test"); @@ -101,19 +96,19 @@ public class MockMvcHtmlUnitDriverBuilderTests { } @Test - public void javaScriptEnabledByDefault() { + void javaScriptEnabledByDefault() { this.driver = MockMvcHtmlUnitDriverBuilder.mockMvcSetup(this.mockMvc).build(); assertThat(this.driver.isJavascriptEnabled()).isTrue(); } @Test - public void javaScriptDisabled() { + void javaScriptDisabled() { this.driver = MockMvcHtmlUnitDriverBuilder.mockMvcSetup(this.mockMvc).javascriptEnabled(false).build(); assertThat(this.driver.isJavascriptEnabled()).isFalse(); } @Test // SPR-14066 - public void cookieManagerShared() throws Exception { + void cookieManagerShared() throws Exception { WebConnectionHtmlUnitDriver otherDriver = new WebConnectionHtmlUnitDriver(); this.mockMvc = MockMvcBuilders.standaloneSetup(new CookieController()).build(); this.driver = MockMvcHtmlUnitDriverBuilder.mockMvcSetup(this.mockMvc) diff --git a/spring-test/src/test/java/org/springframework/test/web/servlet/htmlunit/webdriver/WebConnectionHtmlUnitDriverTests.java b/spring-test/src/test/java/org/springframework/test/web/servlet/htmlunit/webdriver/WebConnectionHtmlUnitDriverTests.java index 2871991374..fbe4737624 100644 --- a/spring-test/src/test/java/org/springframework/test/web/servlet/htmlunit/webdriver/WebConnectionHtmlUnitDriverTests.java +++ b/spring-test/src/test/java/org/springframework/test/web/servlet/htmlunit/webdriver/WebConnectionHtmlUnitDriverTests.java @@ -20,11 +20,11 @@ import java.io.IOException; import com.gargoylesoftware.htmlunit.WebConnection; import com.gargoylesoftware.htmlunit.WebRequest; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoSettings; +import org.mockito.quality.Strictness; import org.openqa.selenium.WebDriverException; import static org.assertj.core.api.Assertions.assertThat; @@ -40,37 +40,35 @@ import static org.mockito.BDDMockito.given; * @author Sam Brannen * @since 4.2 */ -@RunWith(MockitoJUnitRunner.class) -public class WebConnectionHtmlUnitDriverTests { +@MockitoSettings(strictness = Strictness.LENIENT) +class WebConnectionHtmlUnitDriverTests { private final WebConnectionHtmlUnitDriver driver = new WebConnectionHtmlUnitDriver(); @Mock private WebConnection connection; - @Before - public void setup() throws Exception { + @BeforeEach + void setup() throws Exception { given(this.connection.getResponse(any(WebRequest.class))).willThrow(new IOException("")); } @Test - public void getWebConnectionDefaultNotNull() { + void getWebConnectionDefaultNotNull() { assertThat(this.driver.getWebConnection()).isNotNull(); } @Test - public void setWebConnectionToNull() { - assertThatIllegalArgumentException().isThrownBy(() -> - this.driver.setWebConnection(null)); + void setWebConnectionToNull() { + assertThatIllegalArgumentException().isThrownBy(() -> this.driver.setWebConnection(null)); } @Test public void setWebConnection() { this.driver.setWebConnection(this.connection); assertThat(this.driver.getWebConnection()).isEqualTo(this.connection); - assertThatExceptionOfType(WebDriverException.class).isThrownBy(() -> - this.driver.get("https://example.com")); + assertThatExceptionOfType(WebDriverException.class).isThrownBy(() -> this.driver.get("https://example.com")); } } diff --git a/spring-test/src/test/java/org/springframework/test/web/servlet/request/MockHttpServletRequestBuilderTests.java b/spring-test/src/test/java/org/springframework/test/web/servlet/request/MockHttpServletRequestBuilderTests.java index 384ddca574..547f03eda0 100644 --- a/spring-test/src/test/java/org/springframework/test/web/servlet/request/MockHttpServletRequestBuilderTests.java +++ b/spring-test/src/test/java/org/springframework/test/web/servlet/request/MockHttpServletRequestBuilderTests.java @@ -30,8 +30,8 @@ import java.util.Map; import javax.servlet.ServletContext; import javax.servlet.http.Cookie; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; @@ -62,7 +62,7 @@ public class MockHttpServletRequestBuilderTests { private MockHttpServletRequestBuilder builder; - @Before + @BeforeEach public void setUp() { this.builder = new MockHttpServletRequestBuilder(HttpMethod.GET, "/foo/bar"); } diff --git a/spring-test/src/test/java/org/springframework/test/web/servlet/request/MockMultipartHttpServletRequestBuilderTests.java b/spring-test/src/test/java/org/springframework/test/web/servlet/request/MockMultipartHttpServletRequestBuilderTests.java index e35a9abe20..82f039d590 100644 --- a/spring-test/src/test/java/org/springframework/test/web/servlet/request/MockMultipartHttpServletRequestBuilderTests.java +++ b/spring-test/src/test/java/org/springframework/test/web/servlet/request/MockMultipartHttpServletRequestBuilderTests.java @@ -16,7 +16,7 @@ package org.springframework.test.web.servlet.request; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.http.HttpMethod; import org.springframework.mock.web.MockHttpServletRequest; diff --git a/spring-test/src/test/java/org/springframework/test/web/servlet/result/ContentResultMatchersTests.java b/spring-test/src/test/java/org/springframework/test/web/servlet/result/ContentResultMatchersTests.java index abfb47a4eb..89cd56743d 100644 --- a/spring-test/src/test/java/org/springframework/test/web/servlet/result/ContentResultMatchersTests.java +++ b/spring-test/src/test/java/org/springframework/test/web/servlet/result/ContentResultMatchersTests.java @@ -17,7 +17,7 @@ package org.springframework.test.web.servlet.result; import org.hamcrest.Matchers; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.mock.web.MockHttpServletResponse; import org.springframework.test.web.servlet.StubMvcResult; diff --git a/spring-test/src/test/java/org/springframework/test/web/servlet/result/FlashAttributeResultMatchersTests.java b/spring-test/src/test/java/org/springframework/test/web/servlet/result/FlashAttributeResultMatchersTests.java index 5d104ace5a..4967adf7b9 100644 --- a/spring-test/src/test/java/org/springframework/test/web/servlet/result/FlashAttributeResultMatchersTests.java +++ b/spring-test/src/test/java/org/springframework/test/web/servlet/result/FlashAttributeResultMatchersTests.java @@ -16,7 +16,7 @@ package org.springframework.test.web.servlet.result; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.test.web.servlet.StubMvcResult; import org.springframework.web.servlet.FlashMap; diff --git a/spring-test/src/test/java/org/springframework/test/web/servlet/result/HeaderResultMatchersTests.java b/spring-test/src/test/java/org/springframework/test/web/servlet/result/HeaderResultMatchersTests.java index 401f9cab0c..19d79f1f4c 100644 --- a/spring-test/src/test/java/org/springframework/test/web/servlet/result/HeaderResultMatchersTests.java +++ b/spring-test/src/test/java/org/springframework/test/web/servlet/result/HeaderResultMatchersTests.java @@ -18,7 +18,7 @@ package org.springframework.test.web.servlet.result; import java.time.ZoneId; import java.time.ZonedDateTime; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.http.HttpHeaders; import org.springframework.mock.web.MockHttpServletRequest; diff --git a/spring-test/src/test/java/org/springframework/test/web/servlet/result/JsonPathResultMatchersTests.java b/spring-test/src/test/java/org/springframework/test/web/servlet/result/JsonPathResultMatchersTests.java index 05ec75dd65..787d0a7632 100644 --- a/spring-test/src/test/java/org/springframework/test/web/servlet/result/JsonPathResultMatchersTests.java +++ b/spring-test/src/test/java/org/springframework/test/web/servlet/result/JsonPathResultMatchersTests.java @@ -19,7 +19,7 @@ package org.springframework.test.web.servlet.result; import java.nio.charset.StandardCharsets; import org.hamcrest.Matchers; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.mock.web.MockHttpServletResponse; import org.springframework.test.web.servlet.StubMvcResult; diff --git a/spring-test/src/test/java/org/springframework/test/web/servlet/result/MockMvcResultMatchersTests.java b/spring-test/src/test/java/org/springframework/test/web/servlet/result/MockMvcResultMatchersTests.java index 63b73a9125..e54f033ffc 100644 --- a/spring-test/src/test/java/org/springframework/test/web/servlet/result/MockMvcResultMatchersTests.java +++ b/spring-test/src/test/java/org/springframework/test/web/servlet/result/MockMvcResultMatchersTests.java @@ -16,7 +16,7 @@ package org.springframework.test.web.servlet.result; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.mock.web.MockHttpServletResponse; import org.springframework.test.web.servlet.StubMvcResult; diff --git a/spring-test/src/test/java/org/springframework/test/web/servlet/result/ModelResultMatchersTests.java b/spring-test/src/test/java/org/springframework/test/web/servlet/result/ModelResultMatchersTests.java index 4d3f94a152..cb26910d3d 100644 --- a/spring-test/src/test/java/org/springframework/test/web/servlet/result/ModelResultMatchersTests.java +++ b/spring-test/src/test/java/org/springframework/test/web/servlet/result/ModelResultMatchersTests.java @@ -18,8 +18,8 @@ package org.springframework.test.web.servlet.result; import java.util.Date; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.test.web.servlet.MvcResult; import org.springframework.test.web.servlet.StubMvcResult; @@ -46,7 +46,7 @@ public class ModelResultMatchersTests { private MvcResult mvcResult; private MvcResult mvcResultWithError; - @Before + @BeforeEach public void setUp() throws Exception { this.matchers = new ModelResultMatchers(); diff --git a/spring-test/src/test/java/org/springframework/test/web/servlet/result/PrintingResultHandlerTests.java b/spring-test/src/test/java/org/springframework/test/web/servlet/result/PrintingResultHandlerTests.java index 996cfe6d4f..5a7abb6c55 100644 --- a/spring-test/src/test/java/org/springframework/test/web/servlet/result/PrintingResultHandlerTests.java +++ b/spring-test/src/test/java/org/springframework/test/web/servlet/result/PrintingResultHandlerTests.java @@ -24,7 +24,7 @@ import java.util.Map; import javax.servlet.http.Cookie; import javax.servlet.http.HttpSession; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.mockito.Mockito; import org.springframework.http.HttpHeaders; diff --git a/spring-test/src/test/java/org/springframework/test/web/servlet/result/StatusResultMatchersTests.java b/spring-test/src/test/java/org/springframework/test/web/servlet/result/StatusResultMatchersTests.java index 78d6787978..c3a82c1502 100644 --- a/spring-test/src/test/java/org/springframework/test/web/servlet/result/StatusResultMatchersTests.java +++ b/spring-test/src/test/java/org/springframework/test/web/servlet/result/StatusResultMatchersTests.java @@ -20,7 +20,7 @@ import java.lang.reflect.Method; import java.util.ArrayList; import java.util.List; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.core.Conventions; import org.springframework.http.HttpStatus; diff --git a/spring-test/src/test/java/org/springframework/test/web/servlet/result/XpathResultMatchersTests.java b/spring-test/src/test/java/org/springframework/test/web/servlet/result/XpathResultMatchersTests.java index 20cb7ca8bc..f62ca5e4e2 100644 --- a/spring-test/src/test/java/org/springframework/test/web/servlet/result/XpathResultMatchersTests.java +++ b/spring-test/src/test/java/org/springframework/test/web/servlet/result/XpathResultMatchersTests.java @@ -19,7 +19,7 @@ package org.springframework.test.web.servlet.result; import java.nio.charset.StandardCharsets; import org.hamcrest.Matchers; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.mock.web.MockHttpServletResponse; import org.springframework.test.web.servlet.StubMvcResult; diff --git a/spring-test/src/test/java/org/springframework/test/web/servlet/samples/context/AsyncControllerJavaConfigTests.java b/spring-test/src/test/java/org/springframework/test/web/servlet/samples/context/AsyncControllerJavaConfigTests.java index e5424deca3..8cd326a4fb 100644 --- a/spring-test/src/test/java/org/springframework/test/web/servlet/samples/context/AsyncControllerJavaConfigTests.java +++ b/spring-test/src/test/java/org/springframework/test/web/servlet/samples/context/AsyncControllerJavaConfigTests.java @@ -20,9 +20,9 @@ import java.util.Collections; import java.util.Map; import java.util.concurrent.Callable; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mockito; import org.springframework.beans.factory.annotation.Autowired; @@ -31,7 +31,7 @@ import org.springframework.context.annotation.Configuration; import org.springframework.http.MediaType; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.ContextHierarchy; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.test.context.web.WebAppConfiguration; import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.MvcResult; @@ -57,7 +57,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers. * @author Rossen Stoyanchev * @author Sam Brannen */ -@RunWith(SpringJUnit4ClassRunner.class) +@ExtendWith(SpringExtension.class) @WebAppConfiguration @ContextHierarchy(@ContextConfiguration(classes = AsyncControllerJavaConfigTests.WebConfig.class)) public class AsyncControllerJavaConfigTests { @@ -71,7 +71,7 @@ public class AsyncControllerJavaConfigTests { private MockMvc mockMvc; - @Before + @BeforeEach public void setup() { this.mockMvc = MockMvcBuilders.webAppContextSetup(this.wac).build(); } diff --git a/spring-test/src/test/java/org/springframework/test/web/servlet/samples/context/JavaConfigTests.java b/spring-test/src/test/java/org/springframework/test/web/servlet/samples/context/JavaConfigTests.java index 4fa235b97f..a96a38e5b0 100644 --- a/spring-test/src/test/java/org/springframework/test/web/servlet/samples/context/JavaConfigTests.java +++ b/spring-test/src/test/java/org/springframework/test/web/servlet/samples/context/JavaConfigTests.java @@ -18,9 +18,9 @@ package org.springframework.test.web.servlet.samples.context; import javax.servlet.ServletContext; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mockito; import org.springframework.beans.factory.annotation.Autowired; @@ -30,7 +30,7 @@ import org.springframework.context.annotation.Configuration; import org.springframework.http.MediaType; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.ContextHierarchy; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.test.context.web.WebAppConfiguration; import org.springframework.test.web.Person; import org.springframework.test.web.servlet.MockMvc; @@ -61,7 +61,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers. * @author Sam Brannen * @author Sebastien Deleuze */ -@RunWith(SpringJUnit4ClassRunner.class) +@ExtendWith(SpringExtension.class) @WebAppConfiguration("classpath:META-INF/web-resources") @ContextHierarchy({ @ContextConfiguration(classes = RootConfig.class), @@ -81,7 +81,7 @@ public class JavaConfigTests { private MockMvc mockMvc; - @Before + @BeforeEach public void setup() { this.mockMvc = MockMvcBuilders.webAppContextSetup(this.wac).build(); verifyRootWacSupport(); diff --git a/spring-test/src/test/java/org/springframework/test/web/servlet/samples/context/WebAppResourceTests.java b/spring-test/src/test/java/org/springframework/test/web/servlet/samples/context/WebAppResourceTests.java index e5edf3d275..57c3b1737a 100644 --- a/spring-test/src/test/java/org/springframework/test/web/servlet/samples/context/WebAppResourceTests.java +++ b/spring-test/src/test/java/org/springframework/test/web/servlet/samples/context/WebAppResourceTests.java @@ -16,14 +16,14 @@ package org.springframework.test.web.servlet.samples.context; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.ContextHierarchy; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.test.context.web.WebAppConfiguration; import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.setup.MockMvcBuilders; @@ -42,7 +42,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers. * * @author Rossen Stoyanchev */ -@RunWith(SpringJUnit4ClassRunner.class) +@ExtendWith(SpringExtension.class) @WebAppConfiguration("src/test/resources/META-INF/web-resources") @ContextHierarchy({ @ContextConfiguration("root-context.xml"), @@ -55,7 +55,7 @@ public class WebAppResourceTests { private MockMvc mockMvc; - @Before + @BeforeEach public void setup() { this.mockMvc = MockMvcBuilders.webAppContextSetup(this.wac).alwaysExpect(status().isOk()).build(); } diff --git a/spring-test/src/test/java/org/springframework/test/web/servlet/samples/context/XmlConfigTests.java b/spring-test/src/test/java/org/springframework/test/web/servlet/samples/context/XmlConfigTests.java index b155dfc613..783aead747 100644 --- a/spring-test/src/test/java/org/springframework/test/web/servlet/samples/context/XmlConfigTests.java +++ b/spring-test/src/test/java/org/springframework/test/web/servlet/samples/context/XmlConfigTests.java @@ -16,15 +16,15 @@ package org.springframework.test.web.servlet.samples.context; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.MediaType; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.ContextHierarchy; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.test.context.web.WebAppConfiguration; import org.springframework.test.web.Person; import org.springframework.test.web.servlet.MockMvc; @@ -44,7 +44,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers. * @author Rossen Stoyanchev * @author Sam Brannen */ -@RunWith(SpringJUnit4ClassRunner.class) +@ExtendWith(SpringExtension.class) @WebAppConfiguration("src/test/resources/META-INF/web-resources") @ContextHierarchy({ @ContextConfiguration("root-context.xml"), @@ -61,7 +61,7 @@ public class XmlConfigTests { private MockMvc mockMvc; - @Before + @BeforeEach public void setup() { this.mockMvc = MockMvcBuilders.webAppContextSetup(this.wac).build(); given(this.personDao.getPerson(5L)).willReturn(new Person("Joe")); diff --git a/spring-test/src/test/java/org/springframework/test/web/servlet/samples/spr/CustomRequestAttributesRequestContextHolderTests.java b/spring-test/src/test/java/org/springframework/test/web/servlet/samples/spr/CustomRequestAttributesRequestContextHolderTests.java index 2f27ee4aa9..acf3202550 100644 --- a/spring-test/src/test/java/org/springframework/test/web/servlet/samples/spr/CustomRequestAttributesRequestContextHolderTests.java +++ b/spring-test/src/test/java/org/springframework/test/web/servlet/samples/spr/CustomRequestAttributesRequestContextHolderTests.java @@ -20,9 +20,9 @@ import javax.servlet.ServletContext; import javax.servlet.ServletRequest; import javax.servlet.http.HttpServletRequest; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.context.annotation.AnnotatedBeanDefinitionReader; import org.springframework.context.annotation.Bean; @@ -65,7 +65,7 @@ public class CustomRequestAttributesRequestContextHolderTests { private MockMvc mockMvc; - @Before + @BeforeEach public void setUp() { ServletContext servletContext = new MockServletContext(); MockHttpServletRequest mockRequest = new MockHttpServletRequest(servletContext); @@ -87,7 +87,7 @@ public class CustomRequestAttributesRequestContextHolderTests { this.mockMvc.perform(get("/singletonController").requestAttr(FROM_MVC_TEST_MOCK, FROM_MVC_TEST_MOCK)); } - @After + @AfterEach public void verifyCustomRequestAttributesAreRestored() { RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes(); assertThat(requestAttributes).isInstanceOf(ServletRequestAttributes.class); diff --git a/spring-test/src/test/java/org/springframework/test/web/servlet/samples/spr/EncodedUriTests.java b/spring-test/src/test/java/org/springframework/test/web/servlet/samples/spr/EncodedUriTests.java index d6ad9b4d6c..431e051133 100644 --- a/spring-test/src/test/java/org/springframework/test/web/servlet/samples/spr/EncodedUriTests.java +++ b/spring-test/src/test/java/org/springframework/test/web/servlet/samples/spr/EncodedUriTests.java @@ -19,9 +19,9 @@ package org.springframework.test.web.servlet.samples.spr; import java.net.URI; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.BeansException; import org.springframework.beans.factory.annotation.Autowired; @@ -32,7 +32,7 @@ import org.springframework.core.PriorityOrdered; import org.springframework.stereotype.Component; import org.springframework.stereotype.Controller; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.test.context.web.WebAppConfiguration; import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.ResultActions; @@ -58,7 +58,7 @@ import static org.springframework.test.web.servlet.setup.MockMvcBuilders.webAppC * * @author Sebastien Deleuze */ -@RunWith(SpringJUnit4ClassRunner.class) +@ExtendWith(SpringExtension.class) @WebAppConfiguration @ContextConfiguration public class EncodedUriTests { @@ -68,7 +68,7 @@ public class EncodedUriTests { private MockMvc mockMvc; - @Before + @BeforeEach public void setup() { this.mockMvc = webAppContextSetup(this.wac).build(); } diff --git a/spring-test/src/test/java/org/springframework/test/web/servlet/samples/spr/FormContentTests.java b/spring-test/src/test/java/org/springframework/test/web/servlet/samples/spr/FormContentTests.java index a294d32713..add9394203 100644 --- a/spring-test/src/test/java/org/springframework/test/web/servlet/samples/spr/FormContentTests.java +++ b/spring-test/src/test/java/org/springframework/test/web/servlet/samples/spr/FormContentTests.java @@ -16,7 +16,7 @@ package org.springframework.test.web.servlet.samples.spr; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.http.MediaType; import org.springframework.test.web.servlet.MockMvc; diff --git a/spring-test/src/test/java/org/springframework/test/web/servlet/samples/spr/HttpOptionsTests.java b/spring-test/src/test/java/org/springframework/test/web/servlet/samples/spr/HttpOptionsTests.java index 719362fd0a..37bb180dbb 100644 --- a/spring-test/src/test/java/org/springframework/test/web/servlet/samples/spr/HttpOptionsTests.java +++ b/spring-test/src/test/java/org/springframework/test/web/servlet/samples/spr/HttpOptionsTests.java @@ -18,16 +18,16 @@ package org.springframework.test.web.servlet.samples.spr; import java.util.concurrent.atomic.AtomicInteger; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.stereotype.Controller; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.test.context.web.WebAppConfiguration; import org.springframework.test.web.servlet.MockMvc; import org.springframework.web.bind.annotation.RequestMapping; @@ -47,7 +47,7 @@ import static org.springframework.test.web.servlet.setup.MockMvcBuilders.webAppC * * @author Arnaud Cogoluègnes */ -@RunWith(SpringJUnit4ClassRunner.class) +@ExtendWith(SpringExtension.class) @WebAppConfiguration @ContextConfiguration public class HttpOptionsTests { @@ -58,7 +58,7 @@ public class HttpOptionsTests { private MockMvc mockMvc; - @Before + @BeforeEach public void setup() { this.mockMvc = webAppContextSetup(this.wac).dispatchOptions(true).build(); } diff --git a/spring-test/src/test/java/org/springframework/test/web/servlet/samples/spr/MockMvcBuilderMethodChainTests.java b/spring-test/src/test/java/org/springframework/test/web/servlet/samples/spr/MockMvcBuilderMethodChainTests.java index f89be8a9eb..6d4fc912c7 100644 --- a/spring-test/src/test/java/org/springframework/test/web/servlet/samples/spr/MockMvcBuilderMethodChainTests.java +++ b/spring-test/src/test/java/org/springframework/test/web/servlet/samples/spr/MockMvcBuilderMethodChainTests.java @@ -16,13 +16,13 @@ package org.springframework.test.web.servlet.samples.spr; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Configuration; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.test.context.web.WebAppConfiguration; import org.springframework.test.web.servlet.setup.MockMvcBuilders; import org.springframework.web.context.WebApplicationContext; @@ -37,7 +37,7 @@ import static org.springframework.test.web.servlet.request.MockMvcRequestBuilder * * @author Wesley Hall */ -@RunWith(SpringJUnit4ClassRunner.class) +@ExtendWith(SpringExtension.class) @WebAppConfiguration @ContextConfiguration public class MockMvcBuilderMethodChainTests { diff --git a/spring-test/src/test/java/org/springframework/test/web/servlet/samples/spr/RequestContextHolderTests.java b/spring-test/src/test/java/org/springframework/test/web/servlet/samples/spr/RequestContextHolderTests.java index 031bbad4e5..db31fb8d77 100644 --- a/spring-test/src/test/java/org/springframework/test/web/servlet/samples/spr/RequestContextHolderTests.java +++ b/spring-test/src/test/java/org/springframework/test/web/servlet/samples/spr/RequestContextHolderTests.java @@ -22,10 +22,10 @@ import javax.servlet.ServletException; import javax.servlet.ServletRequest; import javax.servlet.ServletResponse; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.aop.support.AopUtils; import org.springframework.beans.factory.annotation.Autowired; @@ -36,7 +36,7 @@ import org.springframework.context.annotation.ScopedProxyMode; import org.springframework.mock.web.MockHttpServletRequest; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.test.context.web.WebAppConfiguration; import org.springframework.test.web.servlet.MockMvc; import org.springframework.web.bind.annotation.RequestMapping; @@ -68,7 +68,7 @@ import static org.springframework.test.web.servlet.setup.MockMvcBuilders.webAppC * @author Sam Brannen * @see CustomRequestAttributesRequestContextHolderTests */ -@RunWith(SpringRunner.class) +@ExtendWith(SpringExtension.class) @WebAppConfiguration @ContextConfiguration @DirtiesContext @@ -101,7 +101,7 @@ public class RequestContextHolderTests { private MockMvc mockMvc; - @Before + @BeforeEach public void setup() { this.mockRequest.setAttribute(FROM_TCF_MOCK, FROM_TCF_MOCK); @@ -135,7 +135,7 @@ public class RequestContextHolderTests { this.mockMvc.perform(get("/sessionScopedService").requestAttr(FROM_MVC_TEST_MOCK, FROM_MVC_TEST_MOCK)); } - @After + @AfterEach public void verifyRestoredRequestAttributes() { assertRequestAttributes(false); } diff --git a/spring-test/src/test/java/org/springframework/test/web/servlet/samples/standalone/AsyncTests.java b/spring-test/src/test/java/org/springframework/test/web/servlet/samples/standalone/AsyncTests.java index 0ae30662e7..f1f78a7ad7 100644 --- a/spring-test/src/test/java/org/springframework/test/web/servlet/samples/standalone/AsyncTests.java +++ b/spring-test/src/test/java/org/springframework/test/web/servlet/samples/standalone/AsyncTests.java @@ -23,7 +23,7 @@ import java.util.concurrent.Callable; import java.util.concurrent.CompletableFuture; import java.util.concurrent.CopyOnWriteArrayList; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; diff --git a/spring-test/src/test/java/org/springframework/test/web/servlet/samples/standalone/ExceptionHandlerTests.java b/spring-test/src/test/java/org/springframework/test/web/servlet/samples/standalone/ExceptionHandlerTests.java index aef7c9e07e..993ff76504 100644 --- a/spring-test/src/test/java/org/springframework/test/web/servlet/samples/standalone/ExceptionHandlerTests.java +++ b/spring-test/src/test/java/org/springframework/test/web/servlet/samples/standalone/ExceptionHandlerTests.java @@ -16,7 +16,7 @@ package org.springframework.test.web.servlet.samples.standalone; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.ControllerAdvice; diff --git a/spring-test/src/test/java/org/springframework/test/web/servlet/samples/standalone/FilterTests.java b/spring-test/src/test/java/org/springframework/test/web/servlet/samples/standalone/FilterTests.java index 0788b63637..7e6d492064 100644 --- a/spring-test/src/test/java/org/springframework/test/web/servlet/samples/standalone/FilterTests.java +++ b/spring-test/src/test/java/org/springframework/test/web/servlet/samples/standalone/FilterTests.java @@ -33,7 +33,7 @@ import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponseWrapper; import javax.validation.Valid; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.http.MediaType; import org.springframework.stereotype.Controller; diff --git a/spring-test/src/test/java/org/springframework/test/web/servlet/samples/standalone/FrameworkExtensionTests.java b/spring-test/src/test/java/org/springframework/test/web/servlet/samples/standalone/FrameworkExtensionTests.java index 12f2013ed8..a18759bba8 100644 --- a/spring-test/src/test/java/org/springframework/test/web/servlet/samples/standalone/FrameworkExtensionTests.java +++ b/spring-test/src/test/java/org/springframework/test/web/servlet/samples/standalone/FrameworkExtensionTests.java @@ -18,8 +18,8 @@ package org.springframework.test.web.servlet.samples.standalone; import java.security.Principal; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.http.HttpHeaders; import org.springframework.mock.web.MockHttpServletRequest; @@ -56,7 +56,7 @@ public class FrameworkExtensionTests { private MockMvc mockMvc; - @Before + @BeforeEach public void setup() { this.mockMvc = standaloneSetup(new SampleController()).apply(defaultSetup()).build(); } diff --git a/spring-test/src/test/java/org/springframework/test/web/servlet/samples/standalone/MultipartControllerTests.java b/spring-test/src/test/java/org/springframework/test/web/servlet/samples/standalone/MultipartControllerTests.java index afbe3276cd..2ec02d9eaa 100644 --- a/spring-test/src/test/java/org/springframework/test/web/servlet/samples/standalone/MultipartControllerTests.java +++ b/spring-test/src/test/java/org/springframework/test/web/servlet/samples/standalone/MultipartControllerTests.java @@ -30,7 +30,7 @@ import javax.servlet.http.HttpServletRequestWrapper; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.Part; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.http.MediaType; import org.springframework.mock.web.MockMultipartFile; diff --git a/spring-test/src/test/java/org/springframework/test/web/servlet/samples/standalone/ReactiveReturnTypeTests.java b/spring-test/src/test/java/org/springframework/test/web/servlet/samples/standalone/ReactiveReturnTypeTests.java index 8642e552a3..12d72f1a2e 100644 --- a/spring-test/src/test/java/org/springframework/test/web/servlet/samples/standalone/ReactiveReturnTypeTests.java +++ b/spring-test/src/test/java/org/springframework/test/web/servlet/samples/standalone/ReactiveReturnTypeTests.java @@ -17,7 +17,7 @@ package org.springframework.test.web.servlet.samples.standalone; import java.time.Duration; -import org.junit.Test; +import org.junit.jupiter.api.Test; import reactor.core.publisher.Flux; import org.springframework.http.MediaType; diff --git a/spring-test/src/test/java/org/springframework/test/web/servlet/samples/standalone/RedirectTests.java b/spring-test/src/test/java/org/springframework/test/web/servlet/samples/standalone/RedirectTests.java index e69aa6502e..0981973439 100644 --- a/spring-test/src/test/java/org/springframework/test/web/servlet/samples/standalone/RedirectTests.java +++ b/spring-test/src/test/java/org/springframework/test/web/servlet/samples/standalone/RedirectTests.java @@ -18,8 +18,8 @@ package org.springframework.test.web.servlet.samples.standalone; import javax.validation.Valid; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.stereotype.Controller; import org.springframework.test.web.Person; @@ -51,7 +51,7 @@ public class RedirectTests { private MockMvc mockMvc; - @Before + @BeforeEach public void setup() { this.mockMvc = standaloneSetup(new PersonController()).build(); } diff --git a/spring-test/src/test/java/org/springframework/test/web/servlet/samples/standalone/RequestParameterTests.java b/spring-test/src/test/java/org/springframework/test/web/servlet/samples/standalone/RequestParameterTests.java index e023714cc1..ff67744cc3 100644 --- a/spring-test/src/test/java/org/springframework/test/web/servlet/samples/standalone/RequestParameterTests.java +++ b/spring-test/src/test/java/org/springframework/test/web/servlet/samples/standalone/RequestParameterTests.java @@ -15,7 +15,7 @@ */ package org.springframework.test.web.servlet.samples.standalone; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.http.MediaType; import org.springframework.stereotype.Controller; diff --git a/spring-test/src/test/java/org/springframework/test/web/servlet/samples/standalone/ResponseBodyTests.java b/spring-test/src/test/java/org/springframework/test/web/servlet/samples/standalone/ResponseBodyTests.java index 9846ea79ca..5dabd07ab5 100644 --- a/spring-test/src/test/java/org/springframework/test/web/servlet/samples/standalone/ResponseBodyTests.java +++ b/spring-test/src/test/java/org/springframework/test/web/servlet/samples/standalone/ResponseBodyTests.java @@ -18,7 +18,7 @@ package org.springframework.test.web.servlet.samples.standalone; import javax.validation.constraints.NotNull; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.http.MediaType; import org.springframework.web.bind.annotation.GetMapping; diff --git a/spring-test/src/test/java/org/springframework/test/web/servlet/samples/standalone/ViewResolutionTests.java b/spring-test/src/test/java/org/springframework/test/web/servlet/samples/standalone/ViewResolutionTests.java index 18994ee54e..91ea1a52b9 100644 --- a/spring-test/src/test/java/org/springframework/test/web/servlet/samples/standalone/ViewResolutionTests.java +++ b/spring-test/src/test/java/org/springframework/test/web/servlet/samples/standalone/ViewResolutionTests.java @@ -19,7 +19,7 @@ package org.springframework.test.web.servlet.samples.standalone; import java.util.ArrayList; import java.util.List; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.http.MediaType; import org.springframework.oxm.jaxb.Jaxb2Marshaller; diff --git a/spring-test/src/test/java/org/springframework/test/web/servlet/samples/standalone/resulthandlers/PrintingResultHandlerSmokeTests.java b/spring-test/src/test/java/org/springframework/test/web/servlet/samples/standalone/resulthandlers/PrintingResultHandlerSmokeTests.java index 9c68a95ffb..c8874dbbf3 100644 --- a/spring-test/src/test/java/org/springframework/test/web/servlet/samples/standalone/resulthandlers/PrintingResultHandlerSmokeTests.java +++ b/spring-test/src/test/java/org/springframework/test/web/servlet/samples/standalone/resulthandlers/PrintingResultHandlerSmokeTests.java @@ -20,8 +20,8 @@ import java.io.StringWriter; import javax.servlet.http.Cookie; import javax.servlet.http.HttpServletResponse; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import org.springframework.stereotype.Controller; import org.springframework.test.web.servlet.result.PrintingResultHandler; @@ -40,14 +40,14 @@ import static org.springframework.test.web.servlet.setup.MockMvcBuilders.standal * various output streams. * *

NOTE: this smoke test is not intended to be - * executed with the build. To run this test, comment out the {@code @Ignore} + * executed with the build. To run this test, comment out the {@code @Disabled} * declaration and inspect the output manually. * * @author Rossen Stoyanchev * @author Sam Brannen * @see org.springframework.test.web.servlet.result.PrintingResultHandlerTests */ -@Ignore("Not intended to be executed with the build. Comment out this line to inspect the output manually.") +@Disabled("Not intended to be executed with the build. Comment out this line to inspect the output manually.") public class PrintingResultHandlerSmokeTests { @Test diff --git a/spring-test/src/test/java/org/springframework/test/web/servlet/samples/standalone/resultmatchers/ContentAssertionTests.java b/spring-test/src/test/java/org/springframework/test/web/servlet/samples/standalone/resultmatchers/ContentAssertionTests.java index 34b4c3b7b5..65d0ede06c 100644 --- a/spring-test/src/test/java/org/springframework/test/web/servlet/samples/standalone/resultmatchers/ContentAssertionTests.java +++ b/spring-test/src/test/java/org/springframework/test/web/servlet/samples/standalone/resultmatchers/ContentAssertionTests.java @@ -16,8 +16,8 @@ package org.springframework.test.web.servlet.samples.standalone.resultmatchers; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.http.MediaType; import org.springframework.stereotype.Controller; @@ -46,7 +46,7 @@ public class ContentAssertionTests { private MockMvc mockMvc; - @Before + @BeforeEach public void setup() { this.mockMvc = standaloneSetup(new SimpleController()).alwaysExpect(status().isOk()).build(); } diff --git a/spring-test/src/test/java/org/springframework/test/web/servlet/samples/standalone/resultmatchers/CookieAssertionTests.java b/spring-test/src/test/java/org/springframework/test/web/servlet/samples/standalone/resultmatchers/CookieAssertionTests.java index 16a8aacda2..901126a62c 100644 --- a/spring-test/src/test/java/org/springframework/test/web/servlet/samples/standalone/resultmatchers/CookieAssertionTests.java +++ b/spring-test/src/test/java/org/springframework/test/web/servlet/samples/standalone/resultmatchers/CookieAssertionTests.java @@ -16,8 +16,8 @@ package org.springframework.test.web.servlet.samples.standalone.resultmatchers; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.stereotype.Controller; import org.springframework.test.web.servlet.MockMvc; @@ -45,7 +45,7 @@ public class CookieAssertionTests { private MockMvc mockMvc; - @Before + @BeforeEach public void setup() { CookieLocaleResolver localeResolver = new CookieLocaleResolver(); localeResolver.setCookieDomain("domain"); diff --git a/spring-test/src/test/java/org/springframework/test/web/servlet/samples/standalone/resultmatchers/FlashAttributeAssertionTests.java b/spring-test/src/test/java/org/springframework/test/web/servlet/samples/standalone/resultmatchers/FlashAttributeAssertionTests.java index dcae3721ee..8a439e87ff 100644 --- a/spring-test/src/test/java/org/springframework/test/web/servlet/samples/standalone/resultmatchers/FlashAttributeAssertionTests.java +++ b/spring-test/src/test/java/org/springframework/test/web/servlet/samples/standalone/resultmatchers/FlashAttributeAssertionTests.java @@ -18,8 +18,8 @@ package org.springframework.test.web.servlet.samples.standalone.resultmatchers; import java.net.URL; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.stereotype.Controller; import org.springframework.test.web.servlet.MockMvc; @@ -46,7 +46,7 @@ public class FlashAttributeAssertionTests { private MockMvc mockMvc; - @Before + @BeforeEach public void setup() { this.mockMvc = standaloneSetup(new PersonController()) .alwaysExpect(status().isFound()) diff --git a/spring-test/src/test/java/org/springframework/test/web/servlet/samples/standalone/resultmatchers/HandlerAssertionTests.java b/spring-test/src/test/java/org/springframework/test/web/servlet/samples/standalone/resultmatchers/HandlerAssertionTests.java index bf5dd387eb..e7eb1f5bdf 100644 --- a/spring-test/src/test/java/org/springframework/test/web/servlet/samples/standalone/resultmatchers/HandlerAssertionTests.java +++ b/spring-test/src/test/java/org/springframework/test/web/servlet/samples/standalone/resultmatchers/HandlerAssertionTests.java @@ -18,7 +18,7 @@ package org.springframework.test.web.servlet.samples.standalone.resultmatchers; import java.lang.reflect.Method; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.http.ResponseEntity; import org.springframework.test.web.servlet.MockMvc; diff --git a/spring-test/src/test/java/org/springframework/test/web/servlet/samples/standalone/resultmatchers/HeaderAssertionTests.java b/spring-test/src/test/java/org/springframework/test/web/servlet/samples/standalone/resultmatchers/HeaderAssertionTests.java index 1869336592..4bc351d95c 100644 --- a/spring-test/src/test/java/org/springframework/test/web/servlet/samples/standalone/resultmatchers/HeaderAssertionTests.java +++ b/spring-test/src/test/java/org/springframework/test/web/servlet/samples/standalone/resultmatchers/HeaderAssertionTests.java @@ -21,8 +21,8 @@ import java.util.Date; import java.util.Locale; import java.util.TimeZone; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.http.HttpHeaders; import org.springframework.http.ResponseEntity; @@ -73,7 +73,7 @@ public class HeaderAssertionTests { private SimpleDateFormat dateFormat; - @Before + @BeforeEach public void setup() { this.dateFormat = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz", Locale.US); this.dateFormat.setTimeZone(TimeZone.getTimeZone("GMT")); diff --git a/spring-test/src/test/java/org/springframework/test/web/servlet/samples/standalone/resultmatchers/JsonPathAssertionTests.java b/spring-test/src/test/java/org/springframework/test/web/servlet/samples/standalone/resultmatchers/JsonPathAssertionTests.java index d4875bd06c..42d1ba5eb5 100644 --- a/spring-test/src/test/java/org/springframework/test/web/servlet/samples/standalone/resultmatchers/JsonPathAssertionTests.java +++ b/spring-test/src/test/java/org/springframework/test/web/servlet/samples/standalone/resultmatchers/JsonPathAssertionTests.java @@ -18,8 +18,8 @@ package org.springframework.test.web.servlet.samples.standalone.resultmatchers; import java.util.Arrays; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.http.MediaType; import org.springframework.test.web.Person; @@ -52,7 +52,7 @@ public class JsonPathAssertionTests { private MockMvc mockMvc; - @Before + @BeforeEach public void setup() { this.mockMvc = standaloneSetup(new MusicController()) .defaultRequest(get("/").accept(MediaType.APPLICATION_JSON)) diff --git a/spring-test/src/test/java/org/springframework/test/web/servlet/samples/standalone/resultmatchers/ModelAssertionTests.java b/spring-test/src/test/java/org/springframework/test/web/servlet/samples/standalone/resultmatchers/ModelAssertionTests.java index f97a5dcfe5..49e86bb308 100644 --- a/spring-test/src/test/java/org/springframework/test/web/servlet/samples/standalone/resultmatchers/ModelAssertionTests.java +++ b/spring-test/src/test/java/org/springframework/test/web/servlet/samples/standalone/resultmatchers/ModelAssertionTests.java @@ -18,8 +18,8 @@ package org.springframework.test.web.servlet.samples.standalone.resultmatchers; import javax.validation.Valid; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.stereotype.Controller; import org.springframework.test.web.Person; @@ -54,7 +54,7 @@ public class ModelAssertionTests { private MockMvc mockMvc; - @Before + @BeforeEach public void setup() { SampleController controller = new SampleController("a string value", 3, new Person("a name")); diff --git a/spring-test/src/test/java/org/springframework/test/web/servlet/samples/standalone/resultmatchers/RequestAttributeAssertionTests.java b/spring-test/src/test/java/org/springframework/test/web/servlet/samples/standalone/resultmatchers/RequestAttributeAssertionTests.java index 896930bc0b..562af455fa 100644 --- a/spring-test/src/test/java/org/springframework/test/web/servlet/samples/standalone/resultmatchers/RequestAttributeAssertionTests.java +++ b/spring-test/src/test/java/org/springframework/test/web/servlet/samples/standalone/resultmatchers/RequestAttributeAssertionTests.java @@ -16,8 +16,8 @@ package org.springframework.test.web.servlet.samples.standalone.resultmatchers; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.http.MediaType; import org.springframework.stereotype.Controller; @@ -41,7 +41,7 @@ public class RequestAttributeAssertionTests { private MockMvc mockMvc; - @Before + @BeforeEach public void setup() { this.mockMvc = standaloneSetup(new SimpleController()).build(); } diff --git a/spring-test/src/test/java/org/springframework/test/web/servlet/samples/standalone/resultmatchers/SessionAttributeAssertionTests.java b/spring-test/src/test/java/org/springframework/test/web/servlet/samples/standalone/resultmatchers/SessionAttributeAssertionTests.java index 0669fca654..c1280c4d98 100644 --- a/spring-test/src/test/java/org/springframework/test/web/servlet/samples/standalone/resultmatchers/SessionAttributeAssertionTests.java +++ b/spring-test/src/test/java/org/springframework/test/web/servlet/samples/standalone/resultmatchers/SessionAttributeAssertionTests.java @@ -18,8 +18,8 @@ package org.springframework.test.web.servlet.samples.standalone.resultmatchers; import java.util.Locale; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.stereotype.Controller; import org.springframework.test.web.servlet.MockMvc; @@ -44,7 +44,7 @@ public class SessionAttributeAssertionTests { private MockMvc mockMvc; - @Before + @BeforeEach public void setup() { this.mockMvc = standaloneSetup(new SimpleController()) .defaultRequest(get("/")) diff --git a/spring-test/src/test/java/org/springframework/test/web/servlet/samples/standalone/resultmatchers/StatusAssertionTests.java b/spring-test/src/test/java/org/springframework/test/web/servlet/samples/standalone/resultmatchers/StatusAssertionTests.java index aef6398668..882621bc44 100644 --- a/spring-test/src/test/java/org/springframework/test/web/servlet/samples/standalone/resultmatchers/StatusAssertionTests.java +++ b/spring-test/src/test/java/org/springframework/test/web/servlet/samples/standalone/resultmatchers/StatusAssertionTests.java @@ -19,7 +19,7 @@ package org.springframework.test.web.servlet.samples.standalone.resultmatchers; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.core.annotation.AliasFor; import org.springframework.http.HttpStatus; diff --git a/spring-test/src/test/java/org/springframework/test/web/servlet/samples/standalone/resultmatchers/UrlAssertionTests.java b/spring-test/src/test/java/org/springframework/test/web/servlet/samples/standalone/resultmatchers/UrlAssertionTests.java index a43a784ea5..9d3f46fca1 100644 --- a/spring-test/src/test/java/org/springframework/test/web/servlet/samples/standalone/resultmatchers/UrlAssertionTests.java +++ b/spring-test/src/test/java/org/springframework/test/web/servlet/samples/standalone/resultmatchers/UrlAssertionTests.java @@ -16,8 +16,8 @@ package org.springframework.test.web.servlet.samples.standalone.resultmatchers; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.stereotype.Controller; import org.springframework.test.web.servlet.MockMvc; @@ -39,7 +39,7 @@ public class UrlAssertionTests { private MockMvc mockMvc; - @Before + @BeforeEach public void setup() { this.mockMvc = standaloneSetup(new SimpleController()).build(); } diff --git a/spring-test/src/test/java/org/springframework/test/web/servlet/samples/standalone/resultmatchers/ViewNameAssertionTests.java b/spring-test/src/test/java/org/springframework/test/web/servlet/samples/standalone/resultmatchers/ViewNameAssertionTests.java index 0dce557397..b2f809077d 100644 --- a/spring-test/src/test/java/org/springframework/test/web/servlet/samples/standalone/resultmatchers/ViewNameAssertionTests.java +++ b/spring-test/src/test/java/org/springframework/test/web/servlet/samples/standalone/resultmatchers/ViewNameAssertionTests.java @@ -16,8 +16,8 @@ package org.springframework.test.web.servlet.samples.standalone.resultmatchers; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.stereotype.Controller; import org.springframework.test.web.servlet.MockMvc; @@ -39,7 +39,7 @@ public class ViewNameAssertionTests { private MockMvc mockMvc; - @Before + @BeforeEach public void setup() { this.mockMvc = standaloneSetup(new SimpleController()) .alwaysExpect(status().isOk()) diff --git a/spring-test/src/test/java/org/springframework/test/web/servlet/samples/standalone/resultmatchers/XmlContentAssertionTests.java b/spring-test/src/test/java/org/springframework/test/web/servlet/samples/standalone/resultmatchers/XmlContentAssertionTests.java index d6432436f9..f00aeef944 100644 --- a/spring-test/src/test/java/org/springframework/test/web/servlet/samples/standalone/resultmatchers/XmlContentAssertionTests.java +++ b/spring-test/src/test/java/org/springframework/test/web/servlet/samples/standalone/resultmatchers/XmlContentAssertionTests.java @@ -24,8 +24,8 @@ import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlElementWrapper; import javax.xml.bind.annotation.XmlRootElement; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.http.MediaType; import org.springframework.stereotype.Controller; @@ -62,7 +62,7 @@ public class XmlContentAssertionTests { private MockMvc mockMvc; - @Before + @BeforeEach public void setup() { this.mockMvc = standaloneSetup(new MusicController()) .defaultRequest(get("/").accept(MediaType.APPLICATION_XML, MediaType.parseMediaType("application/xml;charset=UTF-8"))) diff --git a/spring-test/src/test/java/org/springframework/test/web/servlet/samples/standalone/resultmatchers/XpathAssertionTests.java b/spring-test/src/test/java/org/springframework/test/web/servlet/samples/standalone/resultmatchers/XpathAssertionTests.java index 785c8207c9..0c71d3066d 100644 --- a/spring-test/src/test/java/org/springframework/test/web/servlet/samples/standalone/resultmatchers/XpathAssertionTests.java +++ b/spring-test/src/test/java/org/springframework/test/web/servlet/samples/standalone/resultmatchers/XpathAssertionTests.java @@ -26,8 +26,8 @@ import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlElementWrapper; import javax.xml.bind.annotation.XmlRootElement; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.http.MediaType; import org.springframework.stereotype.Controller; @@ -64,7 +64,7 @@ public class XpathAssertionTests { private MockMvc mockMvc; - @Before + @BeforeEach public void setup() throws Exception { this.mockMvc = standaloneSetup(new MusicController()) .defaultRequest(get("/").accept(MediaType.APPLICATION_XML, MediaType.parseMediaType("application/xml;charset=UTF-8"))) diff --git a/spring-test/src/test/java/org/springframework/test/web/servlet/setup/ConditionalDelegatingFilterProxyTests.java b/spring-test/src/test/java/org/springframework/test/web/servlet/setup/ConditionalDelegatingFilterProxyTests.java index 3f960bc3cb..9fbc3c9456 100644 --- a/spring-test/src/test/java/org/springframework/test/web/servlet/setup/ConditionalDelegatingFilterProxyTests.java +++ b/spring-test/src/test/java/org/springframework/test/web/servlet/setup/ConditionalDelegatingFilterProxyTests.java @@ -23,8 +23,8 @@ import javax.servlet.ServletException; import javax.servlet.ServletRequest; import javax.servlet.ServletResponse; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.mock.web.MockFilterChain; import org.springframework.mock.web.MockFilterConfig; @@ -52,7 +52,7 @@ public class ConditionalDelegatingFilterProxyTests { private PatternMappingFilterProxy filter; - @Before + @BeforeEach public void setup() { request = new MockHttpServletRequest(); request.setContextPath("/context"); diff --git a/spring-test/src/test/java/org/springframework/test/web/servlet/setup/DefaultMockMvcBuilderTests.java b/spring-test/src/test/java/org/springframework/test/web/servlet/setup/DefaultMockMvcBuilderTests.java index 8054d0bc63..c6eff77faa 100644 --- a/spring-test/src/test/java/org/springframework/test/web/servlet/setup/DefaultMockMvcBuilderTests.java +++ b/spring-test/src/test/java/org/springframework/test/web/servlet/setup/DefaultMockMvcBuilderTests.java @@ -16,7 +16,7 @@ package org.springframework.test.web.servlet.setup; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.beans.DirectFieldAccessor; import org.springframework.context.support.StaticApplicationContext; diff --git a/spring-test/src/test/java/org/springframework/test/web/servlet/setup/SharedHttpSessionTests.java b/spring-test/src/test/java/org/springframework/test/web/servlet/setup/SharedHttpSessionTests.java index 0ea868a87f..31f308cff6 100644 --- a/spring-test/src/test/java/org/springframework/test/web/servlet/setup/SharedHttpSessionTests.java +++ b/spring-test/src/test/java/org/springframework/test/web/servlet/setup/SharedHttpSessionTests.java @@ -18,7 +18,7 @@ package org.springframework.test.web.servlet.setup; import javax.servlet.http.HttpSession; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.stereotype.Controller; import org.springframework.test.web.servlet.MockMvc; diff --git a/spring-test/src/test/java/org/springframework/test/web/servlet/setup/StandaloneMockMvcBuilderTests.java b/spring-test/src/test/java/org/springframework/test/web/servlet/setup/StandaloneMockMvcBuilderTests.java index c807e09907..4673f55bb0 100644 --- a/spring-test/src/test/java/org/springframework/test/web/servlet/setup/StandaloneMockMvcBuilderTests.java +++ b/spring-test/src/test/java/org/springframework/test/web/servlet/setup/StandaloneMockMvcBuilderTests.java @@ -25,7 +25,7 @@ import javax.servlet.http.HttpServletResponse; import com.fasterxml.jackson.databind.JsonSerializer; import com.fasterxml.jackson.databind.ser.impl.UnknownSerializer; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.http.converter.json.SpringHandlerInstantiator; import org.springframework.mock.web.test.MockHttpServletRequest; diff --git a/spring-test/src/test/kotlin/org/springframework/test/web/reactive/server/WebTestClientExtensionsTests.kt b/spring-test/src/test/kotlin/org/springframework/test/web/reactive/server/WebTestClientExtensionsTests.kt index c5bbf08fbb..1af130fd9d 100644 --- a/spring-test/src/test/kotlin/org/springframework/test/web/reactive/server/WebTestClientExtensionsTests.kt +++ b/spring-test/src/test/kotlin/org/springframework/test/web/reactive/server/WebTestClientExtensionsTests.kt @@ -21,7 +21,7 @@ import io.mockk.verify import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.flow.Flow import org.junit.jupiter.api.Assertions.assertEquals -import org.junit.Test +import org.junit.jupiter.api.Test import org.reactivestreams.Publisher import org.springframework.core.ParameterizedTypeReference import org.springframework.web.reactive.function.server.router diff --git a/spring-test/src/test/kotlin/org/springframework/test/web/servlet/MockMvcExtensionsTests.kt b/spring-test/src/test/kotlin/org/springframework/test/web/servlet/MockMvcExtensionsTests.kt index 0dd6003d77..86cb527d3d 100644 --- a/spring-test/src/test/kotlin/org/springframework/test/web/servlet/MockMvcExtensionsTests.kt +++ b/spring-test/src/test/kotlin/org/springframework/test/web/servlet/MockMvcExtensionsTests.kt @@ -17,7 +17,7 @@ package org.springframework.test.web.servlet import org.hamcrest.CoreMatchers -import org.junit.jupiter.api.Assertions.* +import org.junit.jupiter.api.Assertions.assertTrue import org.junit.jupiter.api.Test import org.junit.jupiter.api.assertThrows import org.springframework.http.HttpMethod diff --git a/spring-test/src/test/kotlin/org/springframework/test/web/servlet/result/StatusResultMatchersExtensionsTests.kt b/spring-test/src/test/kotlin/org/springframework/test/web/servlet/result/StatusResultMatchersExtensionsTests.kt index c4dd257336..b0bef932ee 100644 --- a/spring-test/src/test/kotlin/org/springframework/test/web/servlet/result/StatusResultMatchersExtensionsTests.kt +++ b/spring-test/src/test/kotlin/org/springframework/test/web/servlet/result/StatusResultMatchersExtensionsTests.kt @@ -19,7 +19,7 @@ package org.springframework.test.web.servlet.result import io.mockk.mockk import io.mockk.verify import org.hamcrest.Matcher -import org.junit.Test +import org.junit.jupiter.api.Test class StatusResultMatchersExtensionsTests {