Migrate JUnit 4 assertions to AssertJ
Migrate all existing JUnit 4 `assert...` based assertions to AssertJ and add a checkstyle rule to ensure they don't return. See gh-23022
This commit is contained in:
@@ -22,7 +22,7 @@ import org.junit.Test;
|
||||
import org.springframework.http.HttpCookie;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link MockServerHttpRequest}.
|
||||
@@ -40,10 +40,9 @@ public class MockServerHttpRequestTests {
|
||||
MockServerHttpRequest request = MockServerHttpRequest.get("/")
|
||||
.cookie(foo11, foo12, foo21, foo22).build();
|
||||
|
||||
assertEquals(Arrays.asList(foo11, foo12), request.getCookies().get("foo1"));
|
||||
assertEquals(Arrays.asList(foo21, foo22), request.getCookies().get("foo2"));
|
||||
assertEquals(Arrays.asList("foo1=bar1", "foo1=bar2", "foo2=baz1", "foo2=baz2"),
|
||||
request.getHeaders().get(HttpHeaders.COOKIE));
|
||||
assertThat(request.getCookies().get("foo1")).isEqualTo(Arrays.asList(foo11, foo12));
|
||||
assertThat(request.getCookies().get("foo2")).isEqualTo(Arrays.asList(foo21, foo22));
|
||||
assertThat(request.getHeaders().get(HttpHeaders.COOKIE)).isEqualTo(Arrays.asList("foo1=bar1", "foo1=bar2", "foo2=baz1", "foo2=baz2"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -53,8 +52,7 @@ public class MockServerHttpRequestTests {
|
||||
.queryParam("name B", "value B1")
|
||||
.build();
|
||||
|
||||
assertEquals("/foo%20bar?a=b&name%20A=value%20A1&name%20A=value%20A2&name%20B=value%20B1",
|
||||
request.getURI().toString());
|
||||
assertThat(request.getURI().toString()).isEqualTo("/foo%20bar?a=b&name%20A=value%20A1&name%20A=value%20A2&name%20B=value%20B1");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ import org.junit.Test;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.ResponseCookie;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link MockServerHttpResponse}.
|
||||
@@ -46,8 +46,7 @@ public class MockServerHttpResponseTests {
|
||||
|
||||
response.applyCookies();
|
||||
|
||||
assertEquals(Arrays.asList("foo1=bar1", "foo1=bar2", "foo2=baz1", "foo2=baz2"),
|
||||
response.getHeaders().get(HttpHeaders.SET_COOKIE));
|
||||
assertThat(response.getHeaders().get(HttpHeaders.SET_COOKIE)).isEqualTo(Arrays.asList("foo1=bar1", "foo1=bar2", "foo2=baz1", "foo2=baz2"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,11 +18,8 @@ package org.springframework.mock.web;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link MockCookie}.
|
||||
@@ -39,12 +36,12 @@ public class MockCookieTests {
|
||||
MockCookie cookie = new MockCookie("SESSION", "123");
|
||||
|
||||
assertCookie(cookie, "SESSION", "123");
|
||||
assertNull(cookie.getDomain());
|
||||
assertEquals(-1, cookie.getMaxAge());
|
||||
assertNull(cookie.getPath());
|
||||
assertFalse(cookie.isHttpOnly());
|
||||
assertFalse(cookie.getSecure());
|
||||
assertNull(cookie.getSameSite());
|
||||
assertThat(cookie.getDomain()).isNull();
|
||||
assertThat(cookie.getMaxAge()).isEqualTo(-1);
|
||||
assertThat(cookie.getPath()).isNull();
|
||||
assertThat(cookie.isHttpOnly()).isFalse();
|
||||
assertThat(cookie.getSecure()).isFalse();
|
||||
assertThat(cookie.getSameSite()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -52,7 +49,7 @@ public class MockCookieTests {
|
||||
MockCookie cookie = new MockCookie("SESSION", "123");
|
||||
cookie.setSameSite("Strict");
|
||||
|
||||
assertEquals("Strict", cookie.getSameSite());
|
||||
assertThat(cookie.getSameSite()).isEqualTo("Strict");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -70,17 +67,17 @@ public class MockCookieTests {
|
||||
"SESSION=123; Domain=example.com; Max-Age=60; Path=/; Secure; HttpOnly; SameSite=Lax");
|
||||
|
||||
assertCookie(cookie, "SESSION", "123");
|
||||
assertEquals("example.com", cookie.getDomain());
|
||||
assertEquals(60, cookie.getMaxAge());
|
||||
assertEquals("/", cookie.getPath());
|
||||
assertTrue(cookie.getSecure());
|
||||
assertTrue(cookie.isHttpOnly());
|
||||
assertEquals("Lax", cookie.getSameSite());
|
||||
assertThat(cookie.getDomain()).isEqualTo("example.com");
|
||||
assertThat(cookie.getMaxAge()).isEqualTo(60);
|
||||
assertThat(cookie.getPath()).isEqualTo("/");
|
||||
assertThat(cookie.getSecure()).isTrue();
|
||||
assertThat(cookie.isHttpOnly()).isTrue();
|
||||
assertThat(cookie.getSameSite()).isEqualTo("Lax");
|
||||
}
|
||||
|
||||
private void assertCookie(MockCookie cookie, String name, String value) {
|
||||
assertEquals(name, cookie.getName());
|
||||
assertEquals(value, cookie.getValue());
|
||||
assertThat(cookie.getName()).isEqualTo(name);
|
||||
assertThat(cookie.getValue()).isEqualTo(value);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -112,12 +109,12 @@ public class MockCookieTests {
|
||||
"SESSION=123; domain=example.com; max-age=60; path=/; secure; httponly; samesite=Lax");
|
||||
|
||||
assertCookie(cookie, "SESSION", "123");
|
||||
assertEquals("example.com", cookie.getDomain());
|
||||
assertEquals(60, cookie.getMaxAge());
|
||||
assertEquals("/", cookie.getPath());
|
||||
assertTrue(cookie.getSecure());
|
||||
assertTrue(cookie.isHttpOnly());
|
||||
assertEquals("Lax", cookie.getSameSite());
|
||||
assertThat(cookie.getDomain()).isEqualTo("example.com");
|
||||
assertThat(cookie.getMaxAge()).isEqualTo(60);
|
||||
assertThat(cookie.getPath()).isEqualTo("/");
|
||||
assertThat(cookie.getSecure()).isTrue();
|
||||
assertThat(cookie.isHttpOnly()).isTrue();
|
||||
assertThat(cookie.getSameSite()).isEqualTo("Lax");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -31,7 +31,6 @@ import org.junit.Test;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
@@ -112,8 +111,8 @@ public class MockFilterChainTests {
|
||||
|
||||
chain.doFilter(this.request, this.response);
|
||||
|
||||
assertTrue(filter1.invoked);
|
||||
assertTrue(filter2.invoked);
|
||||
assertThat(filter1.invoked).isTrue();
|
||||
assertThat(filter2.invoked).isTrue();
|
||||
|
||||
verify(servlet).service(this.request, this.response);
|
||||
|
||||
|
||||
@@ -35,13 +35,9 @@ import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.util.FileCopyUtils;
|
||||
import org.springframework.util.StreamUtils;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link MockHttpServletRequest}.
|
||||
@@ -63,44 +59,44 @@ public class MockHttpServletRequestTests {
|
||||
|
||||
@Test
|
||||
public void protocolAndScheme() {
|
||||
assertEquals(MockHttpServletRequest.DEFAULT_PROTOCOL, request.getProtocol());
|
||||
assertEquals(MockHttpServletRequest.DEFAULT_SCHEME, request.getScheme());
|
||||
assertThat(request.getProtocol()).isEqualTo(MockHttpServletRequest.DEFAULT_PROTOCOL);
|
||||
assertThat(request.getScheme()).isEqualTo(MockHttpServletRequest.DEFAULT_SCHEME);
|
||||
request.setProtocol("HTTP/2.0");
|
||||
request.setScheme("https");
|
||||
assertEquals("HTTP/2.0", request.getProtocol());
|
||||
assertEquals("https", request.getScheme());
|
||||
assertThat(request.getProtocol()).isEqualTo("HTTP/2.0");
|
||||
assertThat(request.getScheme()).isEqualTo("https");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setContentAndGetInputStream() throws IOException {
|
||||
byte[] bytes = "body".getBytes(Charset.defaultCharset());
|
||||
request.setContent(bytes);
|
||||
assertEquals(bytes.length, request.getContentLength());
|
||||
assertEquals("body", StreamUtils.copyToString(request.getInputStream(), Charset.defaultCharset()));
|
||||
assertThat(request.getContentLength()).isEqualTo(bytes.length);
|
||||
assertThat(StreamUtils.copyToString(request.getInputStream(), Charset.defaultCharset())).isEqualTo("body");
|
||||
|
||||
request.setContent(bytes);
|
||||
assertEquals(bytes.length, request.getContentLength());
|
||||
assertEquals("body", StreamUtils.copyToString(request.getInputStream(), Charset.defaultCharset()));
|
||||
assertThat(request.getContentLength()).isEqualTo(bytes.length);
|
||||
assertThat(StreamUtils.copyToString(request.getInputStream(), Charset.defaultCharset())).isEqualTo("body");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setContentAndGetReader() throws IOException {
|
||||
byte[] bytes = "body".getBytes(Charset.defaultCharset());
|
||||
request.setContent(bytes);
|
||||
assertEquals(bytes.length, request.getContentLength());
|
||||
assertEquals("body", FileCopyUtils.copyToString(request.getReader()));
|
||||
assertThat(request.getContentLength()).isEqualTo(bytes.length);
|
||||
assertThat(FileCopyUtils.copyToString(request.getReader())).isEqualTo("body");
|
||||
|
||||
request.setContent(bytes);
|
||||
assertEquals(bytes.length, request.getContentLength());
|
||||
assertEquals("body", FileCopyUtils.copyToString(request.getReader()));
|
||||
assertThat(request.getContentLength()).isEqualTo(bytes.length);
|
||||
assertThat(FileCopyUtils.copyToString(request.getReader())).isEqualTo("body");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setContentAndGetContentAsByteArray() {
|
||||
byte[] bytes = "request body".getBytes();
|
||||
request.setContent(bytes);
|
||||
assertEquals(bytes.length, request.getContentLength());
|
||||
assertEquals(bytes, request.getContentAsByteArray());
|
||||
assertThat(request.getContentLength()).isEqualTo(bytes.length);
|
||||
assertThat(request.getContentAsByteArray()).isEqualTo(bytes);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -116,29 +112,29 @@ public class MockHttpServletRequestTests {
|
||||
byte[] bytes = palindrome.getBytes("UTF-16");
|
||||
request.setCharacterEncoding("UTF-16");
|
||||
request.setContent(bytes);
|
||||
assertEquals(bytes.length, request.getContentLength());
|
||||
assertEquals(palindrome, request.getContentAsString());
|
||||
assertThat(request.getContentLength()).isEqualTo(bytes.length);
|
||||
assertThat(request.getContentAsString()).isEqualTo(palindrome);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void noContent() throws IOException {
|
||||
assertEquals(-1, request.getContentLength());
|
||||
assertEquals(-1, request.getInputStream().read());
|
||||
assertNull(request.getContentAsByteArray());
|
||||
assertThat(request.getContentLength()).isEqualTo(-1);
|
||||
assertThat(request.getInputStream().read()).isEqualTo(-1);
|
||||
assertThat(request.getContentAsByteArray()).isNull();
|
||||
}
|
||||
|
||||
@Test // SPR-16505
|
||||
public void getReaderTwice() throws IOException {
|
||||
byte[] bytes = "body".getBytes(Charset.defaultCharset());
|
||||
request.setContent(bytes);
|
||||
assertSame(request.getReader(), request.getReader());
|
||||
assertThat(request.getReader()).isSameAs(request.getReader());
|
||||
}
|
||||
|
||||
@Test // SPR-16505
|
||||
public void getInputStreamTwice() throws IOException {
|
||||
byte[] bytes = "body".getBytes(Charset.defaultCharset());
|
||||
request.setContent(bytes);
|
||||
assertSame(request.getInputStream(), request.getInputStream());
|
||||
assertThat(request.getInputStream()).isSameAs(request.getInputStream());
|
||||
}
|
||||
|
||||
@Test // SPR-16499
|
||||
@@ -161,63 +157,63 @@ public class MockHttpServletRequestTests {
|
||||
public void setContentType() {
|
||||
String contentType = "test/plain";
|
||||
request.setContentType(contentType);
|
||||
assertEquals(contentType, request.getContentType());
|
||||
assertEquals(contentType, request.getHeader(HttpHeaders.CONTENT_TYPE));
|
||||
assertNull(request.getCharacterEncoding());
|
||||
assertThat(request.getContentType()).isEqualTo(contentType);
|
||||
assertThat(request.getHeader(HttpHeaders.CONTENT_TYPE)).isEqualTo(contentType);
|
||||
assertThat(request.getCharacterEncoding()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setContentTypeUTF8() {
|
||||
String contentType = "test/plain;charset=UTF-8";
|
||||
request.setContentType(contentType);
|
||||
assertEquals(contentType, request.getContentType());
|
||||
assertEquals(contentType, request.getHeader(HttpHeaders.CONTENT_TYPE));
|
||||
assertEquals("UTF-8", request.getCharacterEncoding());
|
||||
assertThat(request.getContentType()).isEqualTo(contentType);
|
||||
assertThat(request.getHeader(HttpHeaders.CONTENT_TYPE)).isEqualTo(contentType);
|
||||
assertThat(request.getCharacterEncoding()).isEqualTo("UTF-8");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void contentTypeHeader() {
|
||||
String contentType = "test/plain";
|
||||
request.addHeader(HttpHeaders.CONTENT_TYPE, contentType);
|
||||
assertEquals(contentType, request.getContentType());
|
||||
assertEquals(contentType, request.getHeader(HttpHeaders.CONTENT_TYPE));
|
||||
assertNull(request.getCharacterEncoding());
|
||||
assertThat(request.getContentType()).isEqualTo(contentType);
|
||||
assertThat(request.getHeader(HttpHeaders.CONTENT_TYPE)).isEqualTo(contentType);
|
||||
assertThat(request.getCharacterEncoding()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void contentTypeHeaderUTF8() {
|
||||
String contentType = "test/plain;charset=UTF-8";
|
||||
request.addHeader(HttpHeaders.CONTENT_TYPE, contentType);
|
||||
assertEquals(contentType, request.getContentType());
|
||||
assertEquals(contentType, request.getHeader(HttpHeaders.CONTENT_TYPE));
|
||||
assertEquals("UTF-8", request.getCharacterEncoding());
|
||||
assertThat(request.getContentType()).isEqualTo(contentType);
|
||||
assertThat(request.getHeader(HttpHeaders.CONTENT_TYPE)).isEqualTo(contentType);
|
||||
assertThat(request.getCharacterEncoding()).isEqualTo("UTF-8");
|
||||
}
|
||||
|
||||
@Test // SPR-12677
|
||||
public void setContentTypeHeaderWithMoreComplexCharsetSyntax() {
|
||||
String contentType = "test/plain;charset=\"utf-8\";foo=\"charset=bar\";foocharset=bar;foo=bar";
|
||||
request.addHeader(HttpHeaders.CONTENT_TYPE, contentType);
|
||||
assertEquals(contentType, request.getContentType());
|
||||
assertEquals(contentType, request.getHeader(HttpHeaders.CONTENT_TYPE));
|
||||
assertEquals("UTF-8", request.getCharacterEncoding());
|
||||
assertThat(request.getContentType()).isEqualTo(contentType);
|
||||
assertThat(request.getHeader(HttpHeaders.CONTENT_TYPE)).isEqualTo(contentType);
|
||||
assertThat(request.getCharacterEncoding()).isEqualTo("UTF-8");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setContentTypeThenCharacterEncoding() {
|
||||
request.setContentType("test/plain");
|
||||
request.setCharacterEncoding("UTF-8");
|
||||
assertEquals("test/plain", request.getContentType());
|
||||
assertEquals("test/plain;charset=UTF-8", request.getHeader(HttpHeaders.CONTENT_TYPE));
|
||||
assertEquals("UTF-8", request.getCharacterEncoding());
|
||||
assertThat(request.getContentType()).isEqualTo("test/plain");
|
||||
assertThat(request.getHeader(HttpHeaders.CONTENT_TYPE)).isEqualTo("test/plain;charset=UTF-8");
|
||||
assertThat(request.getCharacterEncoding()).isEqualTo("UTF-8");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setCharacterEncodingThenContentType() {
|
||||
request.setCharacterEncoding("UTF-8");
|
||||
request.setContentType("test/plain");
|
||||
assertEquals("test/plain", request.getContentType());
|
||||
assertEquals("test/plain;charset=UTF-8", request.getHeader(HttpHeaders.CONTENT_TYPE));
|
||||
assertEquals("UTF-8", request.getCharacterEncoding());
|
||||
assertThat(request.getContentType()).isEqualTo("test/plain");
|
||||
assertThat(request.getHeader(HttpHeaders.CONTENT_TYPE)).isEqualTo("test/plain;charset=UTF-8");
|
||||
assertThat(request.getCharacterEncoding()).isEqualTo("UTF-8");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -225,7 +221,7 @@ public class MockHttpServletRequestTests {
|
||||
String headerName = "Header1";
|
||||
request.addHeader(headerName, "value1");
|
||||
Enumeration<String> requestHeaders = request.getHeaderNames();
|
||||
assertEquals("HTTP header casing not being preserved", headerName, requestHeaders.nextElement());
|
||||
assertThat(requestHeaders.nextElement()).as("HTTP header casing not being preserved").isEqualTo(headerName);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -237,13 +233,13 @@ public class MockHttpServletRequestTests {
|
||||
params.put("key3", new String[] { "value3A", "value3B" });
|
||||
request.setParameters(params);
|
||||
String[] values1 = request.getParameterValues("key1");
|
||||
assertEquals(1, values1.length);
|
||||
assertEquals("newValue1", request.getParameter("key1"));
|
||||
assertEquals("value2", request.getParameter("key2"));
|
||||
assertThat(values1.length).isEqualTo(1);
|
||||
assertThat(request.getParameter("key1")).isEqualTo("newValue1");
|
||||
assertThat(request.getParameter("key2")).isEqualTo("value2");
|
||||
String[] values3 = request.getParameterValues("key3");
|
||||
assertEquals(2, values3.length);
|
||||
assertEquals("value3A", values3[0]);
|
||||
assertEquals("value3B", values3[1]);
|
||||
assertThat(values3.length).isEqualTo(2);
|
||||
assertThat(values3[0]).isEqualTo("value3A");
|
||||
assertThat(values3[1]).isEqualTo("value3B");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -255,14 +251,14 @@ public class MockHttpServletRequestTests {
|
||||
params.put("key3", new String[] { "value3A", "value3B" });
|
||||
request.addParameters(params);
|
||||
String[] values1 = request.getParameterValues("key1");
|
||||
assertEquals(2, values1.length);
|
||||
assertEquals("value1", values1[0]);
|
||||
assertEquals("newValue1", values1[1]);
|
||||
assertEquals("value2", request.getParameter("key2"));
|
||||
assertThat(values1.length).isEqualTo(2);
|
||||
assertThat(values1[0]).isEqualTo("value1");
|
||||
assertThat(values1[1]).isEqualTo("newValue1");
|
||||
assertThat(request.getParameter("key2")).isEqualTo("value2");
|
||||
String[] values3 = request.getParameterValues("key3");
|
||||
assertEquals(2, values3.length);
|
||||
assertEquals("value3A", values3[0]);
|
||||
assertEquals("value3B", values3[1]);
|
||||
assertThat(values3.length).isEqualTo(2);
|
||||
assertThat(values3[0]).isEqualTo("value3A");
|
||||
assertThat(values3[1]).isEqualTo("value3B");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -272,9 +268,9 @@ public class MockHttpServletRequestTests {
|
||||
params.put("key2", "value2");
|
||||
params.put("key3", new String[] { "value3A", "value3B" });
|
||||
request.addParameters(params);
|
||||
assertEquals(3, request.getParameterMap().size());
|
||||
assertThat(request.getParameterMap().size()).isEqualTo(3);
|
||||
request.removeAllParameters();
|
||||
assertEquals(0, request.getParameterMap().size());
|
||||
assertThat(request.getParameterMap().size()).isEqualTo(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -286,17 +282,17 @@ public class MockHttpServletRequestTests {
|
||||
Cookie[] cookies = request.getCookies();
|
||||
List<String> cookieHeaders = Collections.list(request.getHeaders("Cookie"));
|
||||
|
||||
assertEquals(2, cookies.length);
|
||||
assertEquals("foo", cookies[0].getName());
|
||||
assertEquals("bar", cookies[0].getValue());
|
||||
assertEquals("baz", cookies[1].getName());
|
||||
assertEquals("qux", cookies[1].getValue());
|
||||
assertEquals(Arrays.asList("foo=bar", "baz=qux"), cookieHeaders);
|
||||
assertThat(cookies.length).isEqualTo(2);
|
||||
assertThat(cookies[0].getName()).isEqualTo("foo");
|
||||
assertThat(cookies[0].getValue()).isEqualTo("bar");
|
||||
assertThat(cookies[1].getName()).isEqualTo("baz");
|
||||
assertThat(cookies[1].getValue()).isEqualTo("qux");
|
||||
assertThat(cookieHeaders).isEqualTo(Arrays.asList("foo=bar", "baz=qux"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void noCookies() {
|
||||
assertNull(request.getCookies());
|
||||
assertThat(request.getCookies()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -307,8 +303,8 @@ public class MockHttpServletRequestTests {
|
||||
Locale.setDefault(newDefaultLocale);
|
||||
// Create the request after changing the default locale.
|
||||
MockHttpServletRequest request = new MockHttpServletRequest();
|
||||
assertFalse(newDefaultLocale.equals(request.getLocale()));
|
||||
assertEquals(Locale.ENGLISH, request.getLocale());
|
||||
assertThat(newDefaultLocale.equals(request.getLocale())).isFalse();
|
||||
assertThat(request.getLocale()).isEqualTo(Locale.ENGLISH);
|
||||
}
|
||||
finally {
|
||||
Locale.setDefault(originalDefaultLocale);
|
||||
@@ -332,7 +328,7 @@ public class MockHttpServletRequestTests {
|
||||
List<Locale> preferredLocales = Arrays.asList(Locale.ITALY, Locale.CHINA);
|
||||
request.setPreferredLocales(preferredLocales);
|
||||
assertEqualEnumerations(Collections.enumeration(preferredLocales), request.getLocales());
|
||||
assertEquals("it-it, zh-cn", request.getHeader(HttpHeaders.ACCEPT_LANGUAGE));
|
||||
assertThat(request.getHeader(HttpHeaders.ACCEPT_LANGUAGE)).isEqualTo("it-it, zh-cn");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -340,80 +336,80 @@ public class MockHttpServletRequestTests {
|
||||
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());
|
||||
assertEquals(Arrays.asList(Locale.forLanguageTag("fr-ch"), Locale.forLanguageTag("fr"),
|
||||
Locale.forLanguageTag("en"), Locale.forLanguageTag("de")), actual);
|
||||
assertEquals(headerValue, request.getHeader("Accept-Language"));
|
||||
assertThat(actual).isEqualTo(Arrays.asList(Locale.forLanguageTag("fr-ch"), Locale.forLanguageTag("fr"),
|
||||
Locale.forLanguageTag("en"), Locale.forLanguageTag("de")));
|
||||
assertThat(request.getHeader("Accept-Language")).isEqualTo(headerValue);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void invalidAcceptLanguageHeader() {
|
||||
request.addHeader("Accept-Language", "en_US");
|
||||
assertEquals(Locale.ENGLISH, request.getLocale());
|
||||
assertEquals("en_US", request.getHeader("Accept-Language"));
|
||||
assertThat(request.getLocale()).isEqualTo(Locale.ENGLISH);
|
||||
assertThat(request.getHeader("Accept-Language")).isEqualTo("en_US");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void emptyAcceptLanguageHeader() {
|
||||
request.addHeader("Accept-Language", "");
|
||||
assertEquals(Locale.ENGLISH, request.getLocale());
|
||||
assertEquals("", request.getHeader("Accept-Language"));
|
||||
assertThat(request.getLocale()).isEqualTo(Locale.ENGLISH);
|
||||
assertThat(request.getHeader("Accept-Language")).isEqualTo("");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getServerNameWithDefaultName() {
|
||||
assertEquals("localhost", request.getServerName());
|
||||
assertThat(request.getServerName()).isEqualTo("localhost");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getServerNameWithCustomName() {
|
||||
request.setServerName("example.com");
|
||||
assertEquals("example.com", request.getServerName());
|
||||
assertThat(request.getServerName()).isEqualTo("example.com");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getServerNameViaHostHeaderWithoutPort() {
|
||||
String testServer = "test.server";
|
||||
request.addHeader(HOST, testServer);
|
||||
assertEquals(testServer, request.getServerName());
|
||||
assertThat(request.getServerName()).isEqualTo(testServer);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getServerNameViaHostHeaderWithPort() {
|
||||
String testServer = "test.server";
|
||||
request.addHeader(HOST, testServer + ":8080");
|
||||
assertEquals(testServer, request.getServerName());
|
||||
assertThat(request.getServerName()).isEqualTo(testServer);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getServerNameViaHostHeaderAsIpv6AddressWithoutPort() {
|
||||
String ipv6Address = "[2001:db8:0:1]";
|
||||
request.addHeader(HOST, ipv6Address);
|
||||
assertEquals("2001:db8:0:1", request.getServerName());
|
||||
assertThat(request.getServerName()).isEqualTo("2001:db8:0:1");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getServerNameViaHostHeaderAsIpv6AddressWithPort() {
|
||||
String ipv6Address = "[2001:db8:0:1]:8081";
|
||||
request.addHeader(HOST, ipv6Address);
|
||||
assertEquals("2001:db8:0:1", request.getServerName());
|
||||
assertThat(request.getServerName()).isEqualTo("2001:db8:0:1");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getServerPortWithDefaultPort() {
|
||||
assertEquals(80, request.getServerPort());
|
||||
assertThat(request.getServerPort()).isEqualTo(80);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getServerPortWithCustomPort() {
|
||||
request.setServerPort(8080);
|
||||
assertEquals(8080, request.getServerPort());
|
||||
assertThat(request.getServerPort()).isEqualTo(8080);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getServerPortViaHostHeaderAsIpv6AddressWithoutPort() {
|
||||
String testServer = "[2001:db8:0:1]";
|
||||
request.addHeader(HOST, testServer);
|
||||
assertEquals(80, request.getServerPort());
|
||||
assertThat(request.getServerPort()).isEqualTo(80);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -421,14 +417,14 @@ public class MockHttpServletRequestTests {
|
||||
String testServer = "[2001:db8:0:1]";
|
||||
int testPort = 9999;
|
||||
request.addHeader(HOST, testServer + ":" + testPort);
|
||||
assertEquals(testPort, request.getServerPort());
|
||||
assertThat(request.getServerPort()).isEqualTo(testPort);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getServerPortViaHostHeaderWithoutPort() {
|
||||
String testServer = "test.server";
|
||||
request.addHeader(HOST, testServer);
|
||||
assertEquals(80, request.getServerPort());
|
||||
assertThat(request.getServerPort()).isEqualTo(80);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -436,25 +432,25 @@ public class MockHttpServletRequestTests {
|
||||
String testServer = "test.server";
|
||||
int testPort = 9999;
|
||||
request.addHeader(HOST, testServer + ":" + testPort);
|
||||
assertEquals(testPort, request.getServerPort());
|
||||
assertThat(request.getServerPort()).isEqualTo(testPort);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getRequestURL() {
|
||||
request.setServerPort(8080);
|
||||
request.setRequestURI("/path");
|
||||
assertEquals("http://localhost:8080/path", request.getRequestURL().toString());
|
||||
assertThat(request.getRequestURL().toString()).isEqualTo("http://localhost:8080/path");
|
||||
|
||||
request.setScheme("https");
|
||||
request.setServerName("example.com");
|
||||
request.setServerPort(8443);
|
||||
assertEquals("https://example.com:8443/path", request.getRequestURL().toString());
|
||||
assertThat(request.getRequestURL().toString()).isEqualTo("https://example.com:8443/path");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getRequestURLWithDefaults() {
|
||||
StringBuffer requestURL = request.getRequestURL();
|
||||
assertEquals("http://localhost", requestURL.toString());
|
||||
assertThat(requestURL.toString()).isEqualTo("http://localhost");
|
||||
}
|
||||
|
||||
@Test // SPR-16138
|
||||
@@ -462,7 +458,7 @@ public class MockHttpServletRequestTests {
|
||||
String testServer = "test.server";
|
||||
request.addHeader(HOST, testServer);
|
||||
StringBuffer requestURL = request.getRequestURL();
|
||||
assertEquals("http://" + testServer, requestURL.toString());
|
||||
assertThat(requestURL.toString()).isEqualTo(("http://" + testServer));
|
||||
}
|
||||
|
||||
@Test // SPR-16138
|
||||
@@ -470,14 +466,14 @@ public class MockHttpServletRequestTests {
|
||||
String testServer = "test.server:9999";
|
||||
request.addHeader(HOST, testServer);
|
||||
StringBuffer requestURL = request.getRequestURL();
|
||||
assertEquals("http://" + testServer, requestURL.toString());
|
||||
assertThat(requestURL.toString()).isEqualTo(("http://" + testServer));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getRequestURLWithNullRequestUri() {
|
||||
request.setRequestURI(null);
|
||||
StringBuffer requestURL = request.getRequestURL();
|
||||
assertEquals("http://localhost", requestURL.toString());
|
||||
assertThat(requestURL.toString()).isEqualTo("http://localhost");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -485,78 +481,78 @@ public class MockHttpServletRequestTests {
|
||||
request.setScheme("https");
|
||||
request.setServerPort(443);
|
||||
StringBuffer requestURL = request.getRequestURL();
|
||||
assertEquals("https://localhost", requestURL.toString());
|
||||
assertThat(requestURL.toString()).isEqualTo("https://localhost");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getRequestURLWithNegativePort() {
|
||||
request.setServerPort(-99);
|
||||
StringBuffer requestURL = request.getRequestURL();
|
||||
assertEquals("http://localhost", requestURL.toString());
|
||||
assertThat(requestURL.toString()).isEqualTo("http://localhost");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isSecureWithHttpSchemeAndSecureFlagIsFalse() {
|
||||
assertFalse(request.isSecure());
|
||||
assertThat(request.isSecure()).isFalse();
|
||||
request.setScheme("http");
|
||||
request.setSecure(false);
|
||||
assertFalse(request.isSecure());
|
||||
assertThat(request.isSecure()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isSecureWithHttpSchemeAndSecureFlagIsTrue() {
|
||||
assertFalse(request.isSecure());
|
||||
assertThat(request.isSecure()).isFalse();
|
||||
request.setScheme("http");
|
||||
request.setSecure(true);
|
||||
assertTrue(request.isSecure());
|
||||
assertThat(request.isSecure()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isSecureWithHttpsSchemeAndSecureFlagIsFalse() {
|
||||
assertFalse(request.isSecure());
|
||||
assertThat(request.isSecure()).isFalse();
|
||||
request.setScheme("https");
|
||||
request.setSecure(false);
|
||||
assertTrue(request.isSecure());
|
||||
assertThat(request.isSecure()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isSecureWithHttpsSchemeAndSecureFlagIsTrue() {
|
||||
assertFalse(request.isSecure());
|
||||
assertThat(request.isSecure()).isFalse();
|
||||
request.setScheme("https");
|
||||
request.setSecure(true);
|
||||
assertTrue(request.isSecure());
|
||||
assertThat(request.isSecure()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void httpHeaderDate() {
|
||||
Date date = new Date();
|
||||
request.addHeader(HttpHeaders.IF_MODIFIED_SINCE, date);
|
||||
assertEquals(date.getTime(), request.getDateHeader(HttpHeaders.IF_MODIFIED_SINCE));
|
||||
assertThat(request.getDateHeader(HttpHeaders.IF_MODIFIED_SINCE)).isEqualTo(date.getTime());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void httpHeaderTimestamp() {
|
||||
long timestamp = new Date().getTime();
|
||||
request.addHeader(HttpHeaders.IF_MODIFIED_SINCE, timestamp);
|
||||
assertEquals(timestamp, request.getDateHeader(HttpHeaders.IF_MODIFIED_SINCE));
|
||||
assertThat(request.getDateHeader(HttpHeaders.IF_MODIFIED_SINCE)).isEqualTo(timestamp);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void httpHeaderRfcFormattedDate() {
|
||||
request.addHeader(HttpHeaders.IF_MODIFIED_SINCE, "Tue, 21 Jul 2015 10:00:00 GMT");
|
||||
assertEquals(1437472800000L, request.getDateHeader(HttpHeaders.IF_MODIFIED_SINCE));
|
||||
assertThat(request.getDateHeader(HttpHeaders.IF_MODIFIED_SINCE)).isEqualTo(1437472800000L);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void httpHeaderFirstVariantFormattedDate() {
|
||||
request.addHeader(HttpHeaders.IF_MODIFIED_SINCE, "Tue, 21-Jul-15 10:00:00 GMT");
|
||||
assertEquals(1437472800000L, request.getDateHeader(HttpHeaders.IF_MODIFIED_SINCE));
|
||||
assertThat(request.getDateHeader(HttpHeaders.IF_MODIFIED_SINCE)).isEqualTo(1437472800000L);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void httpHeaderSecondVariantFormattedDate() {
|
||||
request.addHeader(HttpHeaders.IF_MODIFIED_SINCE, "Tue Jul 21 10:00:00 2015");
|
||||
assertEquals(1437472800000L, request.getDateHeader(HttpHeaders.IF_MODIFIED_SINCE));
|
||||
assertThat(request.getDateHeader(HttpHeaders.IF_MODIFIED_SINCE)).isEqualTo(1437472800000L);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -569,8 +565,9 @@ public class MockHttpServletRequestTests {
|
||||
private void assertEqualEnumerations(Enumeration<?> enum1, Enumeration<?> enum2) {
|
||||
int count = 0;
|
||||
while (enum1.hasMoreElements()) {
|
||||
assertTrue("enumerations must be equal in length", enum2.hasMoreElements());
|
||||
assertEquals("enumeration element #" + ++count, enum1.nextElement(), enum2.nextElement());
|
||||
assertThat(enum2.hasMoreElements()).as("enumerations must be equal in length").isTrue();
|
||||
String message = "enumeration element #" + ++count;
|
||||
assertThat(enum2.nextElement()).as(message).isEqualTo(enum1.nextElement());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -27,12 +27,8 @@ import org.junit.Test;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.web.util.WebUtils;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link MockHttpServletResponse}.
|
||||
@@ -54,102 +50,102 @@ public class MockHttpServletResponseTests {
|
||||
public void setContentType() {
|
||||
String contentType = "test/plain";
|
||||
response.setContentType(contentType);
|
||||
assertEquals(contentType, response.getContentType());
|
||||
assertEquals(contentType, response.getHeader("Content-Type"));
|
||||
assertEquals(WebUtils.DEFAULT_CHARACTER_ENCODING, response.getCharacterEncoding());
|
||||
assertThat(response.getContentType()).isEqualTo(contentType);
|
||||
assertThat(response.getHeader("Content-Type")).isEqualTo(contentType);
|
||||
assertThat(response.getCharacterEncoding()).isEqualTo(WebUtils.DEFAULT_CHARACTER_ENCODING);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setContentTypeUTF8() {
|
||||
String contentType = "test/plain;charset=UTF-8";
|
||||
response.setContentType(contentType);
|
||||
assertEquals("UTF-8", response.getCharacterEncoding());
|
||||
assertEquals(contentType, response.getContentType());
|
||||
assertEquals(contentType, response.getHeader("Content-Type"));
|
||||
assertThat(response.getCharacterEncoding()).isEqualTo("UTF-8");
|
||||
assertThat(response.getContentType()).isEqualTo(contentType);
|
||||
assertThat(response.getHeader("Content-Type")).isEqualTo(contentType);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void contentTypeHeader() {
|
||||
String contentType = "test/plain";
|
||||
response.addHeader("Content-Type", contentType);
|
||||
assertEquals(contentType, response.getContentType());
|
||||
assertEquals(contentType, response.getHeader("Content-Type"));
|
||||
assertEquals(WebUtils.DEFAULT_CHARACTER_ENCODING, response.getCharacterEncoding());
|
||||
assertThat(response.getContentType()).isEqualTo(contentType);
|
||||
assertThat(response.getHeader("Content-Type")).isEqualTo(contentType);
|
||||
assertThat(response.getCharacterEncoding()).isEqualTo(WebUtils.DEFAULT_CHARACTER_ENCODING);
|
||||
|
||||
response = new MockHttpServletResponse();
|
||||
response.setHeader("Content-Type", contentType);
|
||||
assertEquals(contentType, response.getContentType());
|
||||
assertEquals(contentType, response.getHeader("Content-Type"));
|
||||
assertEquals(WebUtils.DEFAULT_CHARACTER_ENCODING, response.getCharacterEncoding());
|
||||
assertThat(response.getContentType()).isEqualTo(contentType);
|
||||
assertThat(response.getHeader("Content-Type")).isEqualTo(contentType);
|
||||
assertThat(response.getCharacterEncoding()).isEqualTo(WebUtils.DEFAULT_CHARACTER_ENCODING);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void contentTypeHeaderUTF8() {
|
||||
String contentType = "test/plain;charset=UTF-8";
|
||||
response.setHeader("Content-Type", contentType);
|
||||
assertEquals(contentType, response.getContentType());
|
||||
assertEquals(contentType, response.getHeader("Content-Type"));
|
||||
assertEquals("UTF-8", response.getCharacterEncoding());
|
||||
assertThat(response.getContentType()).isEqualTo(contentType);
|
||||
assertThat(response.getHeader("Content-Type")).isEqualTo(contentType);
|
||||
assertThat(response.getCharacterEncoding()).isEqualTo("UTF-8");
|
||||
|
||||
response = new MockHttpServletResponse();
|
||||
response.addHeader("Content-Type", contentType);
|
||||
assertEquals(contentType, response.getContentType());
|
||||
assertEquals(contentType, response.getHeader("Content-Type"));
|
||||
assertEquals("UTF-8", response.getCharacterEncoding());
|
||||
assertThat(response.getContentType()).isEqualTo(contentType);
|
||||
assertThat(response.getHeader("Content-Type")).isEqualTo(contentType);
|
||||
assertThat(response.getCharacterEncoding()).isEqualTo("UTF-8");
|
||||
}
|
||||
|
||||
@Test // SPR-12677
|
||||
public void contentTypeHeaderWithMoreComplexCharsetSyntax() {
|
||||
String contentType = "test/plain;charset=\"utf-8\";foo=\"charset=bar\";foocharset=bar;foo=bar";
|
||||
response.setHeader("Content-Type", contentType);
|
||||
assertEquals(contentType, response.getContentType());
|
||||
assertEquals(contentType, response.getHeader("Content-Type"));
|
||||
assertEquals("UTF-8", response.getCharacterEncoding());
|
||||
assertThat(response.getContentType()).isEqualTo(contentType);
|
||||
assertThat(response.getHeader("Content-Type")).isEqualTo(contentType);
|
||||
assertThat(response.getCharacterEncoding()).isEqualTo("UTF-8");
|
||||
|
||||
response = new MockHttpServletResponse();
|
||||
response.addHeader("Content-Type", contentType);
|
||||
assertEquals(contentType, response.getContentType());
|
||||
assertEquals(contentType, response.getHeader("Content-Type"));
|
||||
assertEquals("UTF-8", response.getCharacterEncoding());
|
||||
assertThat(response.getContentType()).isEqualTo(contentType);
|
||||
assertThat(response.getHeader("Content-Type")).isEqualTo(contentType);
|
||||
assertThat(response.getCharacterEncoding()).isEqualTo("UTF-8");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setContentTypeThenCharacterEncoding() {
|
||||
response.setContentType("test/plain");
|
||||
response.setCharacterEncoding("UTF-8");
|
||||
assertEquals("test/plain", response.getContentType());
|
||||
assertEquals("test/plain;charset=UTF-8", response.getHeader("Content-Type"));
|
||||
assertEquals("UTF-8", response.getCharacterEncoding());
|
||||
assertThat(response.getContentType()).isEqualTo("test/plain");
|
||||
assertThat(response.getHeader("Content-Type")).isEqualTo("test/plain;charset=UTF-8");
|
||||
assertThat(response.getCharacterEncoding()).isEqualTo("UTF-8");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setCharacterEncodingThenContentType() {
|
||||
response.setCharacterEncoding("UTF-8");
|
||||
response.setContentType("test/plain");
|
||||
assertEquals("test/plain", response.getContentType());
|
||||
assertEquals("test/plain;charset=UTF-8", response.getHeader("Content-Type"));
|
||||
assertEquals("UTF-8", response.getCharacterEncoding());
|
||||
assertThat(response.getContentType()).isEqualTo("test/plain");
|
||||
assertThat(response.getHeader("Content-Type")).isEqualTo("test/plain;charset=UTF-8");
|
||||
assertThat(response.getCharacterEncoding()).isEqualTo("UTF-8");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void contentLength() {
|
||||
response.setContentLength(66);
|
||||
assertEquals(66, response.getContentLength());
|
||||
assertEquals("66", response.getHeader("Content-Length"));
|
||||
assertThat(response.getContentLength()).isEqualTo(66);
|
||||
assertThat(response.getHeader("Content-Length")).isEqualTo("66");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void contentLengthHeader() {
|
||||
response.addHeader("Content-Length", "66");
|
||||
assertEquals(66, response.getContentLength());
|
||||
assertEquals("66", response.getHeader("Content-Length"));
|
||||
assertThat(response.getContentLength()).isEqualTo(66);
|
||||
assertThat(response.getHeader("Content-Length")).isEqualTo("66");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void contentLengthIntHeader() {
|
||||
response.addIntHeader("Content-Length", 66);
|
||||
assertEquals(66, response.getContentLength());
|
||||
assertEquals("66", response.getHeader("Content-Length"));
|
||||
assertThat(response.getContentLength()).isEqualTo(66);
|
||||
assertThat(response.getHeader("Content-Length")).isEqualTo("66");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -157,9 +153,9 @@ public class MockHttpServletResponseTests {
|
||||
final String headerName = "Header1";
|
||||
response.addHeader(headerName, "value1");
|
||||
Collection<String> responseHeaders = response.getHeaderNames();
|
||||
assertNotNull(responseHeaders);
|
||||
assertEquals(1, responseHeaders.size());
|
||||
assertEquals("HTTP header casing not being preserved", headerName, responseHeaders.iterator().next());
|
||||
assertThat(responseHeaders).isNotNull();
|
||||
assertThat(responseHeaders.size()).isEqualTo(1);
|
||||
assertThat(responseHeaders.iterator().next()).as("HTTP header casing not being preserved").isEqualTo(headerName);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -173,151 +169,151 @@ public class MockHttpServletResponseTests {
|
||||
|
||||
response.addCookie(cookie);
|
||||
|
||||
assertEquals("foo=bar; Path=/path; Domain=example.com; " +
|
||||
assertThat(response.getHeader(HttpHeaders.SET_COOKIE)).isEqualTo(("foo=bar; Path=/path; Domain=example.com; " +
|
||||
"Max-Age=0; Expires=Thu, 01 Jan 1970 00:00:00 GMT; " +
|
||||
"Secure; HttpOnly", response.getHeader(HttpHeaders.SET_COOKIE));
|
||||
"Secure; HttpOnly"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void servletOutputStreamCommittedWhenBufferSizeExceeded() throws IOException {
|
||||
assertFalse(response.isCommitted());
|
||||
assertThat(response.isCommitted()).isFalse();
|
||||
response.getOutputStream().write('X');
|
||||
assertFalse(response.isCommitted());
|
||||
assertThat(response.isCommitted()).isFalse();
|
||||
int size = response.getBufferSize();
|
||||
response.getOutputStream().write(new byte[size]);
|
||||
assertTrue(response.isCommitted());
|
||||
assertEquals(size + 1, response.getContentAsByteArray().length);
|
||||
assertThat(response.isCommitted()).isTrue();
|
||||
assertThat(response.getContentAsByteArray().length).isEqualTo((size + 1));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void servletOutputStreamCommittedOnFlushBuffer() throws IOException {
|
||||
assertFalse(response.isCommitted());
|
||||
assertThat(response.isCommitted()).isFalse();
|
||||
response.getOutputStream().write('X');
|
||||
assertFalse(response.isCommitted());
|
||||
assertThat(response.isCommitted()).isFalse();
|
||||
response.flushBuffer();
|
||||
assertTrue(response.isCommitted());
|
||||
assertEquals(1, response.getContentAsByteArray().length);
|
||||
assertThat(response.isCommitted()).isTrue();
|
||||
assertThat(response.getContentAsByteArray().length).isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void servletWriterCommittedWhenBufferSizeExceeded() throws IOException {
|
||||
assertFalse(response.isCommitted());
|
||||
assertThat(response.isCommitted()).isFalse();
|
||||
response.getWriter().write("X");
|
||||
assertFalse(response.isCommitted());
|
||||
assertThat(response.isCommitted()).isFalse();
|
||||
int size = response.getBufferSize();
|
||||
char[] data = new char[size];
|
||||
Arrays.fill(data, 'p');
|
||||
response.getWriter().write(data);
|
||||
assertTrue(response.isCommitted());
|
||||
assertEquals(size + 1, response.getContentAsByteArray().length);
|
||||
assertThat(response.isCommitted()).isTrue();
|
||||
assertThat(response.getContentAsByteArray().length).isEqualTo((size + 1));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void servletOutputStreamCommittedOnOutputStreamFlush() throws IOException {
|
||||
assertFalse(response.isCommitted());
|
||||
assertThat(response.isCommitted()).isFalse();
|
||||
response.getOutputStream().write('X');
|
||||
assertFalse(response.isCommitted());
|
||||
assertThat(response.isCommitted()).isFalse();
|
||||
response.getOutputStream().flush();
|
||||
assertTrue(response.isCommitted());
|
||||
assertEquals(1, response.getContentAsByteArray().length);
|
||||
assertThat(response.isCommitted()).isTrue();
|
||||
assertThat(response.getContentAsByteArray().length).isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void servletWriterCommittedOnWriterFlush() throws IOException {
|
||||
assertFalse(response.isCommitted());
|
||||
assertThat(response.isCommitted()).isFalse();
|
||||
response.getWriter().write("X");
|
||||
assertFalse(response.isCommitted());
|
||||
assertThat(response.isCommitted()).isFalse();
|
||||
response.getWriter().flush();
|
||||
assertTrue(response.isCommitted());
|
||||
assertEquals(1, response.getContentAsByteArray().length);
|
||||
assertThat(response.isCommitted()).isTrue();
|
||||
assertThat(response.getContentAsByteArray().length).isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test // SPR-16683
|
||||
public void servletWriterCommittedOnWriterClose() throws IOException {
|
||||
assertFalse(response.isCommitted());
|
||||
assertThat(response.isCommitted()).isFalse();
|
||||
response.getWriter().write("X");
|
||||
assertFalse(response.isCommitted());
|
||||
assertThat(response.isCommitted()).isFalse();
|
||||
response.getWriter().close();
|
||||
assertTrue(response.isCommitted());
|
||||
assertEquals(1, response.getContentAsByteArray().length);
|
||||
assertThat(response.isCommitted()).isTrue();
|
||||
assertThat(response.getContentAsByteArray().length).isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void servletWriterAutoFlushedForString() throws IOException {
|
||||
response.getWriter().write("X");
|
||||
assertEquals("X", response.getContentAsString());
|
||||
assertThat(response.getContentAsString()).isEqualTo("X");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void servletWriterAutoFlushedForChar() throws IOException {
|
||||
response.getWriter().write('X');
|
||||
assertEquals("X", response.getContentAsString());
|
||||
assertThat(response.getContentAsString()).isEqualTo("X");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void servletWriterAutoFlushedForCharArray() throws IOException {
|
||||
response.getWriter().write("XY".toCharArray());
|
||||
assertEquals("XY", response.getContentAsString());
|
||||
assertThat(response.getContentAsString()).isEqualTo("XY");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sendRedirect() throws IOException {
|
||||
String redirectUrl = "/redirect";
|
||||
response.sendRedirect(redirectUrl);
|
||||
assertEquals(HttpServletResponse.SC_MOVED_TEMPORARILY, response.getStatus());
|
||||
assertEquals(redirectUrl, response.getHeader("Location"));
|
||||
assertEquals(redirectUrl, response.getRedirectedUrl());
|
||||
assertTrue(response.isCommitted());
|
||||
assertThat(response.getStatus()).isEqualTo(HttpServletResponse.SC_MOVED_TEMPORARILY);
|
||||
assertThat(response.getHeader("Location")).isEqualTo(redirectUrl);
|
||||
assertThat(response.getRedirectedUrl()).isEqualTo(redirectUrl);
|
||||
assertThat(response.isCommitted()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void locationHeaderUpdatesGetRedirectedUrl() {
|
||||
String redirectUrl = "/redirect";
|
||||
response.setHeader("Location", redirectUrl);
|
||||
assertEquals(redirectUrl, response.getRedirectedUrl());
|
||||
assertThat(response.getRedirectedUrl()).isEqualTo(redirectUrl);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setDateHeader() {
|
||||
response.setDateHeader("Last-Modified", 1437472800000L);
|
||||
assertEquals("Tue, 21 Jul 2015 10:00:00 GMT", response.getHeader("Last-Modified"));
|
||||
assertThat(response.getHeader("Last-Modified")).isEqualTo("Tue, 21 Jul 2015 10:00:00 GMT");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addDateHeader() {
|
||||
response.addDateHeader("Last-Modified", 1437472800000L);
|
||||
response.addDateHeader("Last-Modified", 1437472801000L);
|
||||
assertEquals("Tue, 21 Jul 2015 10:00:00 GMT", response.getHeaders("Last-Modified").get(0));
|
||||
assertEquals("Tue, 21 Jul 2015 10:00:01 GMT", response.getHeaders("Last-Modified").get(1));
|
||||
assertThat(response.getHeaders("Last-Modified").get(0)).isEqualTo("Tue, 21 Jul 2015 10:00:00 GMT");
|
||||
assertThat(response.getHeaders("Last-Modified").get(1)).isEqualTo("Tue, 21 Jul 2015 10:00:01 GMT");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getDateHeader() {
|
||||
long time = 1437472800000L;
|
||||
response.setDateHeader("Last-Modified", time);
|
||||
assertEquals("Tue, 21 Jul 2015 10:00:00 GMT", response.getHeader("Last-Modified"));
|
||||
assertEquals(time, response.getDateHeader("Last-Modified"));
|
||||
assertThat(response.getHeader("Last-Modified")).isEqualTo("Tue, 21 Jul 2015 10:00:00 GMT");
|
||||
assertThat(response.getDateHeader("Last-Modified")).isEqualTo(time);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getInvalidDateHeader() {
|
||||
response.setHeader("Last-Modified", "invalid");
|
||||
assertEquals("invalid", response.getHeader("Last-Modified"));
|
||||
assertThat(response.getHeader("Last-Modified")).isEqualTo("invalid");
|
||||
assertThatIllegalArgumentException().isThrownBy(() ->
|
||||
response.getDateHeader("Last-Modified"));
|
||||
}
|
||||
|
||||
@Test // SPR-16160
|
||||
public void getNonExistentDateHeader() {
|
||||
assertNull(response.getHeader("Last-Modified"));
|
||||
assertEquals(-1, response.getDateHeader("Last-Modified"));
|
||||
assertThat(response.getHeader("Last-Modified")).isNull();
|
||||
assertThat(response.getDateHeader("Last-Modified")).isEqualTo(-1);
|
||||
}
|
||||
|
||||
@Test // SPR-10414
|
||||
public void modifyStatusAfterSendError() throws IOException {
|
||||
response.sendError(HttpServletResponse.SC_NOT_FOUND);
|
||||
response.setStatus(HttpServletResponse.SC_OK);
|
||||
assertEquals(HttpServletResponse.SC_NOT_FOUND, response.getStatus());
|
||||
assertThat(response.getStatus()).isEqualTo(HttpServletResponse.SC_NOT_FOUND);
|
||||
}
|
||||
|
||||
@Test // SPR-10414
|
||||
@@ -325,21 +321,22 @@ public class MockHttpServletResponseTests {
|
||||
public void modifyStatusMessageAfterSendError() throws IOException {
|
||||
response.sendError(HttpServletResponse.SC_NOT_FOUND);
|
||||
response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,"Server Error");
|
||||
assertEquals(HttpServletResponse.SC_NOT_FOUND, response.getStatus());
|
||||
assertThat(response.getStatus()).isEqualTo(HttpServletResponse.SC_NOT_FOUND);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setCookieHeaderValid() {
|
||||
response.addHeader(HttpHeaders.SET_COOKIE, "SESSION=123; Path=/; Secure; HttpOnly; SameSite=Lax");
|
||||
Cookie cookie = response.getCookie("SESSION");
|
||||
assertNotNull(cookie);
|
||||
assertTrue(cookie instanceof MockCookie);
|
||||
assertEquals("SESSION", cookie.getName());
|
||||
assertEquals("123", cookie.getValue());
|
||||
assertEquals("/", cookie.getPath());
|
||||
assertTrue(cookie.getSecure());
|
||||
assertTrue(cookie.isHttpOnly());
|
||||
assertEquals("Lax", ((MockCookie) cookie).getSameSite());
|
||||
assertThat(cookie).isNotNull();
|
||||
boolean condition = cookie instanceof MockCookie;
|
||||
assertThat(condition).isTrue();
|
||||
assertThat(cookie.getName()).isEqualTo("SESSION");
|
||||
assertThat(cookie.getValue()).isEqualTo("123");
|
||||
assertThat(cookie.getPath()).isEqualTo("/");
|
||||
assertThat(cookie.getSecure()).isTrue();
|
||||
assertThat(cookie.isHttpOnly()).isTrue();
|
||||
assertThat(((MockCookie) cookie).getSameSite()).isEqualTo("Lax");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -354,9 +351,8 @@ public class MockHttpServletResponseTests {
|
||||
|
||||
response.addCookie(mockCookie);
|
||||
|
||||
assertEquals("SESSION=123; Path=/; Domain=example.com; Max-Age=0; " +
|
||||
"Expires=Thu, 01 Jan 1970 00:00:00 GMT; Secure; HttpOnly; SameSite=Lax",
|
||||
response.getHeader(HttpHeaders.SET_COOKIE));
|
||||
assertThat(response.getHeader(HttpHeaders.SET_COOKIE)).isEqualTo(("SESSION=123; Path=/; Domain=example.com; Max-Age=0; " +
|
||||
"Expires=Thu, 01 Jan 1970 00:00:00 GMT; Secure; HttpOnly; SameSite=Lax"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -22,10 +22,8 @@ import javax.servlet.http.HttpSessionBindingListener;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link MockHttpSession}.
|
||||
@@ -41,9 +39,9 @@ public class MockHttpSessionTests {
|
||||
|
||||
@Test
|
||||
public void invalidateOnce() {
|
||||
assertFalse(session.isInvalid());
|
||||
assertThat(session.isInvalid()).isFalse();
|
||||
session.invalidate();
|
||||
assertTrue(session.isInvalid());
|
||||
assertThat(session.isInvalid()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -137,7 +135,7 @@ public class MockHttpSessionTests {
|
||||
|
||||
session.setAttribute(bindingListenerName, bindingListener);
|
||||
|
||||
assertEquals(bindingListener.getCounter(), 1);
|
||||
assertThat(1).isEqualTo(bindingListener.getCounter());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -148,7 +146,7 @@ public class MockHttpSessionTests {
|
||||
session.setAttribute(bindingListenerName, bindingListener);
|
||||
session.removeAttribute(bindingListenerName);
|
||||
|
||||
assertEquals(bindingListener.getCounter(), 0);
|
||||
assertThat(0).isEqualTo(bindingListener.getCounter());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -159,7 +157,7 @@ public class MockHttpSessionTests {
|
||||
session.setAttribute(bindingListenerName, bindingListener);
|
||||
session.setAttribute(bindingListenerName, bindingListener);
|
||||
|
||||
assertEquals(bindingListener.getCounter(), 1);
|
||||
assertThat(1).isEqualTo(bindingListener.getCounter());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -171,8 +169,8 @@ public class MockHttpSessionTests {
|
||||
session.setAttribute(bindingListenerName, bindingListener1);
|
||||
session.setAttribute(bindingListenerName, bindingListener2);
|
||||
|
||||
assertEquals(bindingListener1.getCounter(), 0);
|
||||
assertEquals(bindingListener2.getCounter(), 1);
|
||||
assertThat(0).isEqualTo(bindingListener1.getCounter());
|
||||
assertThat(1).isEqualTo(bindingListener2.getCounter());
|
||||
}
|
||||
|
||||
private static class CountingHttpSessionBindingListener
|
||||
|
||||
@@ -32,10 +32,7 @@ import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import org.springframework.web.multipart.MultipartHttpServletRequest;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* @author Juergen Hoeller
|
||||
@@ -45,10 +42,10 @@ public class MockMultipartHttpServletRequestTests {
|
||||
@Test
|
||||
public void mockMultipartHttpServletRequestWithByteArray() throws IOException {
|
||||
MockMultipartHttpServletRequest request = new MockMultipartHttpServletRequest();
|
||||
assertFalse(request.getFileNames().hasNext());
|
||||
assertNull(request.getFile("file1"));
|
||||
assertNull(request.getFile("file2"));
|
||||
assertTrue(request.getFileMap().isEmpty());
|
||||
assertThat(request.getFileNames().hasNext()).isFalse();
|
||||
assertThat(request.getFile("file1")).isNull();
|
||||
assertThat(request.getFile("file2")).isNull();
|
||||
assertThat(request.getFileMap().isEmpty()).isTrue();
|
||||
|
||||
request.addFile(new MockMultipartFile("file1", "myContent1".getBytes()));
|
||||
request.addFile(new MockMultipartFile("file2", "myOrigFilename", "text/plain", "myContent2".getBytes()));
|
||||
@@ -70,29 +67,29 @@ public class MockMultipartHttpServletRequestTests {
|
||||
while (fileIter.hasNext()) {
|
||||
fileNames.add(fileIter.next());
|
||||
}
|
||||
assertEquals(2, fileNames.size());
|
||||
assertTrue(fileNames.contains("file1"));
|
||||
assertTrue(fileNames.contains("file2"));
|
||||
assertThat(fileNames.size()).isEqualTo(2);
|
||||
assertThat(fileNames.contains("file1")).isTrue();
|
||||
assertThat(fileNames.contains("file2")).isTrue();
|
||||
MultipartFile file1 = request.getFile("file1");
|
||||
MultipartFile file2 = request.getFile("file2");
|
||||
Map<String, MultipartFile> fileMap = request.getFileMap();
|
||||
List<String> fileMapKeys = new LinkedList<>(fileMap.keySet());
|
||||
assertEquals(2, fileMapKeys.size());
|
||||
assertEquals(file1, fileMap.get("file1"));
|
||||
assertEquals(file2, fileMap.get("file2"));
|
||||
assertThat(fileMapKeys.size()).isEqualTo(2);
|
||||
assertThat(fileMap.get("file1")).isEqualTo(file1);
|
||||
assertThat(fileMap.get("file2")).isEqualTo(file2);
|
||||
|
||||
assertEquals("file1", file1.getName());
|
||||
assertEquals("", file1.getOriginalFilename());
|
||||
assertNull(file1.getContentType());
|
||||
assertTrue(ObjectUtils.nullSafeEquals("myContent1".getBytes(), file1.getBytes()));
|
||||
assertTrue(ObjectUtils.nullSafeEquals("myContent1".getBytes(),
|
||||
FileCopyUtils.copyToByteArray(file1.getInputStream())));
|
||||
assertEquals("file2", file2.getName());
|
||||
assertEquals("myOrigFilename", file2.getOriginalFilename());
|
||||
assertEquals("text/plain", file2.getContentType());
|
||||
assertTrue(ObjectUtils.nullSafeEquals("myContent2".getBytes(), file2.getBytes()));
|
||||
assertTrue(ObjectUtils.nullSafeEquals("myContent2".getBytes(),
|
||||
FileCopyUtils.copyToByteArray(file2.getInputStream())));
|
||||
assertThat(file1.getName()).isEqualTo("file1");
|
||||
assertThat(file1.getOriginalFilename()).isEqualTo("");
|
||||
assertThat(file1.getContentType()).isNull();
|
||||
assertThat(ObjectUtils.nullSafeEquals("myContent1".getBytes(), file1.getBytes())).isTrue();
|
||||
assertThat(ObjectUtils.nullSafeEquals("myContent1".getBytes(),
|
||||
FileCopyUtils.copyToByteArray(file1.getInputStream()))).isTrue();
|
||||
assertThat(file2.getName()).isEqualTo("file2");
|
||||
assertThat(file2.getOriginalFilename()).isEqualTo("myOrigFilename");
|
||||
assertThat(file2.getContentType()).isEqualTo("text/plain");
|
||||
assertThat(ObjectUtils.nullSafeEquals("myContent2".getBytes(), file2.getBytes())).isTrue();
|
||||
assertThat(ObjectUtils.nullSafeEquals("myContent2".getBytes(),
|
||||
FileCopyUtils.copyToByteArray(file2.getInputStream()))).isTrue();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -20,8 +20,7 @@ import javax.servlet.jsp.PageContext;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Unit tests for the {@code MockPageContext} class.
|
||||
@@ -39,10 +38,10 @@ public class MockPageContextTests {
|
||||
@Test
|
||||
public void setAttributeWithNoScopeUsesPageScope() throws Exception {
|
||||
ctx.setAttribute(key, value);
|
||||
assertEquals(value, ctx.getAttribute(key, PageContext.PAGE_SCOPE));
|
||||
assertNull(ctx.getAttribute(key, PageContext.APPLICATION_SCOPE));
|
||||
assertNull(ctx.getAttribute(key, PageContext.REQUEST_SCOPE));
|
||||
assertNull(ctx.getAttribute(key, PageContext.SESSION_SCOPE));
|
||||
assertThat(ctx.getAttribute(key, PageContext.PAGE_SCOPE)).isEqualTo(value);
|
||||
assertThat(ctx.getAttribute(key, PageContext.APPLICATION_SCOPE)).isNull();
|
||||
assertThat(ctx.getAttribute(key, PageContext.REQUEST_SCOPE)).isNull();
|
||||
assertThat(ctx.getAttribute(key, PageContext.SESSION_SCOPE)).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -50,10 +49,10 @@ public class MockPageContextTests {
|
||||
ctx.setAttribute(key, value, PageContext.APPLICATION_SCOPE);
|
||||
ctx.removeAttribute(key);
|
||||
|
||||
assertNull(ctx.getAttribute(key, PageContext.PAGE_SCOPE));
|
||||
assertNull(ctx.getAttribute(key, PageContext.APPLICATION_SCOPE));
|
||||
assertNull(ctx.getAttribute(key, PageContext.REQUEST_SCOPE));
|
||||
assertNull(ctx.getAttribute(key, PageContext.SESSION_SCOPE));
|
||||
assertThat(ctx.getAttribute(key, PageContext.PAGE_SCOPE)).isNull();
|
||||
assertThat(ctx.getAttribute(key, PageContext.APPLICATION_SCOPE)).isNull();
|
||||
assertThat(ctx.getAttribute(key, PageContext.REQUEST_SCOPE)).isNull();
|
||||
assertThat(ctx.getAttribute(key, PageContext.SESSION_SCOPE)).isNull();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -26,11 +26,7 @@ import org.junit.Test;
|
||||
|
||||
import org.springframework.http.MediaType;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* @author Juergen Hoeller
|
||||
@@ -46,27 +42,27 @@ public class MockServletContextTests {
|
||||
@Test
|
||||
public void listFiles() {
|
||||
Set<String> paths = sc.getResourcePaths("/web");
|
||||
assertNotNull(paths);
|
||||
assertTrue(paths.contains("/web/MockServletContextTests.class"));
|
||||
assertThat(paths).isNotNull();
|
||||
assertThat(paths.contains("/web/MockServletContextTests.class")).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void listSubdirectories() {
|
||||
Set<String> paths = sc.getResourcePaths("/");
|
||||
assertNotNull(paths);
|
||||
assertTrue(paths.contains("/web/"));
|
||||
assertThat(paths).isNotNull();
|
||||
assertThat(paths.contains("/web/")).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void listNonDirectory() {
|
||||
Set<String> paths = sc.getResourcePaths("/web/MockServletContextTests.class");
|
||||
assertNull(paths);
|
||||
assertThat(paths).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void listInvalidPath() {
|
||||
Set<String> paths = sc.getResourcePaths("/web/invalid");
|
||||
assertNull(paths);
|
||||
assertThat(paths).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -74,15 +70,15 @@ public class MockServletContextTests {
|
||||
MockServletContext sc2 = new MockServletContext();
|
||||
sc.setContextPath("/");
|
||||
sc.registerContext("/second", sc2);
|
||||
assertSame(sc, sc.getContext("/"));
|
||||
assertSame(sc2, sc.getContext("/second"));
|
||||
assertThat(sc.getContext("/")).isSameAs(sc);
|
||||
assertThat(sc.getContext("/second")).isSameAs(sc2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getMimeType() {
|
||||
assertEquals("text/html", sc.getMimeType("test.html"));
|
||||
assertEquals("image/gif", sc.getMimeType("test.gif"));
|
||||
assertNull(sc.getMimeType("test.foobar"));
|
||||
assertThat(sc.getMimeType("test.html")).isEqualTo("text/html");
|
||||
assertThat(sc.getMimeType("test.gif")).isEqualTo("image/gif");
|
||||
assertThat(sc.getMimeType("test.foobar")).isNull();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -92,69 +88,69 @@ public class MockServletContextTests {
|
||||
@Test
|
||||
public void getMimeTypeWithCustomConfiguredType() {
|
||||
sc.addMimeType("enigma", new MediaType("text", "enigma"));
|
||||
assertEquals("text/enigma", sc.getMimeType("filename.enigma"));
|
||||
assertThat(sc.getMimeType("filename.enigma")).isEqualTo("text/enigma");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void servletVersion() {
|
||||
assertEquals(3, sc.getMajorVersion());
|
||||
assertEquals(1, sc.getMinorVersion());
|
||||
assertEquals(3, sc.getEffectiveMajorVersion());
|
||||
assertEquals(1, sc.getEffectiveMinorVersion());
|
||||
assertThat(sc.getMajorVersion()).isEqualTo(3);
|
||||
assertThat(sc.getMinorVersion()).isEqualTo(1);
|
||||
assertThat(sc.getEffectiveMajorVersion()).isEqualTo(3);
|
||||
assertThat(sc.getEffectiveMinorVersion()).isEqualTo(1);
|
||||
|
||||
sc.setMajorVersion(4);
|
||||
sc.setMinorVersion(0);
|
||||
sc.setEffectiveMajorVersion(4);
|
||||
sc.setEffectiveMinorVersion(0);
|
||||
assertEquals(4, sc.getMajorVersion());
|
||||
assertEquals(0, sc.getMinorVersion());
|
||||
assertEquals(4, sc.getEffectiveMajorVersion());
|
||||
assertEquals(0, sc.getEffectiveMinorVersion());
|
||||
assertThat(sc.getMajorVersion()).isEqualTo(4);
|
||||
assertThat(sc.getMinorVersion()).isEqualTo(0);
|
||||
assertThat(sc.getEffectiveMajorVersion()).isEqualTo(4);
|
||||
assertThat(sc.getEffectiveMinorVersion()).isEqualTo(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void registerAndUnregisterNamedDispatcher() throws Exception {
|
||||
final String name = "test-servlet";
|
||||
final String url = "/test";
|
||||
assertNull(sc.getNamedDispatcher(name));
|
||||
assertThat(sc.getNamedDispatcher(name)).isNull();
|
||||
|
||||
sc.registerNamedDispatcher(name, new MockRequestDispatcher(url));
|
||||
RequestDispatcher namedDispatcher = sc.getNamedDispatcher(name);
|
||||
assertNotNull(namedDispatcher);
|
||||
assertThat(namedDispatcher).isNotNull();
|
||||
MockHttpServletResponse response = new MockHttpServletResponse();
|
||||
namedDispatcher.forward(new MockHttpServletRequest(sc), response);
|
||||
assertEquals(url, response.getForwardedUrl());
|
||||
assertThat(response.getForwardedUrl()).isEqualTo(url);
|
||||
|
||||
sc.unregisterNamedDispatcher(name);
|
||||
assertNull(sc.getNamedDispatcher(name));
|
||||
assertThat(sc.getNamedDispatcher(name)).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getNamedDispatcherForDefaultServlet() throws Exception {
|
||||
final String name = "default";
|
||||
RequestDispatcher namedDispatcher = sc.getNamedDispatcher(name);
|
||||
assertNotNull(namedDispatcher);
|
||||
assertThat(namedDispatcher).isNotNull();
|
||||
|
||||
MockHttpServletResponse response = new MockHttpServletResponse();
|
||||
namedDispatcher.forward(new MockHttpServletRequest(sc), response);
|
||||
assertEquals(name, response.getForwardedUrl());
|
||||
assertThat(response.getForwardedUrl()).isEqualTo(name);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setDefaultServletName() throws Exception {
|
||||
final String originalDefault = "default";
|
||||
final String newDefault = "test";
|
||||
assertNotNull(sc.getNamedDispatcher(originalDefault));
|
||||
assertThat(sc.getNamedDispatcher(originalDefault)).isNotNull();
|
||||
|
||||
sc.setDefaultServletName(newDefault);
|
||||
assertEquals(newDefault, sc.getDefaultServletName());
|
||||
assertNull(sc.getNamedDispatcher(originalDefault));
|
||||
assertThat(sc.getDefaultServletName()).isEqualTo(newDefault);
|
||||
assertThat(sc.getNamedDispatcher(originalDefault)).isNull();
|
||||
|
||||
RequestDispatcher namedDispatcher = sc.getNamedDispatcher(newDefault);
|
||||
assertNotNull(namedDispatcher);
|
||||
assertThat(namedDispatcher).isNotNull();
|
||||
MockHttpServletResponse response = new MockHttpServletResponse();
|
||||
namedDispatcher.forward(new MockHttpServletRequest(sc), response);
|
||||
assertEquals(newDefault, response.getForwardedUrl());
|
||||
assertThat(response.getForwardedUrl()).isEqualTo(newDefault);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -162,7 +158,7 @@ public class MockServletContextTests {
|
||||
*/
|
||||
@Test
|
||||
public void getServletRegistration() {
|
||||
assertNull(sc.getServletRegistration("servlet"));
|
||||
assertThat(sc.getServletRegistration("servlet")).isNull();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -171,8 +167,8 @@ public class MockServletContextTests {
|
||||
@Test
|
||||
public void getServletRegistrations() {
|
||||
Map<String, ? extends ServletRegistration> servletRegistrations = sc.getServletRegistrations();
|
||||
assertNotNull(servletRegistrations);
|
||||
assertEquals(0, servletRegistrations.size());
|
||||
assertThat(servletRegistrations).isNotNull();
|
||||
assertThat(servletRegistrations.size()).isEqualTo(0);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -180,7 +176,7 @@ public class MockServletContextTests {
|
||||
*/
|
||||
@Test
|
||||
public void getFilterRegistration() {
|
||||
assertNull(sc.getFilterRegistration("filter"));
|
||||
assertThat(sc.getFilterRegistration("filter")).isNull();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -189,8 +185,8 @@ public class MockServletContextTests {
|
||||
@Test
|
||||
public void getFilterRegistrations() {
|
||||
Map<String, ? extends FilterRegistration> filterRegistrations = sc.getFilterRegistrations();
|
||||
assertNotNull(filterRegistrations);
|
||||
assertEquals(0, filterRegistrations.size());
|
||||
assertThat(filterRegistrations).isNotNull();
|
||||
assertThat(filterRegistrations.size()).isEqualTo(0);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -23,8 +23,7 @@ import java.lang.reflect.Method;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link ProfileValueUtils}.
|
||||
@@ -48,39 +47,35 @@ public class ProfileValueUtilsTests {
|
||||
}
|
||||
|
||||
private void assertClassIsEnabled(Class<?> testClass) throws Exception {
|
||||
assertTrue("Test class [" + testClass + "] should be enabled.",
|
||||
ProfileValueUtils.isTestEnabledInThisEnvironment(testClass));
|
||||
assertThat(ProfileValueUtils.isTestEnabledInThisEnvironment(testClass)).as("Test class [" + testClass + "] should be enabled.").isTrue();
|
||||
}
|
||||
|
||||
private void assertClassIsDisabled(Class<?> testClass) throws Exception {
|
||||
assertFalse("Test class [" + testClass + "] should be disabled.",
|
||||
ProfileValueUtils.isTestEnabledInThisEnvironment(testClass));
|
||||
assertThat(ProfileValueUtils.isTestEnabledInThisEnvironment(testClass)).as("Test class [" + testClass + "] should be disabled.").isFalse();
|
||||
}
|
||||
|
||||
private void assertMethodIsEnabled(String methodName, Class<?> testClass) throws Exception {
|
||||
Method testMethod = testClass.getMethod(methodName);
|
||||
assertTrue("Test method [" + testMethod + "] should be enabled.",
|
||||
ProfileValueUtils.isTestEnabledInThisEnvironment(testMethod, testClass));
|
||||
assertThat(ProfileValueUtils.isTestEnabledInThisEnvironment(testMethod, testClass)).as("Test method [" + testMethod + "] should be enabled.").isTrue();
|
||||
}
|
||||
|
||||
private void assertMethodIsDisabled(String methodName, Class<?> testClass) throws Exception {
|
||||
Method testMethod = testClass.getMethod(methodName);
|
||||
assertFalse("Test method [" + testMethod + "] should be disabled.",
|
||||
ProfileValueUtils.isTestEnabledInThisEnvironment(testMethod, testClass));
|
||||
assertThat(ProfileValueUtils.isTestEnabledInThisEnvironment(testMethod, testClass)).as("Test method [" + testMethod + "] should be disabled.").isFalse();
|
||||
}
|
||||
|
||||
private void assertMethodIsEnabled(ProfileValueSource profileValueSource, String methodName, Class<?> testClass)
|
||||
throws Exception {
|
||||
Method testMethod = testClass.getMethod(methodName);
|
||||
assertTrue("Test method [" + testMethod + "] should be enabled for ProfileValueSource [" + profileValueSource
|
||||
+ "].", ProfileValueUtils.isTestEnabledInThisEnvironment(profileValueSource, testMethod, testClass));
|
||||
assertThat(ProfileValueUtils.isTestEnabledInThisEnvironment(profileValueSource, testMethod, testClass)).as("Test method [" + testMethod + "] should be enabled for ProfileValueSource [" + profileValueSource
|
||||
+ "].").isTrue();
|
||||
}
|
||||
|
||||
private void assertMethodIsDisabled(ProfileValueSource profileValueSource, String methodName, Class<?> testClass)
|
||||
throws Exception {
|
||||
Method testMethod = testClass.getMethod(methodName);
|
||||
assertFalse("Test method [" + testMethod + "] should be disabled for ProfileValueSource [" + profileValueSource
|
||||
+ "].", ProfileValueUtils.isTestEnabledInThisEnvironment(profileValueSource, testMethod, testClass));
|
||||
assertThat(ProfileValueUtils.isTestEnabledInThisEnvironment(profileValueSource, testMethod, testClass)).as("Test method [" + testMethod + "] should be disabled for ProfileValueSource [" + profileValueSource
|
||||
+ "].").isFalse();
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
@@ -25,9 +25,8 @@ import org.springframework.test.context.support.DefaultTestContextBootstrapper;
|
||||
import org.springframework.test.context.web.WebAppConfiguration;
|
||||
import org.springframework.test.context.web.WebTestContextBootstrapper;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.springframework.test.context.BootstrapUtils.resolveTestContextBootstrapper;
|
||||
|
||||
@@ -102,8 +101,8 @@ public class BootstrapUtilsTests {
|
||||
private void assertBootstrapper(Class<?> testClass, Class<?> expectedBootstrapper) {
|
||||
BootstrapContext bootstrapContext = BootstrapTestUtils.buildBootstrapContext(testClass, delegate);
|
||||
TestContextBootstrapper bootstrapper = resolveTestContextBootstrapper(bootstrapContext);
|
||||
assertNotNull(bootstrapper);
|
||||
assertEquals(expectedBootstrapper, bootstrapper.getClass());
|
||||
assertThat(bootstrapper).isNotNull();
|
||||
assertThat(bootstrapper.getClass()).isEqualTo(expectedBootstrapper);
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
@@ -35,8 +35,6 @@ import org.springframework.test.annotation.DirtiesContext.HierarchyMode;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* Integration tests that verify proper behavior of {@link DirtiesContext @DirtiesContext}
|
||||
@@ -91,22 +89,22 @@ public class ContextHierarchyDirtiesContextTests {
|
||||
|
||||
JUnitCore jUnitCore = new JUnitCore();
|
||||
Result result = jUnitCore.run(testClass);
|
||||
assertTrue("all tests passed", result.wasSuccessful());
|
||||
assertThat(result.wasSuccessful()).as("all tests passed").isTrue();
|
||||
|
||||
assertThat(ContextHierarchyDirtiesContextTests.context).isNotNull();
|
||||
|
||||
ConfigurableApplicationContext bazContext = (ConfigurableApplicationContext) ContextHierarchyDirtiesContextTests.context;
|
||||
assertEquals("baz", ContextHierarchyDirtiesContextTests.baz);
|
||||
assertThat(ContextHierarchyDirtiesContextTests.baz).isEqualTo("baz");
|
||||
assertThat(bazContext.isActive()).isEqualTo(isBazContextActive);
|
||||
|
||||
ConfigurableApplicationContext barContext = (ConfigurableApplicationContext) bazContext.getParent();
|
||||
assertThat(barContext).isNotNull();
|
||||
assertEquals("bar", ContextHierarchyDirtiesContextTests.bar);
|
||||
assertThat(ContextHierarchyDirtiesContextTests.bar).isEqualTo("bar");
|
||||
assertThat(barContext.isActive()).isEqualTo(isBarContextActive);
|
||||
|
||||
ConfigurableApplicationContext fooContext = (ConfigurableApplicationContext) barContext.getParent();
|
||||
assertThat(fooContext).isNotNull();
|
||||
assertEquals("foo", ContextHierarchyDirtiesContextTests.foo);
|
||||
assertThat(ContextHierarchyDirtiesContextTests.foo).isEqualTo("foo");
|
||||
assertThat(fooContext.isActive()).isEqualTo(isFooContextActive);
|
||||
}
|
||||
|
||||
|
||||
@@ -27,8 +27,7 @@ import org.springframework.context.support.GenericApplicationContext;
|
||||
import org.springframework.test.context.support.AnnotationConfigContextLoader;
|
||||
import org.springframework.test.context.support.GenericXmlContextLoader;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotEquals;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
/**
|
||||
@@ -56,14 +55,14 @@ public class MergedContextConfigurationTests {
|
||||
public void hashCodeWithNulls() {
|
||||
MergedContextConfiguration mergedConfig1 = new MergedContextConfiguration(null, null, null, null, null);
|
||||
MergedContextConfiguration mergedConfig2 = new MergedContextConfiguration(null, null, null, null, null);
|
||||
assertEquals(mergedConfig1.hashCode(), mergedConfig2.hashCode());
|
||||
assertThat(mergedConfig2.hashCode()).isEqualTo(mergedConfig1.hashCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hashCodeWithNullArrays() {
|
||||
MergedContextConfiguration mergedConfig1 = new MergedContextConfiguration(getClass(), null, null, null, loader);
|
||||
MergedContextConfiguration mergedConfig2 = new MergedContextConfiguration(getClass(), null, null, null, loader);
|
||||
assertEquals(mergedConfig1.hashCode(), mergedConfig2.hashCode());
|
||||
assertThat(mergedConfig2.hashCode()).isEqualTo(mergedConfig1.hashCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -72,7 +71,7 @@ public class MergedContextConfigurationTests {
|
||||
EMPTY_STRING_ARRAY, EMPTY_CLASS_ARRAY, EMPTY_STRING_ARRAY, loader);
|
||||
MergedContextConfiguration mergedConfig2 = new MergedContextConfiguration(getClass(),
|
||||
EMPTY_STRING_ARRAY, EMPTY_CLASS_ARRAY, EMPTY_STRING_ARRAY, loader);
|
||||
assertEquals(mergedConfig1.hashCode(), mergedConfig2.hashCode());
|
||||
assertThat(mergedConfig2.hashCode()).isEqualTo(mergedConfig1.hashCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -81,7 +80,7 @@ public class MergedContextConfigurationTests {
|
||||
EMPTY_STRING_ARRAY, EMPTY_CLASS_ARRAY, EMPTY_STRING_ARRAY, loader);
|
||||
MergedContextConfiguration mergedConfig2 = new MergedContextConfiguration(getClass(),
|
||||
EMPTY_STRING_ARRAY, EMPTY_CLASS_ARRAY, EMPTY_STRING_ARRAY, new AnnotationConfigContextLoader());
|
||||
assertNotEquals(mergedConfig1.hashCode(), mergedConfig2.hashCode());
|
||||
assertThat(mergedConfig2.hashCode()).isNotEqualTo((long) mergedConfig1.hashCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -91,7 +90,7 @@ public class MergedContextConfigurationTests {
|
||||
EMPTY_CLASS_ARRAY, EMPTY_STRING_ARRAY, loader);
|
||||
MergedContextConfiguration mergedConfig2 = new MergedContextConfiguration(getClass(), locations,
|
||||
EMPTY_CLASS_ARRAY, EMPTY_STRING_ARRAY, loader);
|
||||
assertEquals(mergedConfig1.hashCode(), mergedConfig2.hashCode());
|
||||
assertThat(mergedConfig2.hashCode()).isEqualTo(mergedConfig1.hashCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -102,7 +101,7 @@ public class MergedContextConfigurationTests {
|
||||
EMPTY_CLASS_ARRAY, EMPTY_STRING_ARRAY, loader);
|
||||
MergedContextConfiguration mergedConfig2 = new MergedContextConfiguration(getClass(), locations2,
|
||||
EMPTY_CLASS_ARRAY, EMPTY_STRING_ARRAY, loader);
|
||||
assertNotEquals(mergedConfig1.hashCode(), mergedConfig2.hashCode());
|
||||
assertThat(mergedConfig2.hashCode()).isNotEqualTo((long) mergedConfig1.hashCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -112,7 +111,7 @@ public class MergedContextConfigurationTests {
|
||||
EMPTY_STRING_ARRAY, classes, EMPTY_STRING_ARRAY, loader);
|
||||
MergedContextConfiguration mergedConfig2 = new MergedContextConfiguration(getClass(),
|
||||
EMPTY_STRING_ARRAY, classes, EMPTY_STRING_ARRAY, loader);
|
||||
assertEquals(mergedConfig1.hashCode(), mergedConfig2.hashCode());
|
||||
assertThat(mergedConfig2.hashCode()).isEqualTo(mergedConfig1.hashCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -123,7 +122,7 @@ public class MergedContextConfigurationTests {
|
||||
EMPTY_STRING_ARRAY, classes1, EMPTY_STRING_ARRAY, loader);
|
||||
MergedContextConfiguration mergedConfig2 = new MergedContextConfiguration(getClass(),
|
||||
EMPTY_STRING_ARRAY, classes2, EMPTY_STRING_ARRAY, loader);
|
||||
assertNotEquals(mergedConfig1.hashCode(), mergedConfig2.hashCode());
|
||||
assertThat(mergedConfig2.hashCode()).isNotEqualTo((long) mergedConfig1.hashCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -133,7 +132,7 @@ public class MergedContextConfigurationTests {
|
||||
EMPTY_STRING_ARRAY, EMPTY_CLASS_ARRAY, activeProfiles, loader);
|
||||
MergedContextConfiguration mergedConfig2 = new MergedContextConfiguration(getClass(),
|
||||
EMPTY_STRING_ARRAY, EMPTY_CLASS_ARRAY, activeProfiles, loader);
|
||||
assertEquals(mergedConfig1.hashCode(), mergedConfig2.hashCode());
|
||||
assertThat(mergedConfig2.hashCode()).isEqualTo(mergedConfig1.hashCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -144,7 +143,7 @@ public class MergedContextConfigurationTests {
|
||||
EMPTY_STRING_ARRAY, EMPTY_CLASS_ARRAY, activeProfiles1, loader);
|
||||
MergedContextConfiguration mergedConfig2 = new MergedContextConfiguration(getClass(),
|
||||
EMPTY_STRING_ARRAY, EMPTY_CLASS_ARRAY, activeProfiles2, loader);
|
||||
assertNotEquals(mergedConfig1.hashCode(), mergedConfig2.hashCode());
|
||||
assertThat(mergedConfig2.hashCode()).isNotEqualTo((long) mergedConfig1.hashCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -155,7 +154,7 @@ public class MergedContextConfigurationTests {
|
||||
EMPTY_STRING_ARRAY, EMPTY_CLASS_ARRAY, activeProfiles1, loader);
|
||||
MergedContextConfiguration mergedConfig2 = new MergedContextConfiguration(getClass(),
|
||||
EMPTY_STRING_ARRAY, EMPTY_CLASS_ARRAY, activeProfiles2, loader);
|
||||
assertEquals(mergedConfig1.hashCode(), mergedConfig2.hashCode());
|
||||
assertThat(mergedConfig2.hashCode()).isEqualTo(mergedConfig1.hashCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -166,7 +165,7 @@ public class MergedContextConfigurationTests {
|
||||
EMPTY_STRING_ARRAY, EMPTY_CLASS_ARRAY, activeProfiles1, loader);
|
||||
MergedContextConfiguration mergedConfig2 = new MergedContextConfiguration(getClass(),
|
||||
EMPTY_STRING_ARRAY, EMPTY_CLASS_ARRAY, activeProfiles2, loader);
|
||||
assertNotEquals(mergedConfig1.hashCode(), mergedConfig2.hashCode());
|
||||
assertThat(mergedConfig2.hashCode()).isNotEqualTo((long) mergedConfig1.hashCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -185,7 +184,7 @@ public class MergedContextConfigurationTests {
|
||||
EMPTY_STRING_ARRAY, EMPTY_CLASS_ARRAY, initializerClasses1, EMPTY_STRING_ARRAY, loader);
|
||||
MergedContextConfiguration mergedConfig2 = new MergedContextConfiguration(getClass(),
|
||||
EMPTY_STRING_ARRAY, EMPTY_CLASS_ARRAY, initializerClasses2, EMPTY_STRING_ARRAY, loader);
|
||||
assertEquals(mergedConfig1.hashCode(), mergedConfig2.hashCode());
|
||||
assertThat(mergedConfig2.hashCode()).isEqualTo(mergedConfig1.hashCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -202,7 +201,7 @@ public class MergedContextConfigurationTests {
|
||||
EMPTY_STRING_ARRAY, EMPTY_CLASS_ARRAY, initializerClasses1, EMPTY_STRING_ARRAY, loader);
|
||||
MergedContextConfiguration mergedConfig2 = new MergedContextConfiguration(getClass(),
|
||||
EMPTY_STRING_ARRAY, EMPTY_CLASS_ARRAY, initializerClasses2, EMPTY_STRING_ARRAY, loader);
|
||||
assertNotEquals(mergedConfig1.hashCode(), mergedConfig2.hashCode());
|
||||
assertThat(mergedConfig2.hashCode()).isNotEqualTo((long) mergedConfig1.hashCode());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -217,7 +216,7 @@ public class MergedContextConfigurationTests {
|
||||
EMPTY_STRING_ARRAY, EMPTY_CLASS_ARRAY, null, EMPTY_STRING_ARRAY, loader, null, parent);
|
||||
MergedContextConfiguration mergedConfig2 = new MergedContextConfiguration(getClass(), EMPTY_STRING_ARRAY,
|
||||
EMPTY_CLASS_ARRAY, null, EMPTY_STRING_ARRAY, loader, null, parent);
|
||||
assertEquals(mergedConfig1.hashCode(), mergedConfig2.hashCode());
|
||||
assertThat(mergedConfig2.hashCode()).isEqualTo(mergedConfig1.hashCode());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -234,29 +233,29 @@ public class MergedContextConfigurationTests {
|
||||
EMPTY_CLASS_ARRAY, null, EMPTY_STRING_ARRAY, loader, null, parent1);
|
||||
MergedContextConfiguration mergedConfig2 = new MergedContextConfiguration(getClass(), EMPTY_STRING_ARRAY,
|
||||
EMPTY_CLASS_ARRAY, null, EMPTY_STRING_ARRAY, loader, null, parent2);
|
||||
assertNotEquals(mergedConfig1.hashCode(), mergedConfig2.hashCode());
|
||||
assertThat(mergedConfig2.hashCode()).isNotEqualTo((long) mergedConfig1.hashCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void equalsBasics() {
|
||||
MergedContextConfiguration mergedConfig = new MergedContextConfiguration(null, null, null, null, null);
|
||||
assertEquals(mergedConfig, mergedConfig);
|
||||
assertNotEquals(mergedConfig, null);
|
||||
assertNotEquals(mergedConfig, 1);
|
||||
assertThat(mergedConfig).isEqualTo(mergedConfig);
|
||||
assertThat(mergedConfig).isNotEqualTo(null);
|
||||
assertThat(mergedConfig).isNotEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void equalsWithNulls() {
|
||||
MergedContextConfiguration mergedConfig1 = new MergedContextConfiguration(null, null, null, null, null);
|
||||
MergedContextConfiguration mergedConfig2 = new MergedContextConfiguration(null, null, null, null, null);
|
||||
assertEquals(mergedConfig1, mergedConfig2);
|
||||
assertThat(mergedConfig2).isEqualTo(mergedConfig1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void equalsWithNullArrays() {
|
||||
MergedContextConfiguration mergedConfig1 = new MergedContextConfiguration(getClass(), null, null, null, loader);
|
||||
MergedContextConfiguration mergedConfig2 = new MergedContextConfiguration(getClass(), null, null, null, loader);
|
||||
assertEquals(mergedConfig1, mergedConfig2);
|
||||
assertThat(mergedConfig2).isEqualTo(mergedConfig1);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -265,7 +264,7 @@ public class MergedContextConfigurationTests {
|
||||
EMPTY_STRING_ARRAY, EMPTY_CLASS_ARRAY, EMPTY_STRING_ARRAY, loader);
|
||||
MergedContextConfiguration mergedConfig2 = new MergedContextConfiguration(getClass(),
|
||||
EMPTY_STRING_ARRAY, EMPTY_CLASS_ARRAY, EMPTY_STRING_ARRAY, loader);
|
||||
assertEquals(mergedConfig1, mergedConfig2);
|
||||
assertThat(mergedConfig2).isEqualTo(mergedConfig1);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -274,8 +273,8 @@ public class MergedContextConfigurationTests {
|
||||
EMPTY_STRING_ARRAY, EMPTY_CLASS_ARRAY, EMPTY_STRING_ARRAY, loader);
|
||||
MergedContextConfiguration mergedConfig2 = new MergedContextConfiguration(getClass(),
|
||||
EMPTY_STRING_ARRAY, EMPTY_CLASS_ARRAY, EMPTY_STRING_ARRAY, new AnnotationConfigContextLoader());
|
||||
assertNotEquals(mergedConfig1, mergedConfig2);
|
||||
assertNotEquals(mergedConfig2, mergedConfig1);
|
||||
assertThat(mergedConfig2).isNotEqualTo(mergedConfig1);
|
||||
assertThat(mergedConfig1).isNotEqualTo(mergedConfig2);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -285,7 +284,7 @@ public class MergedContextConfigurationTests {
|
||||
locations, EMPTY_CLASS_ARRAY, EMPTY_STRING_ARRAY, loader);
|
||||
MergedContextConfiguration mergedConfig2 = new MergedContextConfiguration(getClass(),
|
||||
locations, EMPTY_CLASS_ARRAY, EMPTY_STRING_ARRAY, loader);
|
||||
assertEquals(mergedConfig1, mergedConfig2);
|
||||
assertThat(mergedConfig2).isEqualTo(mergedConfig1);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -296,8 +295,8 @@ public class MergedContextConfigurationTests {
|
||||
locations1, EMPTY_CLASS_ARRAY, EMPTY_STRING_ARRAY, loader);
|
||||
MergedContextConfiguration mergedConfig2 = new MergedContextConfiguration(getClass(),
|
||||
locations2, EMPTY_CLASS_ARRAY, EMPTY_STRING_ARRAY, loader);
|
||||
assertNotEquals(mergedConfig1, mergedConfig2);
|
||||
assertNotEquals(mergedConfig2, mergedConfig1);
|
||||
assertThat(mergedConfig2).isNotEqualTo(mergedConfig1);
|
||||
assertThat(mergedConfig1).isNotEqualTo(mergedConfig2);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -307,7 +306,7 @@ public class MergedContextConfigurationTests {
|
||||
EMPTY_STRING_ARRAY, classes, EMPTY_STRING_ARRAY, loader);
|
||||
MergedContextConfiguration mergedConfig2 = new MergedContextConfiguration(getClass(),
|
||||
EMPTY_STRING_ARRAY, classes, EMPTY_STRING_ARRAY, loader);
|
||||
assertEquals(mergedConfig1, mergedConfig2);
|
||||
assertThat(mergedConfig2).isEqualTo(mergedConfig1);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -318,8 +317,8 @@ public class MergedContextConfigurationTests {
|
||||
EMPTY_STRING_ARRAY, classes1, EMPTY_STRING_ARRAY, loader);
|
||||
MergedContextConfiguration mergedConfig2 = new MergedContextConfiguration(getClass(),
|
||||
EMPTY_STRING_ARRAY, classes2, EMPTY_STRING_ARRAY, loader);
|
||||
assertNotEquals(mergedConfig1, mergedConfig2);
|
||||
assertNotEquals(mergedConfig2, mergedConfig1);
|
||||
assertThat(mergedConfig2).isNotEqualTo(mergedConfig1);
|
||||
assertThat(mergedConfig1).isNotEqualTo(mergedConfig2);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -329,7 +328,7 @@ public class MergedContextConfigurationTests {
|
||||
EMPTY_STRING_ARRAY, EMPTY_CLASS_ARRAY, activeProfiles, loader);
|
||||
MergedContextConfiguration mergedConfig2 = new MergedContextConfiguration(getClass(),
|
||||
EMPTY_STRING_ARRAY, EMPTY_CLASS_ARRAY, activeProfiles, loader);
|
||||
assertEquals(mergedConfig1, mergedConfig2);
|
||||
assertThat(mergedConfig2).isEqualTo(mergedConfig1);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -340,7 +339,7 @@ public class MergedContextConfigurationTests {
|
||||
EMPTY_STRING_ARRAY, EMPTY_CLASS_ARRAY, activeProfiles1, loader);
|
||||
MergedContextConfiguration mergedConfig2 = new MergedContextConfiguration(getClass(),
|
||||
EMPTY_STRING_ARRAY, EMPTY_CLASS_ARRAY, activeProfiles2, loader);
|
||||
assertNotEquals(mergedConfig1, mergedConfig2);
|
||||
assertThat(mergedConfig2).isNotEqualTo(mergedConfig1);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -351,7 +350,7 @@ public class MergedContextConfigurationTests {
|
||||
EMPTY_STRING_ARRAY, EMPTY_CLASS_ARRAY, activeProfiles1, loader);
|
||||
MergedContextConfiguration mergedConfig2 = new MergedContextConfiguration(getClass(),
|
||||
EMPTY_STRING_ARRAY, EMPTY_CLASS_ARRAY, activeProfiles2, loader);
|
||||
assertEquals(mergedConfig1, mergedConfig2);
|
||||
assertThat(mergedConfig2).isEqualTo(mergedConfig1);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -362,8 +361,8 @@ public class MergedContextConfigurationTests {
|
||||
EMPTY_STRING_ARRAY, EMPTY_CLASS_ARRAY, activeProfiles1, loader);
|
||||
MergedContextConfiguration mergedConfig2 = new MergedContextConfiguration(getClass(),
|
||||
EMPTY_STRING_ARRAY, EMPTY_CLASS_ARRAY, activeProfiles2, loader);
|
||||
assertNotEquals(mergedConfig1, mergedConfig2);
|
||||
assertNotEquals(mergedConfig2, mergedConfig1);
|
||||
assertThat(mergedConfig2).isNotEqualTo(mergedConfig1);
|
||||
assertThat(mergedConfig1).isNotEqualTo(mergedConfig2);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -382,7 +381,7 @@ public class MergedContextConfigurationTests {
|
||||
EMPTY_STRING_ARRAY, EMPTY_CLASS_ARRAY, initializerClasses1, EMPTY_STRING_ARRAY, loader);
|
||||
MergedContextConfiguration mergedConfig2 = new MergedContextConfiguration(getClass(),
|
||||
EMPTY_STRING_ARRAY, EMPTY_CLASS_ARRAY, initializerClasses2, EMPTY_STRING_ARRAY, loader);
|
||||
assertEquals(mergedConfig1, mergedConfig2);
|
||||
assertThat(mergedConfig2).isEqualTo(mergedConfig1);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -399,8 +398,8 @@ public class MergedContextConfigurationTests {
|
||||
EMPTY_STRING_ARRAY, EMPTY_CLASS_ARRAY, initializerClasses1, EMPTY_STRING_ARRAY, loader);
|
||||
MergedContextConfiguration mergedConfig2 = new MergedContextConfiguration(getClass(),
|
||||
EMPTY_STRING_ARRAY, EMPTY_CLASS_ARRAY, initializerClasses2, EMPTY_STRING_ARRAY, loader);
|
||||
assertNotEquals(mergedConfig1, mergedConfig2);
|
||||
assertNotEquals(mergedConfig2, mergedConfig1);
|
||||
assertThat(mergedConfig2).isNotEqualTo(mergedConfig1);
|
||||
assertThat(mergedConfig1).isNotEqualTo(mergedConfig2);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -413,7 +412,7 @@ public class MergedContextConfigurationTests {
|
||||
EMPTY_CLASS_ARRAY, null, EMPTY_STRING_ARRAY, null, null, customizers, loader, null, null);
|
||||
MergedContextConfiguration mergedConfig2 = new MergedContextConfiguration(getClass(), EMPTY_STRING_ARRAY,
|
||||
EMPTY_CLASS_ARRAY, null, EMPTY_STRING_ARRAY, null, null, customizers, loader, null, null);
|
||||
assertEquals(mergedConfig1, mergedConfig2);
|
||||
assertThat(mergedConfig2).isEqualTo(mergedConfig1);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -428,8 +427,8 @@ public class MergedContextConfigurationTests {
|
||||
EMPTY_CLASS_ARRAY, null, EMPTY_STRING_ARRAY, null, null, customizers1, loader, null, null);
|
||||
MergedContextConfiguration mergedConfig2 = new MergedContextConfiguration(getClass(), EMPTY_STRING_ARRAY,
|
||||
EMPTY_CLASS_ARRAY, null, EMPTY_STRING_ARRAY, null, null, customizers2, loader, null, null);
|
||||
assertNotEquals(mergedConfig1, mergedConfig2);
|
||||
assertNotEquals(mergedConfig2, mergedConfig1);
|
||||
assertThat(mergedConfig2).isNotEqualTo(mergedConfig1);
|
||||
assertThat(mergedConfig1).isNotEqualTo(mergedConfig2);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -444,8 +443,8 @@ public class MergedContextConfigurationTests {
|
||||
EMPTY_CLASS_ARRAY, null, EMPTY_STRING_ARRAY, loader, null, parent);
|
||||
MergedContextConfiguration mergedConfig2 = new MergedContextConfiguration(getClass(), EMPTY_STRING_ARRAY,
|
||||
EMPTY_CLASS_ARRAY, null, EMPTY_STRING_ARRAY, loader, null, parent);
|
||||
assertEquals(mergedConfig1, mergedConfig2);
|
||||
assertEquals(mergedConfig2, mergedConfig1);
|
||||
assertThat(mergedConfig2).isEqualTo(mergedConfig1);
|
||||
assertThat(mergedConfig1).isEqualTo(mergedConfig2);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -462,8 +461,8 @@ public class MergedContextConfigurationTests {
|
||||
EMPTY_CLASS_ARRAY, null, EMPTY_STRING_ARRAY, loader, null, parent1);
|
||||
MergedContextConfiguration mergedConfig2 = new MergedContextConfiguration(getClass(), EMPTY_STRING_ARRAY,
|
||||
EMPTY_CLASS_ARRAY, null, EMPTY_STRING_ARRAY, loader, null, parent2);
|
||||
assertNotEquals(mergedConfig1, mergedConfig2);
|
||||
assertNotEquals(mergedConfig2, mergedConfig1);
|
||||
assertThat(mergedConfig2).isNotEqualTo(mergedConfig1);
|
||||
assertThat(mergedConfig1).isNotEqualTo(mergedConfig2);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -27,7 +27,6 @@ import org.junit.Test;
|
||||
import static java.util.Arrays.stream;
|
||||
import static java.util.stream.Collectors.toCollection;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* Integration tests that verify proper concurrency support between a
|
||||
@@ -77,7 +76,7 @@ public class TestContextConcurrencyTests {
|
||||
});
|
||||
assertThat(actualMethods).isEqualTo(expectedMethods);
|
||||
});
|
||||
assertEquals(0, tcm.getTestContext().attributeNames().length);
|
||||
assertThat(tcm.getTestContext().attributeNames().length).isEqualTo(0);
|
||||
}
|
||||
|
||||
|
||||
@@ -131,7 +130,7 @@ public class TestContextConcurrencyTests {
|
||||
|
||||
@Override
|
||||
public void afterTestMethod(TestContext testContext) throws Exception {
|
||||
assertEquals(this.methodName.get(), testContext.getAttribute("method"));
|
||||
assertThat(testContext.getAttribute("method")).isEqualTo(this.methodName.get());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -22,8 +22,7 @@ import org.junit.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.assertj.core.api.Assertions.fail;
|
||||
|
||||
/**
|
||||
* JUnit 4 based unit tests for {@link TestContextManager}, which verify proper
|
||||
@@ -55,7 +54,7 @@ public class TestContextManagerSuppressedExceptionsTests {
|
||||
|
||||
private void test(String useCase, Class<?> testClass, Callback callback) throws Exception {
|
||||
TestContextManager testContextManager = new TestContextManager(testClass);
|
||||
assertEquals("Registered TestExecutionListeners", 2, testContextManager.getTestExecutionListeners().size());
|
||||
assertThat(testContextManager.getTestExecutionListeners().size()).as("Registered TestExecutionListeners").isEqualTo(2);
|
||||
|
||||
assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> {
|
||||
Method testMethod = getClass().getMethod("toString");
|
||||
|
||||
@@ -23,7 +23,7 @@ import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* JUnit 4 based unit test for {@link TestContextManager}, which verifies proper
|
||||
@@ -53,7 +53,7 @@ public class TestContextManagerTests {
|
||||
@Test
|
||||
public void listenerExecutionOrder() throws Exception {
|
||||
// @formatter:off
|
||||
assertEquals("Registered TestExecutionListeners", 3, this.testContextManager.getTestExecutionListeners().size());
|
||||
assertThat(this.testContextManager.getTestExecutionListeners().size()).as("Registered TestExecutionListeners").isEqualTo(3);
|
||||
|
||||
this.testContextManager.beforeTestMethod(this, this.testMethod);
|
||||
assertExecutionOrder("beforeTestMethod",
|
||||
@@ -104,8 +104,7 @@ public class TestContextManagerTests {
|
||||
}
|
||||
|
||||
private static void assertExecutionOrder(String usageContext, String... expectedBeforeTestMethodCalls) {
|
||||
assertEquals("execution order (" + usageContext + ") ==>", Arrays.asList(expectedBeforeTestMethodCalls),
|
||||
executionOrder);
|
||||
assertThat(executionOrder).as("execution order (" + usageContext + ") ==>").isEqualTo(Arrays.asList(expectedBeforeTestMethodCalls));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -35,8 +35,8 @@ import org.springframework.test.context.web.ServletTestExecutionListener;
|
||||
|
||||
import static java.util.Arrays.asList;
|
||||
import static java.util.stream.Collectors.toList;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.springframework.test.context.TestExecutionListeners.MergeMode.MERGE_WITH_DEFAULTS;
|
||||
|
||||
/**
|
||||
@@ -182,14 +182,12 @@ public class TestExecutionListenersTests {
|
||||
|
||||
private void assertRegisteredListeners(Class<?> testClass, List<Class<?>> expected) {
|
||||
TestContextManager testContextManager = new TestContextManager(testClass);
|
||||
assertEquals("TELs registered for " + testClass.getSimpleName(), names(expected),
|
||||
names(classes(testContextManager)));
|
||||
assertThat(names(classes(testContextManager))).as("TELs registered for " + testClass.getSimpleName()).isEqualTo(names(expected));
|
||||
}
|
||||
|
||||
private void assertNumRegisteredListeners(Class<?> testClass, int expected) {
|
||||
TestContextManager testContextManager = new TestContextManager(testClass);
|
||||
assertEquals("Num registered TELs for " + testClass, expected,
|
||||
testContextManager.getTestExecutionListeners().size());
|
||||
assertThat(testContextManager.getTestExecutionListeners().size()).as("Num registered TELs for " + testClass).isEqualTo(expected);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ import org.springframework.test.context.support.DirtiesContextTestExecutionListe
|
||||
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
|
||||
import org.springframework.test.context.testng.TrackingTestNGTestListener;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.springframework.test.context.cache.ContextCacheTestUtils.assertContextCacheStatistics;
|
||||
import static org.springframework.test.context.cache.ContextCacheTestUtils.resetContextCache;
|
||||
|
||||
@@ -148,12 +148,9 @@ public class ClassLevelDirtiesContextTestNGTests {
|
||||
testNG.setVerbose(0);
|
||||
testNG.run();
|
||||
|
||||
assertEquals("Failures for test class [" + testClass + "].", expectedTestFailureCount,
|
||||
listener.testFailureCount);
|
||||
assertEquals("Tests started for test class [" + testClass + "].", expectedTestStartedCount,
|
||||
listener.testStartCount);
|
||||
assertEquals("Successful tests for test class [" + testClass + "].", expectedTestFinishedCount,
|
||||
listener.testSuccessCount);
|
||||
assertThat(listener.testFailureCount).as("Failures for test class [" + testClass + "].").isEqualTo(expectedTestFailureCount);
|
||||
assertThat(listener.testStartCount).as("Tests started for test class [" + testClass + "].").isEqualTo(expectedTestStartedCount);
|
||||
assertThat(listener.testSuccessCount).as("Successful tests for test class [" + testClass + "].").isEqualTo(expectedTestFinishedCount);
|
||||
}
|
||||
|
||||
private void assertBehaviorForCleanTestCase() {
|
||||
|
||||
@@ -35,7 +35,7 @@ import org.springframework.test.context.support.DependencyInjectionTestExecution
|
||||
import org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener;
|
||||
import org.springframework.test.context.support.DirtiesContextTestExecutionListener;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.springframework.test.context.cache.ContextCacheTestUtils.assertContextCacheStatistics;
|
||||
import static org.springframework.test.context.cache.ContextCacheTestUtils.resetContextCache;
|
||||
import static org.springframework.test.context.junit4.JUnitTestingUtils.runTestsAndAssertCounters;
|
||||
@@ -170,7 +170,7 @@ public class ClassLevelDirtiesContextTests {
|
||||
|
||||
|
||||
protected void assertApplicationContextWasAutowired() {
|
||||
assertNotNull("The application context should have been autowired.", this.applicationContext);
|
||||
assertThat(this.applicationContext).as("The application context should have been autowired.").isNotNull();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
package org.springframework.test.context.cache;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Collection of utility methods for testing scenarios involving the
|
||||
@@ -60,12 +60,9 @@ public class ContextCacheTestUtils {
|
||||
public static final void assertContextCacheStatistics(ContextCache contextCache, String usageScenario,
|
||||
int expectedSize, int expectedHitCount, int expectedMissCount) {
|
||||
|
||||
assertEquals("Verifying number of contexts in cache (" + usageScenario + ").", expectedSize,
|
||||
contextCache.size());
|
||||
assertEquals("Verifying number of cache hits (" + usageScenario + ").", expectedHitCount,
|
||||
contextCache.getHitCount());
|
||||
assertEquals("Verifying number of cache misses (" + usageScenario + ").", expectedMissCount,
|
||||
contextCache.getMissCount());
|
||||
assertThat(contextCache.size()).as("Verifying number of contexts in cache (" + usageScenario + ").").isEqualTo(expectedSize);
|
||||
assertThat(contextCache.getHitCount()).as("Verifying number of cache hits (" + usageScenario + ").").isEqualTo(expectedHitCount);
|
||||
assertThat(contextCache.getMissCount()).as("Verifying number of cache misses (" + usageScenario + ").").isEqualTo(expectedMissCount);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -32,8 +32,7 @@ import org.springframework.test.context.TestContextTestUtils;
|
||||
import org.springframework.test.context.support.AnnotationConfigContextLoader;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.springframework.test.context.cache.ContextCacheTestUtils.assertContextCacheStatistics;
|
||||
|
||||
/**
|
||||
@@ -58,7 +57,7 @@ public class ContextCacheTests {
|
||||
}
|
||||
|
||||
private void assertParentContextCount(int expected) {
|
||||
assertEquals("parent context count", expected, contextCache.getParentContextCount());
|
||||
assertThat(contextCache.getParentContextCount()).as("parent context count").isEqualTo(expected);
|
||||
}
|
||||
|
||||
private MergedContextConfiguration getMergedContextConfiguration(TestContext testContext) {
|
||||
@@ -71,7 +70,7 @@ public class ContextCacheTests {
|
||||
}
|
||||
|
||||
private void loadCtxAndAssertStats(Class<?> testClass, int expectedSize, int expectedHitCount, int expectedMissCount) {
|
||||
assertNotNull(loadContext(testClass));
|
||||
assertThat(loadContext(testClass)).isNotNull();
|
||||
assertContextCacheStatistics(contextCache, testClass.getName(), expectedSize, expectedHitCount,
|
||||
expectedMissCount);
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ import org.junit.Test;
|
||||
|
||||
import org.springframework.core.SpringProperties;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.springframework.test.context.cache.ContextCache.DEFAULT_MAX_CONTEXT_CACHE_SIZE;
|
||||
import static org.springframework.test.context.cache.ContextCache.MAX_CONTEXT_CACHE_SIZE_PROPERTY_NAME;
|
||||
import static org.springframework.test.context.cache.ContextCacheUtils.retrieveMaxCacheSize;
|
||||
@@ -68,23 +68,23 @@ public class ContextCacheUtilsTests {
|
||||
@Test
|
||||
public void retrieveMaxCacheSizeFromSystemProperty() {
|
||||
System.setProperty(MAX_CONTEXT_CACHE_SIZE_PROPERTY_NAME, "42");
|
||||
assertEquals(42, retrieveMaxCacheSize());
|
||||
assertThat(retrieveMaxCacheSize()).isEqualTo(42);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void retrieveMaxCacheSizeFromSystemPropertyContainingWhitespace() {
|
||||
System.setProperty(MAX_CONTEXT_CACHE_SIZE_PROPERTY_NAME, "42\t");
|
||||
assertEquals(42, retrieveMaxCacheSize());
|
||||
assertThat(retrieveMaxCacheSize()).isEqualTo(42);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void retrieveMaxCacheSizeFromSpringProperty() {
|
||||
SpringProperties.setProperty(MAX_CONTEXT_CACHE_SIZE_PROPERTY_NAME, "99");
|
||||
assertEquals(99, retrieveMaxCacheSize());
|
||||
assertThat(retrieveMaxCacheSize()).isEqualTo(99);
|
||||
}
|
||||
|
||||
private static void assertDefaultValue() {
|
||||
assertEquals(DEFAULT_MAX_CONTEXT_CACHE_SIZE, retrieveMaxCacheSize());
|
||||
assertThat(retrieveMaxCacheSize()).isEqualTo(DEFAULT_MAX_CONTEXT_CACHE_SIZE);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -28,8 +28,8 @@ import org.springframework.test.util.ReflectionTestUtils;
|
||||
|
||||
import static java.util.Arrays.asList;
|
||||
import static java.util.stream.Collectors.toList;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.times;
|
||||
@@ -71,8 +71,8 @@ public class LruContextCacheTests {
|
||||
@Test
|
||||
public void maxCacheSizeOne() {
|
||||
DefaultContextCache cache = new DefaultContextCache(1);
|
||||
assertEquals(0, cache.size());
|
||||
assertEquals(1, cache.getMaxSize());
|
||||
assertThat(cache.size()).isEqualTo(0);
|
||||
assertThat(cache.getMaxSize()).isEqualTo(1);
|
||||
|
||||
cache.put(fooConfig, fooContext);
|
||||
assertCacheContents(cache, "Foo");
|
||||
@@ -90,8 +90,8 @@ public class LruContextCacheTests {
|
||||
@Test
|
||||
public void maxCacheSizeThree() {
|
||||
DefaultContextCache cache = new DefaultContextCache(3);
|
||||
assertEquals(0, cache.size());
|
||||
assertEquals(3, cache.getMaxSize());
|
||||
assertThat(cache.size()).isEqualTo(0);
|
||||
assertThat(cache.getMaxSize()).isEqualTo(3);
|
||||
|
||||
cache.put(fooConfig, fooContext);
|
||||
assertCacheContents(cache, "Foo");
|
||||
@@ -171,7 +171,7 @@ public class LruContextCacheTests {
|
||||
.collect(toList());
|
||||
// @formatter:on
|
||||
|
||||
assertEquals(asList(expectedNames), actualNames);
|
||||
assertThat(actualNames).isEqualTo(asList(expectedNames));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -34,9 +34,7 @@ import org.springframework.test.context.support.DependencyInjectionTestExecution
|
||||
import org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener;
|
||||
import org.springframework.test.context.support.DirtiesContextTestExecutionListener;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.springframework.test.annotation.DirtiesContext.MethodMode.BEFORE_METHOD;
|
||||
|
||||
/**
|
||||
@@ -101,13 +99,13 @@ public class MethodLevelDirtiesContextTests {
|
||||
}
|
||||
|
||||
private void performAssertions(int expectedContextCreationCount) throws Exception {
|
||||
assertNotNull("context must not be null", this.context);
|
||||
assertTrue("context must be active", this.context.isActive());
|
||||
assertThat(this.context).as("context must not be null").isNotNull();
|
||||
assertThat(this.context.isActive()).as("context must be active").isTrue();
|
||||
|
||||
assertNotNull("count must not be null", this.count);
|
||||
assertEquals("count: ", expectedContextCreationCount, this.count.intValue());
|
||||
assertThat(this.count).as("count must not be null").isNotNull();
|
||||
assertThat(this.count.intValue()).as("count: ").isEqualTo(expectedContextCreationCount);
|
||||
|
||||
assertEquals("context creation count: ", expectedContextCreationCount, contextCount.get());
|
||||
assertThat(contextCount.get()).as("context creation count: ").isEqualTo(expectedContextCreationCount);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -32,9 +32,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.context.support.DependencyInjectionTestExecutionListener;
|
||||
import org.springframework.test.context.support.DirtiesContextTestExecutionListener;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNotSame;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.springframework.test.context.cache.ContextCacheTestUtils.assertContextCacheStatistics;
|
||||
import static org.springframework.test.context.cache.ContextCacheTestUtils.resetContextCache;
|
||||
|
||||
@@ -77,25 +75,23 @@ public class SpringRunnerContextCacheTests {
|
||||
@DirtiesContext
|
||||
public void dirtyContext() {
|
||||
assertContextCacheStatistics("dirtyContext()", 1, 0, 1);
|
||||
assertNotNull("The application context should have been autowired.", this.applicationContext);
|
||||
assertThat(this.applicationContext).as("The application context should have been autowired.").isNotNull();
|
||||
SpringRunnerContextCacheTests.dirtiedApplicationContext = this.applicationContext;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void verifyContextDirty() {
|
||||
assertContextCacheStatistics("verifyContextWasDirtied()", 1, 0, 2);
|
||||
assertNotNull("The application context should have been autowired.", this.applicationContext);
|
||||
assertNotSame("The application context should have been 'dirtied'.",
|
||||
SpringRunnerContextCacheTests.dirtiedApplicationContext, this.applicationContext);
|
||||
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;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void verifyContextNotDirty() {
|
||||
assertContextCacheStatistics("verifyContextWasNotDirtied()", 1, 1, 2);
|
||||
assertNotNull("The application context should have been autowired.", this.applicationContext);
|
||||
assertSame("The application context should NOT have been 'dirtied'.",
|
||||
SpringRunnerContextCacheTests.dirtiedApplicationContext, this.applicationContext);
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -24,8 +24,7 @@ import org.springframework.test.context.ContextLoader;
|
||||
import org.springframework.test.context.junit4.PropertiesBasedSpringJUnit4ClassRunnerAppCtxTests;
|
||||
import org.springframework.tests.sample.beans.Pet;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Integration tests which verify that the same custom {@link ContextLoader} can
|
||||
@@ -51,11 +50,11 @@ public class ContextConfigurationWithPropertiesExtendingPropertiesAndInheritedLo
|
||||
|
||||
@Test
|
||||
public void verifyExtendedAnnotationAutowiredFields() {
|
||||
assertNotNull("The dog field should have been autowired.", this.dog);
|
||||
assertEquals("Fido", this.dog.getName());
|
||||
assertThat(this.dog).as("The dog field should have been autowired.").isNotNull();
|
||||
assertThat(this.dog.getName()).isEqualTo("Fido");
|
||||
|
||||
assertNotNull("The testString2 field should have been autowired.", this.testString2);
|
||||
assertEquals("Test String #2", this.testString2);
|
||||
assertThat(this.testString2).as("The testString2 field should have been autowired.").isNotNull();
|
||||
assertThat(this.testString2).isEqualTo("Test String #2");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -25,8 +25,7 @@ import org.springframework.test.context.junit4.PropertiesBasedSpringJUnit4ClassR
|
||||
import org.springframework.test.context.support.GenericPropertiesContextLoader;
|
||||
import org.springframework.tests.sample.beans.Pet;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Integration tests which verify that the same custom {@link ContextLoader} can
|
||||
@@ -52,11 +51,11 @@ public class ContextConfigurationWithPropertiesExtendingPropertiesTests extends
|
||||
|
||||
@Test
|
||||
public void verifyExtendedAnnotationAutowiredFields() {
|
||||
assertNotNull("The dog field should have been autowired.", this.dog);
|
||||
assertEquals("Fido", this.dog.getName());
|
||||
assertThat(this.dog).as("The dog field should have been autowired.").isNotNull();
|
||||
assertThat(this.dog.getName()).isEqualTo("Fido");
|
||||
|
||||
assertNotNull("The testString2 field should have been autowired.", this.testString2);
|
||||
assertEquals("Test String #2", this.testString2);
|
||||
assertThat(this.testString2).as("The testString2 field should have been autowired.").isNotNull();
|
||||
assertThat(this.testString2).isEqualTo("Test String #2");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -26,8 +26,7 @@ import org.springframework.context.annotation.Profile;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.tests.sample.beans.Employee;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* @author Sam Brannen
|
||||
@@ -42,8 +41,8 @@ public class ActiveProfilesInterfaceTests implements ActiveProfilesTestInterface
|
||||
|
||||
@Test
|
||||
public void profileFromTestInterface() {
|
||||
assertNotNull(employee);
|
||||
assertEquals("dev", employee.getName());
|
||||
assertThat(employee).isNotNull();
|
||||
assertThat(employee.getName()).isEqualTo("dev");
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* @author Sam Brannen
|
||||
@@ -37,7 +37,7 @@ public class BootstrapWithInterfaceTests implements BootstrapWithTestInterface {
|
||||
|
||||
@Test
|
||||
public void injectedBean() {
|
||||
assertEquals("foo", foo);
|
||||
assertThat(foo).isEqualTo("foo");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -23,8 +23,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.tests.sample.beans.Employee;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* @author Sam Brannen
|
||||
@@ -39,8 +38,8 @@ public class ContextConfigurationInterfaceTests implements ContextConfigurationT
|
||||
|
||||
@Test
|
||||
public void profileFromTestInterface() {
|
||||
assertNotNull(employee);
|
||||
assertEquals("Dilbert", employee.getName());
|
||||
assertThat(employee).isNotNull();
|
||||
assertThat(employee.getName()).isEqualTo("Dilbert");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -23,9 +23,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* @author Sam Brannen
|
||||
@@ -49,12 +47,12 @@ public class ContextHierarchyInterfaceTests implements ContextHierarchyTestInter
|
||||
|
||||
@Test
|
||||
public void loadContextHierarchy() {
|
||||
assertNotNull("child ApplicationContext", context);
|
||||
assertNotNull("parent ApplicationContext", context.getParent());
|
||||
assertNull("grandparent ApplicationContext", context.getParent().getParent());
|
||||
assertEquals("foo", foo);
|
||||
assertEquals("bar", bar);
|
||||
assertEquals("baz-child", baz);
|
||||
assertThat(context).as("child ApplicationContext").isNotNull();
|
||||
assertThat(context.getParent()).as("parent ApplicationContext").isNotNull();
|
||||
assertThat(context.getParent().getParent()).as("grandparent ApplicationContext").isNull();
|
||||
assertThat(foo).isEqualTo("foo");
|
||||
assertThat(bar).isEqualTo("bar");
|
||||
assertThat(baz).isEqualTo("baz-child");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ import org.springframework.test.context.support.DependencyInjectionTestExecution
|
||||
import org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener;
|
||||
import org.springframework.test.context.support.DirtiesContextTestExecutionListener;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.springframework.test.context.cache.ContextCacheTestUtils.assertContextCacheStatistics;
|
||||
import static org.springframework.test.context.cache.ContextCacheTestUtils.resetContextCache;
|
||||
import static org.springframework.test.context.junit4.JUnitTestingUtils.runTestsAndAssertCounters;
|
||||
@@ -92,7 +92,7 @@ public class DirtiesContextInterfaceTests {
|
||||
|
||||
@Test
|
||||
public void verifyContextWasAutowired() {
|
||||
assertNotNull("The application context should have been autowired.", this.applicationContext);
|
||||
assertThat(this.applicationContext).as("The application context should have been autowired.").isNotNull();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ import org.springframework.test.context.jdbc.Sql;
|
||||
import org.springframework.test.context.jdbc.SqlConfig;
|
||||
import org.springframework.test.context.junit4.AbstractTransactionalJUnit4SpringContextTests;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* @author Sam Brannen
|
||||
@@ -40,7 +40,7 @@ public class SqlConfigInterfaceTests extends AbstractTransactionalJUnit4SpringCo
|
||||
}
|
||||
|
||||
protected void assertNumUsers(int expected) {
|
||||
assertEquals("Number of rows in the 'user' table.", expected, countRowsInTable("user"));
|
||||
assertThat(countRowsInTable("user")).as("Number of rows in the 'user' table.").isEqualTo(expected);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.web.context.WebApplicationContext;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* @author Sam Brannen
|
||||
@@ -38,7 +38,7 @@ public class WebAppConfigurationInterfaceTests implements WebAppConfigurationTes
|
||||
|
||||
@Test
|
||||
public void wacLoaded() {
|
||||
assertNotNull(wac);
|
||||
assertThat(wac).isNotNull();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.TestPropertySource;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Integration tests for {@link TestPropertySource @TestPropertySource}
|
||||
@@ -50,7 +50,7 @@ public class ApplicationPropertyOverridePropertiesFileTestPropertySourceTests {
|
||||
|
||||
@Test
|
||||
public void verifyPropertiesAreAvailableInEnvironment() {
|
||||
assertEquals("test override", env.getProperty("explicit"));
|
||||
assertThat(env.getProperty("explicit")).isEqualTo("test override");
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.TestPropertySource;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Integration tests that verify detection of a default properties file
|
||||
@@ -51,7 +51,7 @@ public class DefaultPropertiesFileDetectionTestPropertySourceTests {
|
||||
}
|
||||
|
||||
protected void assertEnvironmentValue(String key, String expected) {
|
||||
assertEquals("Value of key [" + key + "].", expected, env.getProperty(key));
|
||||
assertThat(env.getProperty(key)).as("Value of key [" + key + "].").isEqualTo(expected);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.TestPropertySource;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Integration tests for {@link TestPropertySource @TestPropertySource}
|
||||
@@ -47,8 +47,8 @@ public class ExplicitPropertiesFileTestPropertySourceTests {
|
||||
@Test
|
||||
public void verifyPropertiesAreAvailableInEnvironment() {
|
||||
String userHomeKey = "user.home";
|
||||
assertEquals(System.getProperty(userHomeKey), env.getProperty(userHomeKey));
|
||||
assertEquals("enigma", env.getProperty("explicit"));
|
||||
assertThat(env.getProperty(userHomeKey)).isEqualTo(System.getProperty(userHomeKey));
|
||||
assertThat(env.getProperty("explicit")).isEqualTo("enigma");
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.TestPropertySource;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Integration tests for {@link TestPropertySource @TestPropertySource} support with
|
||||
@@ -50,8 +50,8 @@ public class InlinedPropertiesOverridePropertiesFilesTestPropertySourceTests {
|
||||
|
||||
@Test
|
||||
public void inlinedPropertyOverridesValueFromPropertiesFile() {
|
||||
assertEquals("inlined", env.getProperty("explicit"));
|
||||
assertEquals("inlined", this.explicit);
|
||||
assertThat(env.getProperty("explicit")).isEqualTo("inlined");
|
||||
assertThat(this.explicit).isEqualTo("inlined");
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -28,7 +28,6 @@ import org.springframework.test.context.TestPropertySource;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.springframework.test.context.support.TestPropertySourceUtils.INLINED_PROPERTIES_PROPERTY_SOURCE_NAME;
|
||||
|
||||
/**
|
||||
@@ -74,7 +73,7 @@ public class InlinedPropertiesTestPropertySourceTests {
|
||||
"key.value.1", "key.value.2", "key.value.3" };
|
||||
EnumerablePropertySource eps = (EnumerablePropertySource) env.getPropertySources().get(
|
||||
INLINED_PROPERTIES_PROPERTY_SOURCE_NAME);
|
||||
assertArrayEquals(expectedPropertyNames, eps.getPropertyNames());
|
||||
assertThat(eps.getPropertyNames()).isEqualTo(expectedPropertyNames);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ import org.junit.Test;
|
||||
|
||||
import org.springframework.test.context.TestPropertySource;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Integration tests that verify support for overriding properties from
|
||||
@@ -37,13 +37,13 @@ public class MergedPropertiesFilesOverriddenByInlinedPropertiesTestPropertySourc
|
||||
@Test
|
||||
@Override
|
||||
public void verifyPropertiesAreAvailableInEnvironment() {
|
||||
assertEquals("inlined", env.getProperty("explicit"));
|
||||
assertThat(env.getProperty("explicit")).isEqualTo("inlined");
|
||||
}
|
||||
|
||||
@Test
|
||||
@Override
|
||||
public void verifyExtendedPropertiesAreAvailableInEnvironment() {
|
||||
assertEquals("inlined2", env.getProperty("extended"));
|
||||
assertThat(env.getProperty("extended")).isEqualTo("inlined2");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ import org.junit.Test;
|
||||
|
||||
import org.springframework.test.context.TestPropertySource;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Integration tests that verify support for contributing additional properties
|
||||
@@ -35,7 +35,7 @@ public class MergedPropertiesFilesTestPropertySourceTests extends
|
||||
|
||||
@Test
|
||||
public void verifyExtendedPropertiesAreAvailableInEnvironment() {
|
||||
assertEquals(42, env.getProperty("extended", Integer.class).intValue());
|
||||
assertThat(env.getProperty("extended", Integer.class).intValue()).isEqualTo(42);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.TestPropertySource;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Integration tests for {@link TestPropertySource @TestPropertySource}
|
||||
@@ -61,7 +61,7 @@ public class SystemPropertyOverridePropertiesFileTestPropertySourceTests {
|
||||
|
||||
@Test
|
||||
public void verifyPropertiesAreAvailableInEnvironment() {
|
||||
assertEquals("enigma", env.getProperty(KEY));
|
||||
assertThat(env.getProperty(KEY)).isEqualTo("enigma");
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* @author Andy Clement
|
||||
@@ -52,18 +52,18 @@ public class ExpressionUsageTests {
|
||||
@Test
|
||||
public void testSpr5906() throws Exception {
|
||||
// verify the property values have been evaluated as expressions
|
||||
assertEquals("Dave", props.getProperty("user.name"));
|
||||
assertEquals("Andy", props.getProperty("username"));
|
||||
assertThat(props.getProperty("user.name")).isEqualTo("Dave");
|
||||
assertThat(props.getProperty("username")).isEqualTo("Andy");
|
||||
|
||||
// verify the property keys have been evaluated as expressions
|
||||
assertEquals("exists", props.getProperty("Dave"));
|
||||
assertEquals("exists also", props.getProperty("Andy"));
|
||||
assertThat(props.getProperty("Dave")).isEqualTo("exists");
|
||||
assertThat(props.getProperty("Andy")).isEqualTo("exists also");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSpr5847() throws Exception {
|
||||
assertEquals("Andy", andy2.getName());
|
||||
assertEquals("Andy", andy.getName());
|
||||
assertThat(andy2.getName()).isEqualTo("Andy");
|
||||
assertThat(andy.getName()).isEqualTo("Andy");
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -25,8 +25,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.tests.sample.beans.Employee;
|
||||
import org.springframework.tests.sample.beans.Pet;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Integration test class that verifies proper detection of a default
|
||||
@@ -53,13 +52,13 @@ public class DefaultScriptDetectionGroovySpringContextTests {
|
||||
|
||||
@Test
|
||||
public final void verifyAnnotationAutowiredFields() {
|
||||
assertNotNull("The employee field should have been autowired.", this.employee);
|
||||
assertEquals("Dilbert", this.employee.getName());
|
||||
assertThat(this.employee).as("The employee field should have been autowired.").isNotNull();
|
||||
assertThat(this.employee.getName()).isEqualTo("Dilbert");
|
||||
|
||||
assertNotNull("The pet field should have been autowired.", this.pet);
|
||||
assertEquals("Dogbert", this.pet.getName());
|
||||
assertThat(this.pet).as("The pet field should have been autowired.").isNotNull();
|
||||
assertThat(this.pet.getName()).isEqualTo("Dogbert");
|
||||
|
||||
assertEquals("The foo field should have been autowired.", "Foo", this.foo);
|
||||
assertThat(this.foo).as("The foo field should have been autowired.").isEqualTo("Foo");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Integration test class that verifies proper detection of a default
|
||||
@@ -42,7 +42,7 @@ public class DefaultScriptDetectionXmlSupersedesGroovySpringContextTests {
|
||||
|
||||
@Test
|
||||
public final void foo() {
|
||||
assertEquals("The foo field should have been autowired.", "Foo", this.foo);
|
||||
assertThat(this.foo).as("The foo field should have been autowired.").isEqualTo("Foo");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -23,8 +23,7 @@ import org.springframework.context.support.GenericGroovyApplicationContext;
|
||||
import org.springframework.tests.sample.beans.Employee;
|
||||
import org.springframework.tests.sample.beans.Pet;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Simple integration test to verify the expected functionality of
|
||||
@@ -47,19 +46,19 @@ public class GroovyControlGroupTests {
|
||||
ApplicationContext ctx = new GenericGroovyApplicationContext(getClass(), "context.groovy");
|
||||
|
||||
String foo = ctx.getBean("foo", String.class);
|
||||
assertEquals("Foo", foo);
|
||||
assertThat(foo).isEqualTo("Foo");
|
||||
|
||||
String bar = ctx.getBean("bar", String.class);
|
||||
assertEquals("Bar", bar);
|
||||
assertThat(bar).isEqualTo("Bar");
|
||||
|
||||
Pet pet = ctx.getBean(Pet.class);
|
||||
assertNotNull("pet", pet);
|
||||
assertEquals("Dogbert", pet.getName());
|
||||
assertThat(pet).as("pet").isNotNull();
|
||||
assertThat(pet.getName()).isEqualTo("Dogbert");
|
||||
|
||||
Employee employee = ctx.getBean(Employee.class);
|
||||
assertNotNull("employee", employee);
|
||||
assertEquals("Dilbert", employee.getName());
|
||||
assertEquals("???", employee.getCompany());
|
||||
assertThat(employee).as("employee").isNotNull();
|
||||
assertThat(employee.getName()).isEqualTo("Dilbert");
|
||||
assertThat(employee.getCompany()).isEqualTo("???");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -30,10 +30,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.tests.sample.beans.Employee;
|
||||
import org.springframework.tests.sample.beans.Pet;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Integration tests for loading an {@code ApplicationContext} from a
|
||||
@@ -90,38 +87,37 @@ public class GroovySpringContextTests implements BeanNameAware, InitializingBean
|
||||
|
||||
@Test
|
||||
public void verifyBeanNameSet() {
|
||||
assertTrue("The bean name of this test instance should have been set to the fully qualified class name " +
|
||||
"due to BeanNameAware semantics.", this.beanName.startsWith(getClass().getName()));
|
||||
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() {
|
||||
assertTrue("This test bean should have been initialized due to InitializingBean semantics.",
|
||||
this.beanInitialized);
|
||||
assertThat(this.beanInitialized).as("This test bean should have been initialized due to InitializingBean semantics.").isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void verifyAnnotationAutowiredFields() {
|
||||
assertNull("The nonrequiredLong property should NOT have been autowired.", this.nonrequiredLong);
|
||||
assertNotNull("The application context should have been autowired.", this.applicationContext);
|
||||
assertNotNull("The pet field should have been autowired.", this.pet);
|
||||
assertEquals("Dogbert", this.pet.getName());
|
||||
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();
|
||||
assertThat(this.pet.getName()).isEqualTo("Dogbert");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void verifyAnnotationAutowiredMethods() {
|
||||
assertNotNull("The employee setter method should have been autowired.", this.employee);
|
||||
assertEquals("Dilbert", this.employee.getName());
|
||||
assertThat(this.employee).as("The employee setter method should have been autowired.").isNotNull();
|
||||
assertThat(this.employee.getName()).isEqualTo("Dilbert");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void verifyResourceAnnotationWiredFields() {
|
||||
assertEquals("The foo field should have been wired via @Resource.", "Foo", this.foo);
|
||||
assertThat(this.foo).as("The foo field should have been wired via @Resource.").isEqualTo("Foo");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void verifyResourceAnnotationWiredMethods() {
|
||||
assertEquals("The bar method should have been wired via @Resource.", "Bar", this.bar);
|
||||
assertThat(this.bar).as("The bar method should have been wired via @Resource.").isEqualTo("Bar");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -25,8 +25,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.tests.sample.beans.Employee;
|
||||
import org.springframework.tests.sample.beans.Pet;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Integration test class that verifies proper support for mixing XML
|
||||
@@ -55,14 +54,14 @@ public class MixedXmlAndGroovySpringContextTests {
|
||||
|
||||
@Test
|
||||
public final void verifyAnnotationAutowiredFields() {
|
||||
assertNotNull("The employee field should have been autowired.", this.employee);
|
||||
assertEquals("Dilbert", this.employee.getName());
|
||||
assertThat(this.employee).as("The employee field should have been autowired.").isNotNull();
|
||||
assertThat(this.employee.getName()).isEqualTo("Dilbert");
|
||||
|
||||
assertNotNull("The pet field should have been autowired.", this.pet);
|
||||
assertEquals("Dogbert", this.pet.getName());
|
||||
assertThat(this.pet).as("The pet field should have been autowired.").isNotNull();
|
||||
assertThat(this.pet.getName()).isEqualTo("Dogbert");
|
||||
|
||||
assertEquals("The foo field should have been autowired.", "Groovy Foo", this.foo);
|
||||
assertEquals("The bar field should have been autowired.", "XML Bar", this.bar);
|
||||
assertThat(this.foo).as("The foo field should have been autowired.").isEqualTo("Groovy Foo");
|
||||
assertThat(this.bar).as("The bar field should have been autowired.").isEqualTo("XML Bar");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* @author Sam Brannen
|
||||
@@ -38,7 +38,7 @@ public class MetaHierarchyLevelOneTests {
|
||||
|
||||
@Test
|
||||
public void foo() {
|
||||
assertEquals("Dev Foo", foo);
|
||||
assertThat(foo).isEqualTo("Dev Foo");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -26,9 +26,7 @@ import org.springframework.context.annotation.Profile;
|
||||
import org.springframework.test.context.ActiveProfiles;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* @author Sam Brannen
|
||||
@@ -58,14 +56,14 @@ public class MetaHierarchyLevelTwoTests extends MetaHierarchyLevelOneTests {
|
||||
|
||||
@Test
|
||||
public void bar() {
|
||||
assertEquals("Prod Bar", bar);
|
||||
assertThat(bar).isEqualTo("Prod Bar");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void contextHierarchy() {
|
||||
assertNotNull("child ApplicationContext", context);
|
||||
assertNotNull("parent ApplicationContext", context.getParent());
|
||||
assertNull("grandparent ApplicationContext", context.getParent().getParent());
|
||||
assertThat(context).as("child ApplicationContext").isNotNull();
|
||||
assertThat(context.getParent()).as("parent ApplicationContext").isNotNull();
|
||||
assertThat(context.getParent().getParent()).as("grandparent ApplicationContext").isNull();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -28,9 +28,7 @@ import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.ContextHierarchy;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* @author Sam Brannen
|
||||
@@ -88,12 +86,12 @@ public class ClassHierarchyWithMergedConfigLevelOneTests {
|
||||
|
||||
@Test
|
||||
public void loadContextHierarchy() {
|
||||
assertNotNull("child ApplicationContext", context);
|
||||
assertNotNull("parent ApplicationContext", context.getParent());
|
||||
assertNull("grandparent ApplicationContext", context.getParent().getParent());
|
||||
assertEquals("parent", parent);
|
||||
assertEquals("parent + user", user);
|
||||
assertEquals("from UserConfig", beanFromUserConfig);
|
||||
assertThat(context).as("child ApplicationContext").isNotNull();
|
||||
assertThat(context.getParent()).as("parent ApplicationContext").isNotNull();
|
||||
assertThat(context.getParent().getParent()).as("grandparent ApplicationContext").isNull();
|
||||
assertThat(parent).isEqualTo("parent");
|
||||
assertThat(user).isEqualTo("parent + user");
|
||||
assertThat(beanFromUserConfig).isEqualTo("from UserConfig");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.ContextHierarchy;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* @author Sam Brannen
|
||||
@@ -57,7 +57,7 @@ public class ClassHierarchyWithMergedConfigLevelTwoTests extends ClassHierarchyW
|
||||
@Override
|
||||
public void loadContextHierarchy() {
|
||||
super.loadContextHierarchy();
|
||||
assertEquals("parent + user + order", order);
|
||||
assertThat(order).isEqualTo("parent + user + order");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -26,9 +26,7 @@ import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.ContextHierarchy;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* @author Sam Brannen
|
||||
@@ -64,13 +62,13 @@ public class ClassHierarchyWithOverriddenConfigLevelTwoTests extends ClassHierar
|
||||
@Test
|
||||
@Override
|
||||
public void loadContextHierarchy() {
|
||||
assertNotNull("child ApplicationContext", context);
|
||||
assertNotNull("parent ApplicationContext", context.getParent());
|
||||
assertNull("grandparent ApplicationContext", context.getParent().getParent());
|
||||
assertEquals("parent", parent);
|
||||
assertEquals("parent + test user", user);
|
||||
assertEquals("from TestUserConfig", beanFromTestUserConfig);
|
||||
assertNull("Bean from UserConfig should not be present.", beanFromUserConfig);
|
||||
assertThat(context).as("child ApplicationContext").isNotNull();
|
||||
assertThat(context.getParent()).as("parent ApplicationContext").isNotNull();
|
||||
assertThat(context.getParent().getParent()).as("grandparent ApplicationContext").isNull();
|
||||
assertThat(parent).isEqualTo("parent");
|
||||
assertThat(user).isEqualTo("parent + test user");
|
||||
assertThat(beanFromTestUserConfig).isEqualTo("from TestUserConfig");
|
||||
assertThat(beanFromUserConfig).as("Bean from UserConfig should not be present.").isNull();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -32,9 +32,7 @@ import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.ContextHierarchy;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Integration tests that verify support for {@link DirtiesContext.HierarchyMode}
|
||||
@@ -99,28 +97,28 @@ public class DirtiesContextWithContextHierarchyTests {
|
||||
}
|
||||
|
||||
private void assertCleanParentContext() {
|
||||
assertEquals("foo", foo.toString());
|
||||
assertThat(foo.toString()).isEqualTo("foo");
|
||||
}
|
||||
|
||||
private void assertCleanChildContext() {
|
||||
assertEquals("baz-child", baz.toString());
|
||||
assertThat(baz.toString()).isEqualTo("baz-child");
|
||||
}
|
||||
|
||||
private void assertDirtyParentContext() {
|
||||
assertEquals("oof", foo.toString());
|
||||
assertThat(foo.toString()).isEqualTo("oof");
|
||||
}
|
||||
|
||||
private void assertDirtyChildContext() {
|
||||
assertEquals("dlihc-zab", baz.toString());
|
||||
assertThat(baz.toString()).isEqualTo("dlihc-zab");
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
@Before
|
||||
public void verifyContextHierarchy() {
|
||||
assertNotNull("child ApplicationContext", context);
|
||||
assertNotNull("parent ApplicationContext", context.getParent());
|
||||
assertNull("grandparent ApplicationContext", context.getParent().getParent());
|
||||
assertThat(context).as("child ApplicationContext").isNotNull();
|
||||
assertThat(context.getParent()).as("parent ApplicationContext").isNotNull();
|
||||
assertThat(context.getParent().getParent()).as("grandparent ApplicationContext").isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -27,9 +27,7 @@ import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.ContextHierarchy;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* @author Sam Brannen
|
||||
@@ -58,9 +56,9 @@ public class SingleTestClassWithSingleLevelContextHierarchyTests {
|
||||
|
||||
@Test
|
||||
public void loadContextHierarchy() {
|
||||
assertNotNull("child ApplicationContext", context);
|
||||
assertNull("parent ApplicationContext", context.getParent());
|
||||
assertEquals("foo", foo);
|
||||
assertThat(context).as("child ApplicationContext").isNotNull();
|
||||
assertThat(context.getParent()).as("parent ApplicationContext").isNull();
|
||||
assertThat(foo).isEqualTo("foo");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -27,9 +27,7 @@ import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.ContextHierarchy;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* @author Sam Brannen
|
||||
@@ -71,12 +69,12 @@ public class SingleTestClassWithTwoLevelContextHierarchyAndMixedConfigTypesTests
|
||||
|
||||
@Test
|
||||
public void loadContextHierarchy() {
|
||||
assertNotNull("child ApplicationContext", context);
|
||||
assertNotNull("parent ApplicationContext", context.getParent());
|
||||
assertNull("grandparent ApplicationContext", context.getParent().getParent());
|
||||
assertEquals("foo", foo);
|
||||
assertEquals("bar", bar);
|
||||
assertEquals("baz-child", baz);
|
||||
assertThat(context).as("child ApplicationContext").isNotNull();
|
||||
assertThat(context.getParent()).as("parent ApplicationContext").isNotNull();
|
||||
assertThat(context.getParent().getParent()).as("grandparent ApplicationContext").isNull();
|
||||
assertThat(foo).isEqualTo("foo");
|
||||
assertThat(bar).isEqualTo("bar");
|
||||
assertThat(baz).isEqualTo("baz-child");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -27,9 +27,7 @@ import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.ContextHierarchy;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* @author Sam Brannen
|
||||
@@ -85,12 +83,12 @@ public class SingleTestClassWithTwoLevelContextHierarchyTests {
|
||||
|
||||
@Test
|
||||
public void loadContextHierarchy() {
|
||||
assertNotNull("child ApplicationContext", context);
|
||||
assertNotNull("parent ApplicationContext", context.getParent());
|
||||
assertNull("grandparent ApplicationContext", context.getParent().getParent());
|
||||
assertEquals("foo", foo);
|
||||
assertEquals("bar", bar);
|
||||
assertEquals("baz-child", baz);
|
||||
assertThat(context).as("child ApplicationContext").isNotNull();
|
||||
assertThat(context.getParent()).as("parent ApplicationContext").isNotNull();
|
||||
assertThat(context.getParent().getParent()).as("grandparent ApplicationContext").isNull();
|
||||
assertThat(foo).isEqualTo("foo");
|
||||
assertThat(bar).isEqualTo("bar");
|
||||
assertThat(baz).isEqualTo("baz-child");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -27,9 +27,7 @@ import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.ContextHierarchy;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* @author Sam Brannen
|
||||
@@ -66,10 +64,10 @@ public class TestHierarchyLevelOneWithBareContextConfigurationInSubclassTests {
|
||||
|
||||
@Test
|
||||
public void loadContextHierarchy() {
|
||||
assertNotNull("child ApplicationContext", context);
|
||||
assertNull("parent ApplicationContext", context.getParent());
|
||||
assertEquals("foo-level-1", foo);
|
||||
assertEquals("bar", bar);
|
||||
assertThat(context).as("child ApplicationContext").isNotNull();
|
||||
assertThat(context.getParent()).as("parent ApplicationContext").isNull();
|
||||
assertThat(foo).isEqualTo("foo-level-1");
|
||||
assertThat(bar).isEqualTo("bar");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -26,9 +26,7 @@ import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* @author Sam Brannen
|
||||
@@ -65,10 +63,10 @@ public class TestHierarchyLevelOneWithBareContextConfigurationInSuperclassTests
|
||||
|
||||
@Test
|
||||
public void loadContextHierarchy() {
|
||||
assertNotNull("child ApplicationContext", context);
|
||||
assertNull("parent ApplicationContext", context.getParent());
|
||||
assertEquals("foo-level-1", foo);
|
||||
assertEquals("bar", bar);
|
||||
assertThat(context).as("child ApplicationContext").isNotNull();
|
||||
assertThat(context.getParent()).as("parent ApplicationContext").isNull();
|
||||
assertThat(foo).isEqualTo("foo-level-1");
|
||||
assertThat(bar).isEqualTo("bar");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -27,9 +27,7 @@ import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.ContextHierarchy;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* @author Sam Brannen
|
||||
@@ -66,10 +64,10 @@ public class TestHierarchyLevelOneWithSingleLevelContextHierarchyTests {
|
||||
|
||||
@Test
|
||||
public void loadContextHierarchy() {
|
||||
assertNotNull("child ApplicationContext", context);
|
||||
assertNull("parent ApplicationContext", context.getParent());
|
||||
assertEquals("foo-level-1", foo);
|
||||
assertEquals("bar", bar);
|
||||
assertThat(context).as("child ApplicationContext").isNotNull();
|
||||
assertThat(context.getParent()).as("parent ApplicationContext").isNull();
|
||||
assertThat(foo).isEqualTo("foo-level-1");
|
||||
assertThat(bar).isEqualTo("bar");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -26,9 +26,7 @@ import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* @author Sam Brannen
|
||||
@@ -70,12 +68,12 @@ public class TestHierarchyLevelTwoWithBareContextConfigurationInSubclassTests ex
|
||||
@Test
|
||||
@Override
|
||||
public void loadContextHierarchy() {
|
||||
assertNotNull("child ApplicationContext", context);
|
||||
assertNotNull("parent ApplicationContext", context.getParent());
|
||||
assertNull("grandparent ApplicationContext", context.getParent().getParent());
|
||||
assertEquals("foo-level-2", foo);
|
||||
assertEquals("bar", bar);
|
||||
assertEquals("baz", baz);
|
||||
assertThat(context).as("child ApplicationContext").isNotNull();
|
||||
assertThat(context.getParent()).as("parent ApplicationContext").isNotNull();
|
||||
assertThat(context.getParent().getParent()).as("grandparent ApplicationContext").isNull();
|
||||
assertThat(foo).isEqualTo("foo-level-2");
|
||||
assertThat(bar).isEqualTo("bar");
|
||||
assertThat(baz).isEqualTo("baz");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -27,9 +27,7 @@ import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.ContextHierarchy;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* @author Sam Brannen
|
||||
@@ -71,12 +69,12 @@ public class TestHierarchyLevelTwoWithBareContextConfigurationInSuperclassTests
|
||||
@Test
|
||||
@Override
|
||||
public void loadContextHierarchy() {
|
||||
assertNotNull("child ApplicationContext", context);
|
||||
assertNotNull("parent ApplicationContext", context.getParent());
|
||||
assertNull("grandparent ApplicationContext", context.getParent().getParent());
|
||||
assertEquals("foo-level-2", foo);
|
||||
assertEquals("bar", bar);
|
||||
assertEquals("baz", baz);
|
||||
assertThat(context).as("child ApplicationContext").isNotNull();
|
||||
assertThat(context.getParent()).as("parent ApplicationContext").isNotNull();
|
||||
assertThat(context.getParent().getParent()).as("grandparent ApplicationContext").isNull();
|
||||
assertThat(foo).isEqualTo("foo-level-2");
|
||||
assertThat(bar).isEqualTo("bar");
|
||||
assertThat(baz).isEqualTo("baz");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -25,9 +25,7 @@ import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.ContextHierarchy;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* @author Sam Brannen
|
||||
@@ -54,12 +52,12 @@ public class TestHierarchyLevelTwoWithSingleLevelContextHierarchyAndMixedConfigT
|
||||
@Test
|
||||
@Override
|
||||
public void loadContextHierarchy() {
|
||||
assertNotNull("child ApplicationContext", context);
|
||||
assertNotNull("parent ApplicationContext", context.getParent());
|
||||
assertNull("grandparent ApplicationContext", context.getParent().getParent());
|
||||
assertEquals("foo-level-2", foo);
|
||||
assertEquals("bar", bar);
|
||||
assertEquals("baz", baz);
|
||||
assertThat(context).as("child ApplicationContext").isNotNull();
|
||||
assertThat(context.getParent()).as("parent ApplicationContext").isNotNull();
|
||||
assertThat(context.getParent().getParent()).as("grandparent ApplicationContext").isNull();
|
||||
assertThat(foo).isEqualTo("foo-level-2");
|
||||
assertThat(bar).isEqualTo("bar");
|
||||
assertThat(baz).isEqualTo("baz");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -27,8 +27,7 @@ import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.ContextHierarchy;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* @author Sam Brannen
|
||||
@@ -70,11 +69,11 @@ public class TestHierarchyLevelTwoWithSingleLevelContextHierarchyTests extends
|
||||
@Test
|
||||
@Override
|
||||
public void loadContextHierarchy() {
|
||||
assertNotNull("child ApplicationContext", context);
|
||||
assertNotNull("parent ApplicationContext", context.getParent());
|
||||
assertEquals("foo-level-2", foo);
|
||||
assertEquals("bar", bar);
|
||||
assertEquals("baz", baz);
|
||||
assertThat(context).as("child ApplicationContext").isNotNull();
|
||||
assertThat(context.getParent()).as("parent ApplicationContext").isNotNull();
|
||||
assertThat(foo).isEqualTo("foo-level-2");
|
||||
assertThat(bar).isEqualTo("bar");
|
||||
assertThat(baz).isEqualTo("baz");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -33,11 +33,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.context.web.WebAppConfiguration;
|
||||
import org.springframework.web.context.WebApplicationContext;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* @author Sam Brannen
|
||||
@@ -85,23 +81,24 @@ public class ControllerIntegrationTests {
|
||||
|
||||
@Test
|
||||
public void verifyRootWacSupport() {
|
||||
assertEquals("foo", foo);
|
||||
assertEquals("bar", bar);
|
||||
assertThat(foo).isEqualTo("foo");
|
||||
assertThat(bar).isEqualTo("bar");
|
||||
|
||||
ApplicationContext parent = wac.getParent();
|
||||
assertNotNull(parent);
|
||||
assertTrue(parent instanceof WebApplicationContext);
|
||||
assertThat(parent).isNotNull();
|
||||
boolean condition = parent instanceof WebApplicationContext;
|
||||
assertThat(condition).isTrue();
|
||||
WebApplicationContext root = (WebApplicationContext) parent;
|
||||
assertFalse(root.getBeansOfType(String.class).containsKey("bar"));
|
||||
assertThat(root.getBeansOfType(String.class).containsKey("bar")).isFalse();
|
||||
|
||||
ServletContext childServletContext = wac.getServletContext();
|
||||
assertNotNull(childServletContext);
|
||||
assertThat(childServletContext).isNotNull();
|
||||
ServletContext rootServletContext = root.getServletContext();
|
||||
assertNotNull(rootServletContext);
|
||||
assertSame(childServletContext, rootServletContext);
|
||||
assertThat(rootServletContext).isNotNull();
|
||||
assertThat(rootServletContext).isSameAs(childServletContext);
|
||||
|
||||
assertSame(root, rootServletContext.getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE));
|
||||
assertSame(root, childServletContext.getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE));
|
||||
assertThat(rootServletContext.getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE)).isSameAs(root);
|
||||
assertThat(childServletContext.getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE)).isSameAs(root);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -27,11 +27,7 @@ import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.ContextHierarchy;
|
||||
import org.springframework.web.context.WebApplicationContext;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* @author Sam Brannen
|
||||
@@ -70,27 +66,27 @@ public class DispatcherWacRootWacEarTests extends RootWacEarTests {
|
||||
@Test
|
||||
public void verifyDispatcherWacConfig() {
|
||||
ApplicationContext parent = wac.getParent();
|
||||
assertNotNull(parent);
|
||||
assertTrue(parent instanceof WebApplicationContext);
|
||||
assertThat(parent).isNotNull();
|
||||
boolean condition = parent instanceof WebApplicationContext;
|
||||
assertThat(condition).isTrue();
|
||||
|
||||
ApplicationContext grandParent = parent.getParent();
|
||||
assertNotNull(grandParent);
|
||||
assertFalse(grandParent instanceof WebApplicationContext);
|
||||
assertThat(grandParent).isNotNull();
|
||||
boolean condition1 = grandParent instanceof WebApplicationContext;
|
||||
assertThat(condition1).isFalse();
|
||||
|
||||
ServletContext dispatcherServletContext = wac.getServletContext();
|
||||
assertNotNull(dispatcherServletContext);
|
||||
assertThat(dispatcherServletContext).isNotNull();
|
||||
ServletContext rootServletContext = ((WebApplicationContext) parent).getServletContext();
|
||||
assertNotNull(rootServletContext);
|
||||
assertSame(dispatcherServletContext, rootServletContext);
|
||||
assertThat(rootServletContext).isNotNull();
|
||||
assertThat(rootServletContext).isSameAs(dispatcherServletContext);
|
||||
|
||||
assertSame(parent,
|
||||
rootServletContext.getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE));
|
||||
assertSame(parent,
|
||||
dispatcherServletContext.getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE));
|
||||
assertThat(rootServletContext.getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE)).isSameAs(parent);
|
||||
assertThat(dispatcherServletContext.getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE)).isSameAs(parent);
|
||||
|
||||
assertEquals("ear", ear);
|
||||
assertEquals("root", root);
|
||||
assertEquals("dispatcher", dispatcher);
|
||||
assertThat(ear).isEqualTo("ear");
|
||||
assertThat(root).isEqualTo("root");
|
||||
assertThat(dispatcher).isEqualTo("dispatcher");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -27,9 +27,7 @@ import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.web.context.WebApplicationContext;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* @author Sam Brannen
|
||||
@@ -60,9 +58,10 @@ public class EarTests {
|
||||
|
||||
@Test
|
||||
public void verifyEarConfig() {
|
||||
assertFalse(context instanceof WebApplicationContext);
|
||||
assertNull(context.getParent());
|
||||
assertEquals("ear", ear);
|
||||
boolean condition = context instanceof WebApplicationContext;
|
||||
assertThat(condition).isFalse();
|
||||
assertThat(context.getParent()).isNull();
|
||||
assertThat(ear).isEqualTo("ear");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -28,9 +28,7 @@ import org.springframework.test.context.ContextHierarchy;
|
||||
import org.springframework.test.context.web.WebAppConfiguration;
|
||||
import org.springframework.web.context.WebApplicationContext;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* @author Sam Brannen
|
||||
@@ -72,10 +70,11 @@ public class RootWacEarTests extends EarTests {
|
||||
@Test
|
||||
public void verifyRootWacConfig() {
|
||||
ApplicationContext parent = wac.getParent();
|
||||
assertNotNull(parent);
|
||||
assertFalse(parent instanceof WebApplicationContext);
|
||||
assertEquals("ear", ear);
|
||||
assertEquals("root", root);
|
||||
assertThat(parent).isNotNull();
|
||||
boolean condition = parent instanceof WebApplicationContext;
|
||||
assertThat(condition).isFalse();
|
||||
assertThat(ear).isEqualTo("ear");
|
||||
assertThat(root).isEqualTo("root");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ import org.springframework.test.context.jdbc.Sql.ExecutionPhase;
|
||||
import org.springframework.test.context.junit4.AbstractTransactionalJUnit4SpringContextTests;
|
||||
|
||||
import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.springframework.test.context.jdbc.Sql.ExecutionPhase.BEFORE_TEST_METHOD;
|
||||
|
||||
/**
|
||||
@@ -48,7 +48,7 @@ public class ComposedAnnotationSqlScriptsTests extends AbstractTransactionalJUni
|
||||
executionPhase = BEFORE_TEST_METHOD
|
||||
)
|
||||
public void composedSqlAnnotation() {
|
||||
assertEquals("Number of rows in the 'user' table.", 1, countRowsInTable("user"));
|
||||
assertThat(countRowsInTable("user")).as("Number of rows in the 'user' table.").isEqualTo(1);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.AbstractTransactionalJUnit4SpringContextTests;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Integration tests that verify support for custom SQL script syntax
|
||||
@@ -44,7 +44,7 @@ public class CustomScriptSyntaxSqlScriptsTests extends AbstractTransactionalJUni
|
||||
}
|
||||
|
||||
protected void assertNumUsers(int expected) {
|
||||
assertEquals("Number of rows in the 'user' table.", expected, countRowsInTable("user"));
|
||||
assertThat(countRowsInTable("user")).as("Number of rows in the 'user' table.").isEqualTo(expected);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.jdbc.JdbcTestUtils;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.springframework.test.transaction.TransactionTestUtils.assertInTransaction;
|
||||
|
||||
/**
|
||||
@@ -74,8 +74,7 @@ public class DataSourceOnlySqlScriptsTests {
|
||||
}
|
||||
|
||||
protected void assertNumUsers(int expected) {
|
||||
assertEquals("Number of rows in the 'user' table.", expected,
|
||||
JdbcTestUtils.countRowsInTable(jdbcTemplate, "user"));
|
||||
assertThat(JdbcTestUtils.countRowsInTable(jdbcTemplate, "user")).as("Number of rows in the 'user' table.").isEqualTo(expected);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.AbstractTransactionalJUnit4SpringContextTests;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Integration tests that verify support for default SQL script detection.
|
||||
@@ -47,7 +47,7 @@ public class DefaultScriptDetectionSqlScriptsTests extends AbstractTransactional
|
||||
}
|
||||
|
||||
protected void assertNumUsers(int expected) {
|
||||
assertEquals("Number of rows in the 'user' table.", expected, countRowsInTable("user"));
|
||||
assertThat(countRowsInTable("user")).as("Number of rows in the 'user' table.").isEqualTo(expected);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.AbstractTransactionalJUnit4SpringContextTests;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Modified copy of {@link CustomScriptSyntaxSqlScriptsTests} with
|
||||
@@ -44,7 +44,7 @@ public class GlobalCustomScriptSyntaxSqlScriptsTests extends AbstractTransaction
|
||||
}
|
||||
|
||||
protected void assertNumUsers(int expected) {
|
||||
assertEquals("Number of rows in the 'user' table.", expected, countRowsInTable("user"));
|
||||
assertThat(countRowsInTable("user")).as("Number of rows in the 'user' table.").isEqualTo(expected);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.transaction.PlatformTransactionManager;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.springframework.test.transaction.TransactionTestUtils.assertInTransaction;
|
||||
|
||||
/**
|
||||
@@ -77,7 +77,7 @@ public class InferredDataSourceSqlScriptsTests {
|
||||
Collections.sort(expected);
|
||||
List<String> actual = jdbcTemplate.queryForList("select name from user", String.class);
|
||||
Collections.sort(actual);
|
||||
assertEquals("Users in database;", expected, actual);
|
||||
assertThat(actual).as("Users in database;").isEqualTo(expected);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.transaction.PlatformTransactionManager;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.springframework.test.transaction.TransactionTestUtils.assertInTransaction;
|
||||
|
||||
/**
|
||||
@@ -80,7 +80,7 @@ public class InferredDataSourceTransactionalSqlScriptsTests {
|
||||
Collections.sort(expected);
|
||||
List<String> actual = jdbcTemplate.queryForList("select name from user", String.class);
|
||||
Collections.sort(actual);
|
||||
assertEquals("Users in database;", expected, actual);
|
||||
assertThat(actual).as("Users in database;").isEqualTo(expected);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ import org.springframework.test.context.junit4.AbstractTransactionalJUnit4Spring
|
||||
import org.springframework.test.context.transaction.AfterTransaction;
|
||||
import org.springframework.test.context.transaction.BeforeTransaction;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Transactional integration tests that verify commit semantics for
|
||||
@@ -55,7 +55,7 @@ public class IsolatedTransactionModeSqlScriptsTests extends AbstractTransactiona
|
||||
}
|
||||
|
||||
protected void assertNumUsers(int expected) {
|
||||
assertEquals("Number of rows in the 'user' table.", expected, countRowsInTable("user"));
|
||||
assertThat(countRowsInTable("user")).as("Number of rows in the 'user' table.").isEqualTo(expected);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -20,8 +20,7 @@ import java.lang.reflect.Method;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.springframework.jdbc.datasource.init.ScriptUtils.DEFAULT_BLOCK_COMMENT_END_DELIMITER;
|
||||
import static org.springframework.jdbc.datasource.init.ScriptUtils.DEFAULT_BLOCK_COMMENT_START_DELIMITER;
|
||||
import static org.springframework.jdbc.datasource.init.ScriptUtils.DEFAULT_COMMENT_PREFIX;
|
||||
@@ -41,17 +40,16 @@ import static org.springframework.test.context.jdbc.SqlConfig.TransactionMode.IS
|
||||
public class MergedSqlConfigTests {
|
||||
|
||||
private void assertDefaults(MergedSqlConfig cfg) {
|
||||
assertNotNull(cfg);
|
||||
assertEquals("dataSource", "", cfg.getDataSource());
|
||||
assertEquals("transactionManager", "", cfg.getTransactionManager());
|
||||
assertEquals("transactionMode", INFERRED, cfg.getTransactionMode());
|
||||
assertEquals("encoding", "", cfg.getEncoding());
|
||||
assertEquals("separator", DEFAULT_STATEMENT_SEPARATOR, cfg.getSeparator());
|
||||
assertEquals("commentPrefix", DEFAULT_COMMENT_PREFIX, cfg.getCommentPrefix());
|
||||
assertEquals("blockCommentStartDelimiter", DEFAULT_BLOCK_COMMENT_START_DELIMITER,
|
||||
cfg.getBlockCommentStartDelimiter());
|
||||
assertEquals("blockCommentEndDelimiter", DEFAULT_BLOCK_COMMENT_END_DELIMITER, cfg.getBlockCommentEndDelimiter());
|
||||
assertEquals("errorMode", FAIL_ON_ERROR, cfg.getErrorMode());
|
||||
assertThat(cfg).isNotNull();
|
||||
assertThat(cfg.getDataSource()).as("dataSource").isEqualTo("");
|
||||
assertThat(cfg.getTransactionManager()).as("transactionManager").isEqualTo("");
|
||||
assertThat(cfg.getTransactionMode()).as("transactionMode").isEqualTo(INFERRED);
|
||||
assertThat(cfg.getEncoding()).as("encoding").isEqualTo("");
|
||||
assertThat(cfg.getSeparator()).as("separator").isEqualTo(DEFAULT_STATEMENT_SEPARATOR);
|
||||
assertThat(cfg.getCommentPrefix()).as("commentPrefix").isEqualTo(DEFAULT_COMMENT_PREFIX);
|
||||
assertThat(cfg.getBlockCommentStartDelimiter()).as("blockCommentStartDelimiter").isEqualTo(DEFAULT_BLOCK_COMMENT_START_DELIMITER);
|
||||
assertThat(cfg.getBlockCommentEndDelimiter()).as("blockCommentEndDelimiter").isEqualTo(DEFAULT_BLOCK_COMMENT_END_DELIMITER);
|
||||
assertThat(cfg.getErrorMode()).as("errorMode").isEqualTo(FAIL_ON_ERROR);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -75,16 +73,16 @@ public class MergedSqlConfigTests {
|
||||
Method method = getClass().getMethod("localConfigMethodWithCustomValues");
|
||||
SqlConfig localSqlConfig = method.getAnnotation(Sql.class).config();
|
||||
MergedSqlConfig cfg = new MergedSqlConfig(localSqlConfig, getClass());
|
||||
assertNotNull(cfg);
|
||||
assertEquals("dataSource", "ds", cfg.getDataSource());
|
||||
assertEquals("transactionManager", "txMgr", cfg.getTransactionManager());
|
||||
assertEquals("transactionMode", ISOLATED, cfg.getTransactionMode());
|
||||
assertEquals("encoding", "enigma", cfg.getEncoding());
|
||||
assertEquals("separator", "\n", cfg.getSeparator());
|
||||
assertEquals("commentPrefix", "`", cfg.getCommentPrefix());
|
||||
assertEquals("blockCommentStartDelimiter", "<<", cfg.getBlockCommentStartDelimiter());
|
||||
assertEquals("blockCommentEndDelimiter", ">>", cfg.getBlockCommentEndDelimiter());
|
||||
assertEquals("errorMode", IGNORE_FAILED_DROPS, cfg.getErrorMode());
|
||||
assertThat(cfg).isNotNull();
|
||||
assertThat(cfg.getDataSource()).as("dataSource").isEqualTo("ds");
|
||||
assertThat(cfg.getTransactionManager()).as("transactionManager").isEqualTo("txMgr");
|
||||
assertThat(cfg.getTransactionMode()).as("transactionMode").isEqualTo(ISOLATED);
|
||||
assertThat(cfg.getEncoding()).as("encoding").isEqualTo("enigma");
|
||||
assertThat(cfg.getSeparator()).as("separator").isEqualTo("\n");
|
||||
assertThat(cfg.getCommentPrefix()).as("commentPrefix").isEqualTo("`");
|
||||
assertThat(cfg.getBlockCommentStartDelimiter()).as("blockCommentStartDelimiter").isEqualTo("<<");
|
||||
assertThat(cfg.getBlockCommentEndDelimiter()).as("blockCommentEndDelimiter").isEqualTo(">>");
|
||||
assertThat(cfg.getErrorMode()).as("errorMode").isEqualTo(IGNORE_FAILED_DROPS);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -92,8 +90,8 @@ public class MergedSqlConfigTests {
|
||||
Method method = getClass().getMethod("localConfigMethodWithContinueOnError");
|
||||
SqlConfig localSqlConfig = method.getAnnotation(Sql.class).config();
|
||||
MergedSqlConfig cfg = new MergedSqlConfig(localSqlConfig, getClass());
|
||||
assertNotNull(cfg);
|
||||
assertEquals("errorMode", CONTINUE_ON_ERROR, cfg.getErrorMode());
|
||||
assertThat(cfg).isNotNull();
|
||||
assertThat(cfg.getErrorMode()).as("errorMode").isEqualTo(CONTINUE_ON_ERROR);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -101,8 +99,8 @@ public class MergedSqlConfigTests {
|
||||
Method method = getClass().getMethod("localConfigMethodWithIgnoreFailedDrops");
|
||||
SqlConfig localSqlConfig = method.getAnnotation(Sql.class).config();
|
||||
MergedSqlConfig cfg = new MergedSqlConfig(localSqlConfig, getClass());
|
||||
assertNotNull(cfg);
|
||||
assertEquals("errorMode", IGNORE_FAILED_DROPS, cfg.getErrorMode());
|
||||
assertThat(cfg).isNotNull();
|
||||
assertThat(cfg.getErrorMode()).as("errorMode").isEqualTo(IGNORE_FAILED_DROPS);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -110,17 +108,16 @@ public class MergedSqlConfigTests {
|
||||
Method method = GlobalConfigClass.class.getMethod("globalConfigMethod");
|
||||
SqlConfig localSqlConfig = method.getAnnotation(Sql.class).config();
|
||||
MergedSqlConfig cfg = new MergedSqlConfig(localSqlConfig, GlobalConfigClass.class);
|
||||
assertNotNull(cfg);
|
||||
assertEquals("dataSource", "", cfg.getDataSource());
|
||||
assertEquals("transactionManager", "", cfg.getTransactionManager());
|
||||
assertEquals("transactionMode", INFERRED, cfg.getTransactionMode());
|
||||
assertEquals("encoding", "global", cfg.getEncoding());
|
||||
assertEquals("separator", "\n", cfg.getSeparator());
|
||||
assertEquals("commentPrefix", DEFAULT_COMMENT_PREFIX, cfg.getCommentPrefix());
|
||||
assertEquals("blockCommentStartDelimiter", DEFAULT_BLOCK_COMMENT_START_DELIMITER,
|
||||
cfg.getBlockCommentStartDelimiter());
|
||||
assertEquals("blockCommentEndDelimiter", DEFAULT_BLOCK_COMMENT_END_DELIMITER, cfg.getBlockCommentEndDelimiter());
|
||||
assertEquals("errorMode", IGNORE_FAILED_DROPS, cfg.getErrorMode());
|
||||
assertThat(cfg).isNotNull();
|
||||
assertThat(cfg.getDataSource()).as("dataSource").isEqualTo("");
|
||||
assertThat(cfg.getTransactionManager()).as("transactionManager").isEqualTo("");
|
||||
assertThat(cfg.getTransactionMode()).as("transactionMode").isEqualTo(INFERRED);
|
||||
assertThat(cfg.getEncoding()).as("encoding").isEqualTo("global");
|
||||
assertThat(cfg.getSeparator()).as("separator").isEqualTo("\n");
|
||||
assertThat(cfg.getCommentPrefix()).as("commentPrefix").isEqualTo(DEFAULT_COMMENT_PREFIX);
|
||||
assertThat(cfg.getBlockCommentStartDelimiter()).as("blockCommentStartDelimiter").isEqualTo(DEFAULT_BLOCK_COMMENT_START_DELIMITER);
|
||||
assertThat(cfg.getBlockCommentEndDelimiter()).as("blockCommentEndDelimiter").isEqualTo(DEFAULT_BLOCK_COMMENT_END_DELIMITER);
|
||||
assertThat(cfg.getErrorMode()).as("errorMode").isEqualTo(IGNORE_FAILED_DROPS);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -129,17 +126,16 @@ public class MergedSqlConfigTests {
|
||||
SqlConfig localSqlConfig = method.getAnnotation(Sql.class).config();
|
||||
MergedSqlConfig cfg = new MergedSqlConfig(localSqlConfig, GlobalConfigClass.class);
|
||||
|
||||
assertNotNull(cfg);
|
||||
assertEquals("dataSource", "", cfg.getDataSource());
|
||||
assertEquals("transactionManager", "", cfg.getTransactionManager());
|
||||
assertEquals("transactionMode", INFERRED, cfg.getTransactionMode());
|
||||
assertEquals("encoding", "local", cfg.getEncoding());
|
||||
assertEquals("separator", "@@", cfg.getSeparator());
|
||||
assertEquals("commentPrefix", DEFAULT_COMMENT_PREFIX, cfg.getCommentPrefix());
|
||||
assertEquals("blockCommentStartDelimiter", DEFAULT_BLOCK_COMMENT_START_DELIMITER,
|
||||
cfg.getBlockCommentStartDelimiter());
|
||||
assertEquals("blockCommentEndDelimiter", DEFAULT_BLOCK_COMMENT_END_DELIMITER, cfg.getBlockCommentEndDelimiter());
|
||||
assertEquals("errorMode", CONTINUE_ON_ERROR, cfg.getErrorMode());
|
||||
assertThat(cfg).isNotNull();
|
||||
assertThat(cfg.getDataSource()).as("dataSource").isEqualTo("");
|
||||
assertThat(cfg.getTransactionManager()).as("transactionManager").isEqualTo("");
|
||||
assertThat(cfg.getTransactionMode()).as("transactionMode").isEqualTo(INFERRED);
|
||||
assertThat(cfg.getEncoding()).as("encoding").isEqualTo("local");
|
||||
assertThat(cfg.getSeparator()).as("separator").isEqualTo("@@");
|
||||
assertThat(cfg.getCommentPrefix()).as("commentPrefix").isEqualTo(DEFAULT_COMMENT_PREFIX);
|
||||
assertThat(cfg.getBlockCommentStartDelimiter()).as("blockCommentStartDelimiter").isEqualTo(DEFAULT_BLOCK_COMMENT_START_DELIMITER);
|
||||
assertThat(cfg.getBlockCommentEndDelimiter()).as("blockCommentEndDelimiter").isEqualTo(DEFAULT_BLOCK_COMMENT_END_DELIMITER);
|
||||
assertThat(cfg.getErrorMode()).as("errorMode").isEqualTo(CONTINUE_ON_ERROR);
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
@@ -27,7 +27,7 @@ import org.springframework.test.context.junit4.AbstractTransactionalJUnit4Spring
|
||||
|
||||
import static java.lang.annotation.ElementType.METHOD;
|
||||
import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Integration tests that verify support for using {@link Sql @Sql} and
|
||||
@@ -53,7 +53,7 @@ public class MetaAnnotationSqlScriptsTests extends AbstractTransactionalJUnit4Sp
|
||||
}
|
||||
|
||||
protected void assertNumUsers(int expected) {
|
||||
assertEquals("Number of rows in the 'user' table.", expected, countRowsInTable("user"));
|
||||
assertThat(countRowsInTable("user")).as("Number of rows in the 'user' table.").isEqualTo(expected);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@ import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.transaction.PlatformTransactionManager;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Integration tests for {@link Sql @Sql} that verify support for multiple
|
||||
@@ -76,7 +76,7 @@ public class MultipleDataSourcesAndTransactionManagersSqlScriptsTests {
|
||||
Collections.sort(expected);
|
||||
List<String> actual = jdbcTemplate.queryForList("select name from user", String.class);
|
||||
Collections.sort(actual);
|
||||
assertEquals("Users in database;", expected, actual);
|
||||
assertThat(actual).as("Users in database;").isEqualTo(expected);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.transaction.PlatformTransactionManager;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Exact copy of {@link MultipleDataSourcesAndTransactionManagersSqlScriptsTests},
|
||||
@@ -77,7 +77,7 @@ public class MultipleDataSourcesAndTransactionManagersTransactionalSqlScriptsTes
|
||||
Collections.sort(expected);
|
||||
List<String> actual = jdbcTemplate.queryForList("select name from user", String.class);
|
||||
Collections.sort(actual);
|
||||
assertEquals("Users in database;", expected, actual);
|
||||
assertThat(actual).as("Users in database;").isEqualTo(expected);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.jdbc.JdbcTestUtils;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Integration tests which verify that scripts executed via {@link Sql @Sql}
|
||||
@@ -68,8 +68,7 @@ public class NonTransactionalSqlScriptsTests {
|
||||
}
|
||||
|
||||
protected void assertNumUsers(int expected) {
|
||||
assertEquals("Number of rows in the 'user' table.", expected,
|
||||
JdbcTestUtils.countRowsInTable(jdbcTemplate, "user"));
|
||||
assertThat(JdbcTestUtils.countRowsInTable(jdbcTemplate, "user")).as("Number of rows in the 'user' table.").isEqualTo(expected);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ import org.springframework.test.context.junit4.AbstractTransactionalJUnit4Spring
|
||||
import org.springframework.test.context.transaction.AfterTransaction;
|
||||
import org.springframework.test.context.transaction.BeforeTransaction;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Transactional integration tests that verify rollback semantics for
|
||||
@@ -50,7 +50,7 @@ public class PopulatedSchemaTransactionalSqlScriptsTests extends AbstractTransac
|
||||
}
|
||||
|
||||
protected void assertNumUsers(int expected) {
|
||||
assertEquals("Number of rows in the 'user' table.", expected, countRowsInTable("user"));
|
||||
assertThat(countRowsInTable("user")).as("Number of rows in the 'user' table.").isEqualTo(expected);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.jdbc.JdbcTestUtils;
|
||||
import org.springframework.test.transaction.TransactionTestUtils;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Integration tests that ensure that <em>primary</em> data sources are
|
||||
@@ -82,8 +82,7 @@ public class PrimaryDataSourceTests {
|
||||
@Sql("data.sql")
|
||||
public void dataSourceTest() {
|
||||
TransactionTestUtils.assertInTransaction(false);
|
||||
assertEquals("Number of rows in the 'user' table.", 1,
|
||||
JdbcTestUtils.countRowsInTable(this.jdbcTemplate, "user"));
|
||||
assertThat(JdbcTestUtils.countRowsInTable(this.jdbcTemplate, "user")).as("Number of rows in the 'user' table.").isEqualTo(1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.AbstractTransactionalJUnit4SpringContextTests;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* This is a copy of {@link TransactionalSqlScriptsTests} that verifies proper
|
||||
@@ -59,7 +59,7 @@ public class RepeatableSqlAnnotationSqlScriptsTests extends AbstractTransactiona
|
||||
}
|
||||
|
||||
protected void assertNumUsers(int expected) {
|
||||
assertEquals("Number of rows in the 'user' table.", expected, countRowsInTable("user"));
|
||||
assertThat(countRowsInTable("user")).as("Number of rows in the 'user' table.").isEqualTo(expected);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -29,8 +29,8 @@ import org.springframework.test.context.jdbc.Sql.ExecutionPhase;
|
||||
import org.springframework.test.context.junit4.AbstractTransactionalJUnit4SpringContextTests;
|
||||
import org.springframework.test.context.transaction.AfterTransaction;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.springframework.test.context.jdbc.Sql.ExecutionPhase.AFTER_TEST_METHOD;
|
||||
|
||||
/**
|
||||
@@ -76,7 +76,7 @@ public class TransactionalAfterTestMethodSqlScriptsTests extends AbstractTransac
|
||||
}
|
||||
|
||||
protected void assertNumUsers(int expected) {
|
||||
assertEquals("Number of rows in the 'user' table.", expected, countRowsInTable("user"));
|
||||
assertThat(countRowsInTable("user")).as("Number of rows in the 'user' table.").isEqualTo(expected);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.jdbc.JdbcTestUtils;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Transactional integration tests for {@link Sql @Sql} support with
|
||||
@@ -80,7 +80,7 @@ public class TransactionalInlinedStatementsSqlScriptsTests {
|
||||
}
|
||||
|
||||
protected void assertNumUsers(int expected) {
|
||||
assertEquals("Number of rows in the 'user' table.", expected, countRowsInTable("user"));
|
||||
assertThat(countRowsInTable("user")).as("Number of rows in the 'user' table.").isEqualTo(expected);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.jdbc.JdbcTestUtils;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Transactional integration tests for {@link Sql @Sql} support.
|
||||
@@ -73,7 +73,7 @@ public class TransactionalSqlScriptsTests {
|
||||
}
|
||||
|
||||
protected void assertNumUsers(int expected) {
|
||||
assertEquals("Number of rows in the 'user' table.", expected, countRowsInTable("user"));
|
||||
assertThat(countRowsInTable("user")).as("Number of rows in the 'user' table.").isEqualTo(expected);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ import org.springframework.test.context.transaction.BeforeTransaction;
|
||||
import org.springframework.transaction.annotation.Propagation;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.springframework.test.transaction.TransactionTestUtils.assertInTransaction;
|
||||
|
||||
/**
|
||||
@@ -72,12 +72,9 @@ public class BeforeAndAfterTransactionAnnotationTests extends AbstractTransactio
|
||||
|
||||
@AfterClass
|
||||
public static void afterClass() {
|
||||
assertEquals("Verifying the final number of rows in the person table after all tests.", 3,
|
||||
countRowsInPersonTable(jdbcTemplate));
|
||||
assertEquals("Verifying the total number of calls to beforeTransaction().", 2,
|
||||
BeforeAndAfterTransactionAnnotationTests.numBeforeTransactionCalls);
|
||||
assertEquals("Verifying the total number of calls to afterTransaction().", 2,
|
||||
BeforeAndAfterTransactionAnnotationTests.numAfterTransactionCalls);
|
||||
assertThat(countRowsInPersonTable(jdbcTemplate)).as("Verifying the final number of rows in the person table after all tests.").isEqualTo(3);
|
||||
assertThat(BeforeAndAfterTransactionAnnotationTests.numBeforeTransactionCalls).as("Verifying the total number of calls to beforeTransaction().").isEqualTo(2);
|
||||
assertThat(BeforeAndAfterTransactionAnnotationTests.numAfterTransactionCalls).as("Verifying the total number of calls to afterTransaction().").isEqualTo(2);
|
||||
}
|
||||
|
||||
@BeforeTransaction
|
||||
@@ -86,7 +83,7 @@ public class BeforeAndAfterTransactionAnnotationTests extends AbstractTransactio
|
||||
this.inTransaction = true;
|
||||
BeforeAndAfterTransactionAnnotationTests.numBeforeTransactionCalls++;
|
||||
clearPersonTable(jdbcTemplate);
|
||||
assertEquals("Adding yoda", 1, addPerson(jdbcTemplate, YODA));
|
||||
assertThat(addPerson(jdbcTemplate, YODA)).as("Adding yoda").isEqualTo(1);
|
||||
}
|
||||
|
||||
@AfterTransaction
|
||||
@@ -94,16 +91,16 @@ public class BeforeAndAfterTransactionAnnotationTests extends AbstractTransactio
|
||||
assertInTransaction(false);
|
||||
this.inTransaction = false;
|
||||
BeforeAndAfterTransactionAnnotationTests.numAfterTransactionCalls++;
|
||||
assertEquals("Deleting yoda", 1, deletePerson(jdbcTemplate, YODA));
|
||||
assertEquals("Verifying the number of rows in the person table after a transactional test method.", 0,
|
||||
countRowsInPersonTable(jdbcTemplate));
|
||||
assertThat(deletePerson(jdbcTemplate, YODA)).as("Deleting yoda").isEqualTo(1);
|
||||
assertThat(countRowsInPersonTable(jdbcTemplate)).as("Verifying the number of rows in the person table after a transactional test method.").isEqualTo(0);
|
||||
}
|
||||
|
||||
@Before
|
||||
public void before() {
|
||||
assertShouldBeInTransaction();
|
||||
assertEquals("Verifying the number of rows in the person table before a test method.", (this.inTransaction ? 1
|
||||
: 0), countRowsInPersonTable(jdbcTemplate));
|
||||
long expected = (this.inTransaction ? 1
|
||||
: 0);
|
||||
assertThat(countRowsInPersonTable(jdbcTemplate)).as("Verifying the number of rows in the person table before a test method.").isEqualTo(expected);
|
||||
}
|
||||
|
||||
private void assertShouldBeInTransaction() {
|
||||
@@ -119,29 +116,26 @@ public class BeforeAndAfterTransactionAnnotationTests extends AbstractTransactio
|
||||
@Test
|
||||
public void transactionalMethod1() {
|
||||
assertInTransaction(true);
|
||||
assertEquals("Adding jane", 1, addPerson(jdbcTemplate, JANE));
|
||||
assertEquals("Verifying the number of rows in the person table within transactionalMethod1().", 2,
|
||||
countRowsInPersonTable(jdbcTemplate));
|
||||
assertThat(addPerson(jdbcTemplate, JANE)).as("Adding jane").isEqualTo(1);
|
||||
assertThat(countRowsInPersonTable(jdbcTemplate)).as("Verifying the number of rows in the person table within transactionalMethod1().").isEqualTo(2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void transactionalMethod2() {
|
||||
assertInTransaction(true);
|
||||
assertEquals("Adding jane", 1, addPerson(jdbcTemplate, JANE));
|
||||
assertEquals("Adding sue", 1, addPerson(jdbcTemplate, SUE));
|
||||
assertEquals("Verifying the number of rows in the person table within transactionalMethod2().", 3,
|
||||
countRowsInPersonTable(jdbcTemplate));
|
||||
assertThat(addPerson(jdbcTemplate, JANE)).as("Adding jane").isEqualTo(1);
|
||||
assertThat(addPerson(jdbcTemplate, SUE)).as("Adding sue").isEqualTo(1);
|
||||
assertThat(countRowsInPersonTable(jdbcTemplate)).as("Verifying the number of rows in the person table within transactionalMethod2().").isEqualTo(3);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Transactional(propagation = Propagation.NOT_SUPPORTED)
|
||||
public void nonTransactionalMethod() {
|
||||
assertInTransaction(false);
|
||||
assertEquals("Adding luke", 1, addPerson(jdbcTemplate, LUKE));
|
||||
assertEquals("Adding leia", 1, addPerson(jdbcTemplate, LEIA));
|
||||
assertEquals("Adding yoda", 1, addPerson(jdbcTemplate, YODA));
|
||||
assertEquals("Verifying the number of rows in the person table without a transaction.", 3,
|
||||
countRowsInPersonTable(jdbcTemplate));
|
||||
assertThat(addPerson(jdbcTemplate, LUKE)).as("Adding luke").isEqualTo(1);
|
||||
assertThat(addPerson(jdbcTemplate, LEIA)).as("Adding leia").isEqualTo(1);
|
||||
assertThat(addPerson(jdbcTemplate, YODA)).as("Adding yoda").isEqualTo(1);
|
||||
assertThat(countRowsInPersonTable(jdbcTemplate)).as("Verifying the number of rows in the person table without a transaction.").isEqualTo(3);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ import org.springframework.test.context.TestContext;
|
||||
import org.springframework.test.context.TestExecutionListener;
|
||||
import org.springframework.test.context.TestExecutionListeners;
|
||||
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.assertj.core.api.Assertions.fail;
|
||||
|
||||
/**
|
||||
* @author Juergen Hoeller
|
||||
|
||||
@@ -33,7 +33,7 @@ import org.springframework.test.context.transaction.TransactionalTestExecutionLi
|
||||
import org.springframework.transaction.annotation.Propagation;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.springframework.test.transaction.TransactionTestUtils.assertInTransaction;
|
||||
|
||||
/**
|
||||
@@ -70,37 +70,33 @@ public class ClassLevelTransactionalSpringRunnerTests extends AbstractTransactio
|
||||
|
||||
@AfterClass
|
||||
public static void verifyFinalTestData() {
|
||||
assertEquals("Verifying the final number of rows in the person table after all tests.", 4,
|
||||
countRowsInPersonTable(jdbcTemplate));
|
||||
assertThat(countRowsInPersonTable(jdbcTemplate)).as("Verifying the final number of rows in the person table after all tests.").isEqualTo(4);
|
||||
}
|
||||
|
||||
@Before
|
||||
public void verifyInitialTestData() {
|
||||
clearPersonTable(jdbcTemplate);
|
||||
assertEquals("Adding bob", 1, addPerson(jdbcTemplate, BOB));
|
||||
assertEquals("Verifying the initial number of rows in the person table.", 1,
|
||||
countRowsInPersonTable(jdbcTemplate));
|
||||
assertThat(addPerson(jdbcTemplate, BOB)).as("Adding bob").isEqualTo(1);
|
||||
assertThat(countRowsInPersonTable(jdbcTemplate)).as("Verifying the initial number of rows in the person table.").isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void modifyTestDataWithinTransaction() {
|
||||
assertInTransaction(true);
|
||||
assertEquals("Deleting bob", 1, deletePerson(jdbcTemplate, BOB));
|
||||
assertEquals("Adding jane", 1, addPerson(jdbcTemplate, JANE));
|
||||
assertEquals("Adding sue", 1, addPerson(jdbcTemplate, SUE));
|
||||
assertEquals("Verifying the number of rows in the person table within a transaction.", 2,
|
||||
countRowsInPersonTable(jdbcTemplate));
|
||||
assertThat(deletePerson(jdbcTemplate, BOB)).as("Deleting bob").isEqualTo(1);
|
||||
assertThat(addPerson(jdbcTemplate, JANE)).as("Adding jane").isEqualTo(1);
|
||||
assertThat(addPerson(jdbcTemplate, SUE)).as("Adding sue").isEqualTo(1);
|
||||
assertThat(countRowsInPersonTable(jdbcTemplate)).as("Verifying the number of rows in the person table within a transaction.").isEqualTo(2);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Transactional(propagation = Propagation.NOT_SUPPORTED)
|
||||
public void modifyTestDataWithoutTransaction() {
|
||||
assertInTransaction(false);
|
||||
assertEquals("Adding luke", 1, addPerson(jdbcTemplate, LUKE));
|
||||
assertEquals("Adding leia", 1, addPerson(jdbcTemplate, LEIA));
|
||||
assertEquals("Adding yoda", 1, addPerson(jdbcTemplate, YODA));
|
||||
assertEquals("Verifying the number of rows in the person table without a transaction.", 4,
|
||||
countRowsInPersonTable(jdbcTemplate));
|
||||
assertThat(addPerson(jdbcTemplate, LUKE)).as("Adding luke").isEqualTo(1);
|
||||
assertThat(addPerson(jdbcTemplate, LEIA)).as("Adding leia").isEqualTo(1);
|
||||
assertThat(addPerson(jdbcTemplate, YODA)).as("Adding yoda").isEqualTo(1);
|
||||
assertThat(countRowsInPersonTable(jdbcTemplate)).as("Verifying the number of rows in the person table without a transaction.").isEqualTo(4);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -33,10 +33,7 @@ import org.springframework.tests.sample.beans.Pet;
|
||||
import org.springframework.transaction.annotation.Propagation;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.springframework.test.transaction.TransactionTestUtils.assertInTransaction;
|
||||
import static org.springframework.test.transaction.TransactionTestUtils.inTransaction;
|
||||
|
||||
@@ -96,28 +93,26 @@ public class ConcreteTransactionalJUnit4SpringContextTests extends AbstractTrans
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
assertEquals("Verifying the number of rows in the person table before a test method.",
|
||||
(inTransaction() ? 2 : 1), countRowsInPersonTable());
|
||||
long expected = (inTransaction() ? 2 : 1);
|
||||
assertThat(countRowsInPersonTable()).as("Verifying the number of rows in the person table before a test method.").isEqualTo(expected);
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
assertEquals("Verifying the number of rows in the person table after a test method.",
|
||||
(inTransaction() ? 4 : 1), countRowsInPersonTable());
|
||||
long expected = (inTransaction() ? 4 : 1);
|
||||
assertThat(countRowsInPersonTable()).as("Verifying the number of rows in the person table after a test method.").isEqualTo(expected);
|
||||
}
|
||||
|
||||
@BeforeTransaction
|
||||
public void beforeTransaction() {
|
||||
assertEquals("Verifying the number of rows in the person table before a transactional test method.",
|
||||
1, countRowsInPersonTable());
|
||||
assertEquals("Adding yoda", 1, addPerson(YODA));
|
||||
assertThat(countRowsInPersonTable()).as("Verifying the number of rows in the person table before a transactional test method.").isEqualTo(1);
|
||||
assertThat(addPerson(YODA)).as("Adding yoda").isEqualTo(1);
|
||||
}
|
||||
|
||||
@AfterTransaction
|
||||
public void afterTransaction() {
|
||||
assertEquals("Deleting yoda", 1, deletePerson(YODA));
|
||||
assertEquals("Verifying the number of rows in the person table after a transactional test method.",
|
||||
1, countRowsInPersonTable());
|
||||
assertThat(deletePerson(YODA)).as("Deleting yoda").isEqualTo(1);
|
||||
assertThat(countRowsInPersonTable()).as("Verifying the number of rows in the person table after a transactional test method.").isEqualTo(1);
|
||||
}
|
||||
|
||||
|
||||
@@ -125,64 +120,61 @@ public class ConcreteTransactionalJUnit4SpringContextTests extends AbstractTrans
|
||||
@Transactional(propagation = Propagation.NOT_SUPPORTED)
|
||||
public void verifyBeanNameSet() {
|
||||
assertInTransaction(false);
|
||||
assertTrue("The bean name of this test instance should have been set to the fully qualified class name " +
|
||||
"due to BeanNameAware semantics.", this.beanName.startsWith(getClass().getName()));
|
||||
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
|
||||
@Transactional(propagation = Propagation.NOT_SUPPORTED)
|
||||
public void verifyApplicationContext() {
|
||||
assertInTransaction(false);
|
||||
assertNotNull("The application context should have been set due to ApplicationContextAware semantics.",
|
||||
super.applicationContext);
|
||||
assertThat(super.applicationContext).as("The application context should have been set due to ApplicationContextAware semantics.").isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Transactional(propagation = Propagation.NOT_SUPPORTED)
|
||||
public void verifyBeanInitialized() {
|
||||
assertInTransaction(false);
|
||||
assertTrue("This test bean should have been initialized due to InitializingBean semantics.",
|
||||
this.beanInitialized);
|
||||
assertThat(this.beanInitialized).as("This test bean should have been initialized due to InitializingBean semantics.").isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Transactional(propagation = Propagation.NOT_SUPPORTED)
|
||||
public void verifyAnnotationAutowiredFields() {
|
||||
assertInTransaction(false);
|
||||
assertNull("The nonrequiredLong property should NOT have been autowired.", this.nonrequiredLong);
|
||||
assertNotNull("The pet field should have been autowired.", this.pet);
|
||||
assertEquals("Fido", this.pet.getName());
|
||||
assertThat(this.nonrequiredLong).as("The nonrequiredLong property should NOT have been autowired.").isNull();
|
||||
assertThat(this.pet).as("The pet field should have been autowired.").isNotNull();
|
||||
assertThat(this.pet.getName()).isEqualTo("Fido");
|
||||
}
|
||||
|
||||
@Test
|
||||
@Transactional(propagation = Propagation.NOT_SUPPORTED)
|
||||
public void verifyAnnotationAutowiredMethods() {
|
||||
assertInTransaction(false);
|
||||
assertNotNull("The employee setter method should have been autowired.", this.employee);
|
||||
assertEquals("John Smith", this.employee.getName());
|
||||
assertThat(this.employee).as("The employee setter method should have been autowired.").isNotNull();
|
||||
assertThat(this.employee.getName()).isEqualTo("John Smith");
|
||||
}
|
||||
|
||||
@Test
|
||||
@Transactional(propagation = Propagation.NOT_SUPPORTED)
|
||||
public void verifyResourceAnnotationWiredFields() {
|
||||
assertInTransaction(false);
|
||||
assertEquals("The foo field should have been wired via @Resource.", "Foo", this.foo);
|
||||
assertThat(this.foo).as("The foo field should have been wired via @Resource.").isEqualTo("Foo");
|
||||
}
|
||||
|
||||
@Test
|
||||
@Transactional(propagation = Propagation.NOT_SUPPORTED)
|
||||
public void verifyResourceAnnotationWiredMethods() {
|
||||
assertInTransaction(false);
|
||||
assertEquals("The bar method should have been wired via @Resource.", "Bar", this.bar);
|
||||
assertThat(this.bar).as("The bar method should have been wired via @Resource.").isEqualTo("Bar");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void modifyTestDataWithinTransaction() {
|
||||
assertInTransaction(true);
|
||||
assertEquals("Adding jane", 1, addPerson(JANE));
|
||||
assertEquals("Adding sue", 1, addPerson(SUE));
|
||||
assertEquals("Verifying the number of rows in the person table in modifyTestDataWithinTransaction().",
|
||||
4, countRowsInPersonTable());
|
||||
assertThat(addPerson(JANE)).as("Adding jane").isEqualTo(1);
|
||||
assertThat(addPerson(SUE)).as("Adding sue").isEqualTo(1);
|
||||
assertThat(countRowsInPersonTable()).as("Verifying the number of rows in the person table in modifyTestDataWithinTransaction().").isEqualTo(4);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ import org.springframework.test.context.junit4.ContextCustomizerSpringRunnerTest
|
||||
import org.springframework.test.context.support.DefaultTestContextBootstrapper;
|
||||
|
||||
import static java.util.Collections.singletonList;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* JUnit 4 based integration test which verifies support of
|
||||
@@ -48,7 +48,7 @@ public class ContextCustomizerSpringRunnerTests {
|
||||
|
||||
@Test
|
||||
public void injectedBean() {
|
||||
assertEquals("foo", foo);
|
||||
assertThat(foo).isEqualTo("foo");
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -27,8 +27,7 @@ import org.springframework.test.context.support.DefaultTestContextBootstrapper;
|
||||
import org.springframework.test.context.support.GenericPropertiesContextLoader;
|
||||
import org.springframework.tests.sample.beans.Pet;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Integration tests which verify that a subclass of {@link DefaultTestContextBootstrapper}
|
||||
@@ -52,11 +51,11 @@ public class CustomDefaultContextLoaderClassSpringRunnerTests {
|
||||
|
||||
@Test
|
||||
public void verifyAnnotationAutowiredFields() {
|
||||
assertNotNull("The cat field should have been autowired.", this.cat);
|
||||
assertEquals("Garfield", this.cat.getName());
|
||||
assertThat(this.cat).as("The cat field should have been autowired.").isNotNull();
|
||||
assertThat(this.cat.getName()).isEqualTo("Garfield");
|
||||
|
||||
assertNotNull("The testString field should have been autowired.", this.testString);
|
||||
assertEquals("Test String", this.testString);
|
||||
assertThat(this.testString).as("The testString field should have been autowired.").isNotNull();
|
||||
assertThat(this.testString).isEqualTo("Test String");
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ import org.springframework.test.annotation.Rollback;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.springframework.test.transaction.TransactionTestUtils.assertInTransaction;
|
||||
|
||||
/**
|
||||
@@ -63,25 +63,22 @@ public class DefaultRollbackFalseRollbackAnnotationTransactionalTests extends Ab
|
||||
@Before
|
||||
public void verifyInitialTestData() {
|
||||
clearPersonTable(jdbcTemplate);
|
||||
assertEquals("Adding bob", 1, addPerson(jdbcTemplate, BOB));
|
||||
assertEquals("Verifying the initial number of rows in the person table.", 1,
|
||||
countRowsInPersonTable(jdbcTemplate));
|
||||
assertThat(addPerson(jdbcTemplate, BOB)).as("Adding bob").isEqualTo(1);
|
||||
assertThat(countRowsInPersonTable(jdbcTemplate)).as("Verifying the initial number of rows in the person table.").isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void modifyTestDataWithinTransaction() {
|
||||
assertInTransaction(true);
|
||||
assertEquals("Deleting bob", 1, deletePerson(jdbcTemplate, BOB));
|
||||
assertEquals("Adding jane", 1, addPerson(jdbcTemplate, JANE));
|
||||
assertEquals("Adding sue", 1, addPerson(jdbcTemplate, SUE));
|
||||
assertEquals("Verifying the number of rows in the person table within a transaction.", 2,
|
||||
countRowsInPersonTable(jdbcTemplate));
|
||||
assertThat(deletePerson(jdbcTemplate, BOB)).as("Deleting bob").isEqualTo(1);
|
||||
assertThat(addPerson(jdbcTemplate, JANE)).as("Adding jane").isEqualTo(1);
|
||||
assertThat(addPerson(jdbcTemplate, SUE)).as("Adding sue").isEqualTo(1);
|
||||
assertThat(countRowsInPersonTable(jdbcTemplate)).as("Verifying the number of rows in the person table within a transaction.").isEqualTo(2);
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void verifyFinalTestData() {
|
||||
assertEquals("Verifying the final number of rows in the person table after all tests.", 2,
|
||||
countRowsInPersonTable(jdbcTemplate));
|
||||
assertThat(countRowsInPersonTable(jdbcTemplate)).as("Verifying the final number of rows in the person table after all tests.").isEqualTo(2);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ import org.springframework.test.annotation.Rollback;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.springframework.test.transaction.TransactionTestUtils.assertInTransaction;
|
||||
|
||||
/**
|
||||
@@ -65,24 +65,21 @@ public class DefaultRollbackTrueRollbackAnnotationTransactionalTests extends Abs
|
||||
@Before
|
||||
public void verifyInitialTestData() {
|
||||
originalNumRows = clearPersonTable(jdbcTemplate);
|
||||
assertEquals("Adding bob", 1, addPerson(jdbcTemplate, BOB));
|
||||
assertEquals("Verifying the initial number of rows in the person table.", 1,
|
||||
countRowsInPersonTable(jdbcTemplate));
|
||||
assertThat(addPerson(jdbcTemplate, BOB)).as("Adding bob").isEqualTo(1);
|
||||
assertThat(countRowsInPersonTable(jdbcTemplate)).as("Verifying the initial number of rows in the person table.").isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test(timeout = 1000)
|
||||
public void modifyTestDataWithinTransaction() {
|
||||
assertInTransaction(true);
|
||||
assertEquals("Adding jane", 1, addPerson(jdbcTemplate, JANE));
|
||||
assertEquals("Adding sue", 1, addPerson(jdbcTemplate, SUE));
|
||||
assertEquals("Verifying the number of rows in the person table within a transaction.", 3,
|
||||
countRowsInPersonTable(jdbcTemplate));
|
||||
assertThat(addPerson(jdbcTemplate, JANE)).as("Adding jane").isEqualTo(1);
|
||||
assertThat(addPerson(jdbcTemplate, SUE)).as("Adding sue").isEqualTo(1);
|
||||
assertThat(countRowsInPersonTable(jdbcTemplate)).as("Verifying the number of rows in the person table within a transaction.").isEqualTo(3);
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void verifyFinalTestData() {
|
||||
assertEquals("Verifying the final number of rows in the person table after all tests.", originalNumRows,
|
||||
countRowsInPersonTable(jdbcTemplate));
|
||||
assertThat(countRowsInPersonTable(jdbcTemplate)).as("Verifying the final number of rows in the person table after all tests.").isEqualTo(originalNumRows);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -27,8 +27,8 @@ import org.springframework.test.annotation.ProfileValueSource;
|
||||
import org.springframework.test.annotation.ProfileValueSourceConfiguration;
|
||||
import org.springframework.test.context.TestExecutionListeners;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.fail;
|
||||
|
||||
/**
|
||||
* Verifies proper handling of JUnit's {@link Ignore @Ignore} and Spring's
|
||||
@@ -64,7 +64,7 @@ public class EnabledAndIgnoredSpringRunnerTests {
|
||||
|
||||
@AfterClass
|
||||
public static void verifyNumTestsExecuted() {
|
||||
assertEquals("Verifying the number of tests executed.", 3, numTestsExecuted);
|
||||
assertThat(numTestsExecuted).as("Verifying the number of tests executed.").isEqualTo(3);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -32,7 +32,7 @@ import org.springframework.test.context.transaction.BeforeTransaction;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.ClassUtils;
|
||||
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.assertj.core.api.Assertions.fail;
|
||||
import static org.springframework.test.context.junit4.JUnitTestingUtils.runTestsAndAssertCounters;
|
||||
|
||||
/**
|
||||
|
||||
@@ -35,7 +35,7 @@ import org.springframework.test.context.transaction.AfterTransaction;
|
||||
import org.springframework.test.context.transaction.BeforeTransaction;
|
||||
import org.springframework.util.ClassUtils;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Integration tests which verify that '<i>before</i>' and '<i>after</i>'
|
||||
@@ -104,11 +104,10 @@ public class FailingBeforeAndAfterMethodsTestNGTests {
|
||||
|
||||
String name = this.clazz.getSimpleName();
|
||||
|
||||
assertEquals("tests started for [" + name + "] ==> ", this.expectedTestStartCount, listener.testStartCount);
|
||||
assertEquals("successful tests for [" + name + "] ==> ", this.expectedTestSuccessCount, listener.testSuccessCount);
|
||||
assertEquals("failed tests for [" + name + "] ==> ", this.expectedFailureCount, listener.testFailureCount);
|
||||
assertEquals("failed configurations for [" + name + "] ==> ",
|
||||
this.expectedFailedConfigurationsCount, listener.failedConfigurationsCount);
|
||||
assertThat(listener.testStartCount).as("tests started for [" + name + "] ==> ").isEqualTo(this.expectedTestStartCount);
|
||||
assertThat(listener.testSuccessCount).as("successful tests for [" + name + "] ==> ").isEqualTo(this.expectedTestSuccessCount);
|
||||
assertThat(listener.testFailureCount).as("failed tests for [" + name + "] ==> ").isEqualTo(this.expectedFailureCount);
|
||||
assertThat(listener.failedConfigurationsCount).as("failed configurations for [" + name + "] ==> ").isEqualTo(this.expectedFailedConfigurationsCount);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ import org.springframework.test.context.support.DirtiesContextTestExecutionListe
|
||||
import org.springframework.test.context.transaction.TransactionalTestExecutionListener;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.springframework.test.transaction.TransactionTestUtils.assertInTransaction;
|
||||
|
||||
/**
|
||||
@@ -72,37 +72,33 @@ public class MethodLevelTransactionalSpringRunnerTests extends AbstractTransacti
|
||||
|
||||
@AfterClass
|
||||
public static void verifyFinalTestData() {
|
||||
assertEquals("Verifying the final number of rows in the person table after all tests.", 4,
|
||||
countRowsInPersonTable(jdbcTemplate));
|
||||
assertThat(countRowsInPersonTable(jdbcTemplate)).as("Verifying the final number of rows in the person table after all tests.").isEqualTo(4);
|
||||
}
|
||||
|
||||
@Before
|
||||
public void verifyInitialTestData() {
|
||||
clearPersonTable(jdbcTemplate);
|
||||
assertEquals("Adding bob", 1, addPerson(jdbcTemplate, BOB));
|
||||
assertEquals("Verifying the initial number of rows in the person table.", 1,
|
||||
countRowsInPersonTable(jdbcTemplate));
|
||||
assertThat(addPerson(jdbcTemplate, BOB)).as("Adding bob").isEqualTo(1);
|
||||
assertThat(countRowsInPersonTable(jdbcTemplate)).as("Verifying the initial number of rows in the person table.").isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Transactional("transactionManager2")
|
||||
public void modifyTestDataWithinTransaction() {
|
||||
assertInTransaction(true);
|
||||
assertEquals("Deleting bob", 1, deletePerson(jdbcTemplate, BOB));
|
||||
assertEquals("Adding jane", 1, addPerson(jdbcTemplate, JANE));
|
||||
assertEquals("Adding sue", 1, addPerson(jdbcTemplate, SUE));
|
||||
assertEquals("Verifying the number of rows in the person table within a transaction.", 2,
|
||||
countRowsInPersonTable(jdbcTemplate));
|
||||
assertThat(deletePerson(jdbcTemplate, BOB)).as("Deleting bob").isEqualTo(1);
|
||||
assertThat(addPerson(jdbcTemplate, JANE)).as("Adding jane").isEqualTo(1);
|
||||
assertThat(addPerson(jdbcTemplate, SUE)).as("Adding sue").isEqualTo(1);
|
||||
assertThat(countRowsInPersonTable(jdbcTemplate)).as("Verifying the number of rows in the person table within a transaction.").isEqualTo(2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void modifyTestDataWithoutTransaction() {
|
||||
assertInTransaction(false);
|
||||
assertEquals("Adding luke", 1, addPerson(jdbcTemplate, LUKE));
|
||||
assertEquals("Adding leia", 1, addPerson(jdbcTemplate, LEIA));
|
||||
assertEquals("Adding yoda", 1, addPerson(jdbcTemplate, YODA));
|
||||
assertEquals("Verifying the number of rows in the person table without a transaction.", 4,
|
||||
countRowsInPersonTable(jdbcTemplate));
|
||||
assertThat(addPerson(jdbcTemplate, LUKE)).as("Adding luke").isEqualTo(1);
|
||||
assertThat(addPerson(jdbcTemplate, LEIA)).as("Adding leia").isEqualTo(1);
|
||||
assertThat(addPerson(jdbcTemplate, YODA)).as("Adding yoda").isEqualTo(1);
|
||||
assertThat(countRowsInPersonTable(jdbcTemplate)).as("Verifying the number of rows in the person table without a transaction.").isEqualTo(4);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user