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
This commit is contained in:
Sam Brannen
2019-08-16 14:34:45 +02:00
parent 979508a7f3
commit 5c1f93d9a6
262 changed files with 2227 additions and 2191 deletions

View File

@@ -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")

View File

@@ -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();

View File

@@ -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");

View File

@@ -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);

View File

@@ -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<String> 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<String, Object> 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<String, Object> params = new HashMap<>(2);
@@ -262,7 +262,7 @@ public class MockHttpServletRequestTests {
}
@Test
public void removeAllParameters() {
void removeAllParameters() {
request.setParameter("key1", "value1");
Map<String, Object> 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<Locale> 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<Locale> 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));

View File

@@ -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<String> 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");

View File

@@ -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();

View File

@@ -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(

View File

@@ -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);

View File

@@ -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<String> paths = sc.getResourcePaths("/web");
assertThat(paths).isNotNull();
assertThat(paths.contains("/web/MockServletContextTests.class")).isTrue();
}
@Test
public void listSubdirectories() {
void listSubdirectories() {
Set<String> paths = sc.getResourcePaths("/");
assertThat(paths).isNotNull();
assertThat(paths.contains("/web/")).isTrue();
}
@Test
public void listNonDirectory() {
void listNonDirectory() {
Set<String> paths = sc.getResourcePaths("/web/MockServletContextTests.class");
assertThat(paths).isNull();
}
@Test
public void listInvalidPath() {
void listInvalidPath() {
Set<String> 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 {
* <a href="https://stackoverflow.com/questions/22986109/testing-spring-managed-servlet">Testing Spring managed servlet</a>
*/
@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<String, ? extends ServletRegistration> 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<String, ? extends FilterRegistration> filterRegistrations = sc.getFilterRegistrations();
assertThat(filterRegistrations).isNotNull();
assertThat(filterRegistrations.size()).isEqualTo(0);

View File

@@ -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();

View File

@@ -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);
}

View File

@@ -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() {
}

View File

@@ -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<Class<? extends ApplicationContextInitializer<?>>> initializerClasses1 =
new HashSet<>();
initializerClasses1.add(FooInitializer.class);
@@ -188,7 +188,7 @@ public class MergedContextConfigurationTests {
}
@Test
public void hashCodeWithDifferentInitializers() {
void hashCodeWithDifferentInitializers() {
Set<Class<? extends ApplicationContextInitializer<?>>> 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<Class<? extends ApplicationContextInitializer<?>>> initializerClasses1 =
new HashSet<>();
initializerClasses1.add(FooInitializer.class);
@@ -385,7 +385,7 @@ public class MergedContextConfigurationTests {
}
@Test
public void equalsWithDifferentInitializers() {
void equalsWithDifferentInitializers() {
Set<Class<? extends ApplicationContextInitializer<?>>> initializerClasses1 =
new HashSet<>();
initializerClasses1.add(FooInitializer.class);
@@ -406,7 +406,7 @@ public class MergedContextConfigurationTests {
* @since 4.3
*/
@Test
public void equalsWithSameContextCustomizers() {
void equalsWithSameContextCustomizers() {
Set<ContextCustomizer> 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<ContextCustomizer> customizers1 = Collections.singleton(mock(ContextCustomizer.class));
Set<ContextCustomizer> 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" },

View File

@@ -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<String> expectedMethods = stream(TestCase.class.getDeclaredMethods()).map(
Method::getName).collect(toCollection(TreeSet::new));
private static Set<String> expectedMethods = stream(TestCase.class.getDeclaredMethods())
.map(Method::getName)
.collect(toCollection(TreeSet::new));
private static final Set<String> 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

View File

@@ -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());
}

View File

@@ -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<String> 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;
}

View File

@@ -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<Class<?>> 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<Class<?>> 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<Class<?>> 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<Class<?>> 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));
}

View File

@@ -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());
}

View File

@@ -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();

View File

@@ -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(

View File

@@ -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);
}

View File

@@ -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);

View File

@@ -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();
}
}
}

View File

@@ -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
* &#064;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);
}
}

View File

@@ -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");
}

View File

@@ -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");
}

View File

@@ -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");
}

View File

@@ -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();

View File

@@ -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();
}

View File

@@ -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);
}
}

View File

@@ -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");
}

View File

@@ -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();
}

View File

@@ -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");
}

View File

@@ -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");
}

View File

@@ -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 */

View File

@@ -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");

View File

@@ -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 */

View File

@@ -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");
}

View File

@@ -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(

View File

@@ -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");
}

View File

@@ -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);
}

View File

@@ -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");
}

View File

@@ -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

View File

@@ -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 {

View File

@@ -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");
}

View File

@@ -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");

View File

@@ -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");
}

View File

@@ -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");
}

View File

@@ -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");
}

View File

@@ -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");
}

View File

@@ -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");

View File

@@ -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");
}

View File

@@ -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");
}

View File

@@ -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");
}

View File

@@ -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");
}

View File

@@ -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");

View File

@@ -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 */

View File

@@ -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<CustomEvent> events = new ArrayList<>();
@Before
@BeforeEach
public void clearEvents() {
events.clear();
}

View File

@@ -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 {

View File

@@ -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<Function<TestContext, ? extends ApplicationEvent>> 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);
}

View File

@@ -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");
}

View File

@@ -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 */

View File

@@ -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");

View File

@@ -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");
}

View File

@@ -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);

View File

@@ -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");
}

View File

@@ -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");

View File

@@ -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 */

View File

@@ -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");
}

View File

@@ -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();

View File

@@ -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();

View File

@@ -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");
}

View File

@@ -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();

View File

@@ -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}.
*
* <p>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");
}
}
}

View File

@@ -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");

View File

@@ -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();

View File

@@ -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();

View File

@@ -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");

View File

@@ -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");

View File

@@ -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");

View File

@@ -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();

View File

@@ -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();

View File

@@ -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();

View File

@@ -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");

View File

@@ -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");

View File

@@ -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;

View File

@@ -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();

View File

@@ -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;

View File

@@ -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<String> actualUsers = this.jdbcTemplate.queryForList("select name from user", String.class);
assertThat(actualUsers).containsExactlyInAnyOrder(expectedUsers);
}
}

View File

@@ -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);
}

View File

@@ -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);
}
}

View File

@@ -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();
}
}

View File

@@ -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);
}
}

View File

@@ -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();

View File

@@ -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);
}
}

View File

@@ -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();
}
}

View File

@@ -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")//

View File

@@ -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);
}
}

View File

@@ -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");

Some files were not shown because too many files have changed in this diff Show More