Skip to content

Commit 73a1c2d

Browse files
committed
Polish
1 parent 2b56ca0 commit 73a1c2d

File tree

9 files changed

+58
-55
lines changed

9 files changed

+58
-55
lines changed

spring-test/src/main/java/org/springframework/test/json/JsonLoader.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,11 @@ String getJson(@Nullable CharSequence source) {
5454
if (source == null) {
5555
return null;
5656
}
57-
String string = source.toString();
58-
if (string.endsWith(".json")) {
59-
return getJson(new ClassPathResource(string, this.resourceLoadClass));
57+
String jsonSource = source.toString();
58+
if (jsonSource.endsWith(".json")) {
59+
return getJson(new ClassPathResource(jsonSource, this.resourceLoadClass));
6060
}
61-
return string;
61+
return jsonSource;
6262
}
6363

6464
String getJson(Resource source) {

spring-test/src/main/java/org/springframework/test/web/UriAssert.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,9 @@ public UriAssert isEqualToTemplate(String uriTemplate, Object... uriVars) {
6969
* assertThat(uri).matchPattern("/orders/*"));
7070
* </code></pre>
7171
* @param uriPattern the pattern that is expected to match
72+
* @see AntPathMatcher
7273
*/
73-
public UriAssert matchesPattern(String uriPattern) {
74+
public UriAssert matchesAntPattern(String uriPattern) {
7475
Assertions.assertThat(pathMatcher.isPattern(uriPattern))
7576
.withFailMessage("'%s' is not an Ant-style path pattern", uriPattern).isTrue();
7677
Assertions.assertThat(pathMatcher.match(uriPattern, this.actual))

spring-test/src/main/java/org/springframework/test/web/servlet/assertj/AbstractHttpServletRequestAssert.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public MapAssert<String, Object> sessionAttributes() {
104104
*/
105105
public SELF hasAsyncStarted(boolean started) {
106106
Assertions.assertThat(this.actual.isAsyncStarted())
107-
.withFailMessage("Async expected %sto have started", (started ? "" : "not "))
107+
.withFailMessage("Async expected %s have started", (started ? "to" : "not to"))
108108
.isEqualTo(started);
109109
return this.myself;
110110
}

spring-test/src/main/java/org/springframework/test/web/servlet/assertj/CookieMapAssert.java

+7-8
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public CookieMapAssert hasCookieSatisfying(String name, Consumer<Cookie> cookieR
9898

9999
/**
100100
* Verify that the actual cookies contain a cookie with the given {@code name}
101-
* whose {@linkplain Cookie#getValue() value} is equal to the expected value.
101+
* whose {@linkplain Cookie#getValue() value} is equal to the given one.
102102
* @param name the name of the cookie
103103
* @param expected the expected value of the cookie
104104
*/
@@ -109,7 +109,7 @@ public CookieMapAssert hasValue(String name, String expected) {
109109

110110
/**
111111
* Verify that the actual cookies contain a cookie with the given {@code name}
112-
* whose {@linkplain Cookie#getMaxAge() max age} is equal to the expected value.
112+
* whose {@linkplain Cookie#getMaxAge() max age} is equal to the given one.
113113
* @param name the name of the cookie
114114
* @param expected the expected max age of the cookie
115115
*/
@@ -120,7 +120,7 @@ public CookieMapAssert hasMaxAge(String name, Duration expected) {
120120

121121
/**
122122
* Verify that the actual cookies contain a cookie with the given {@code name}
123-
* whose {@linkplain Cookie#getPath() path} is equal to the expected value.
123+
* whose {@linkplain Cookie#getPath() path} is equal to the given one.
124124
* @param name the name of the cookie
125125
* @param expected the expected path of the cookie
126126
*/
@@ -131,7 +131,7 @@ public CookieMapAssert hasPath(String name, String expected) {
131131

132132
/**
133133
* Verify that the actual cookies contain a cookie with the given {@code name}
134-
* whose {@linkplain Cookie#getDomain() domain} is equal to the expected value.
134+
* whose {@linkplain Cookie#getDomain() domain} is equal to the given one.
135135
* @param name the name of the cookie
136136
* @param expected the expected domain of the cookie
137137
*/
@@ -142,8 +142,7 @@ public CookieMapAssert hasDomain(String name, String expected) {
142142

143143
/**
144144
* Verify that the actual cookies contain a cookie with the given {@code name}
145-
* whose {@linkplain Cookie#getSecure() secure flag} is equal to the expected
146-
* value.
145+
* whose {@linkplain Cookie#getSecure() secure flag} is equal to the give one.
147146
* @param name the name of the cookie
148147
* @param expected whether the cookie is secure
149148
*/
@@ -154,8 +153,8 @@ public CookieMapAssert isSecure(String name, boolean expected) {
154153

155154
/**
156155
* Verify that the actual cookies contain a cookie with the given {@code name}
157-
* whose {@linkplain Cookie#isHttpOnly() http only flag} is equal to the
158-
* expected value.
156+
* whose {@linkplain Cookie#isHttpOnly() http only flag} is equal to the given
157+
* one.
159158
* @param name the name of the cookie
160159
* @param expected whether the cookie is http only
161160
*/

spring-test/src/test/java/org/springframework/test/web/UriAssertTests.java

+6-6
Original file line numberDiff line numberDiff line change
@@ -51,21 +51,21 @@ void isEqualToTemplateMissingArg() {
5151
}
5252

5353
@Test
54-
void matchesPattern() {
55-
assertThat("/orders/1").matchesPattern("/orders/*");
54+
void matchesAntPattern() {
55+
assertThat("/orders/1").matchesAntPattern("/orders/*");
5656
}
5757

5858
@Test
59-
void matchesPatternWithNonValidPattern() {
59+
void matchesAntPatternWithNonValidPattern() {
6060
assertThatExceptionOfType(AssertionError.class)
61-
.isThrownBy(() -> assertThat("/orders/1").matchesPattern("/orders/"))
61+
.isThrownBy(() -> assertThat("/orders/1").matchesAntPattern("/orders/"))
6262
.withMessage("'/orders/' is not an Ant-style path pattern");
6363
}
6464

6565
@Test
66-
void matchesPatternWithWrongValue() {
66+
void matchesAntPatternWithWrongValue() {
6767
assertThatExceptionOfType(AssertionError.class)
68-
.isThrownBy(() -> assertThat("/orders/1").matchesPattern("/resources/*"))
68+
.isThrownBy(() -> assertThat("/orders/1").matchesAntPattern("/resources/*"))
6969
.withMessageContainingAll("Test URI", "/resources/*", "/orders/1");
7070
}
7171

spring-test/src/test/java/org/springframework/test/web/servlet/assertj/AbstractMockHttpServletResponseAssertTests.java

+9-6
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@
1818

1919

2020
import java.io.UnsupportedEncodingException;
21+
import java.nio.charset.StandardCharsets;
2122

2223
import org.junit.jupiter.api.Test;
2324

2425
import org.springframework.http.HttpHeaders;
2526
import org.springframework.mock.web.MockHttpServletResponse;
2627

27-
import static java.nio.charset.StandardCharsets.UTF_8;
2828
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
2929

3030
/**
@@ -34,19 +34,18 @@
3434
*/
3535
public class AbstractMockHttpServletResponseAssertTests {
3636

37-
private MockHttpServletResponse response = new MockHttpServletResponse();
38-
39-
4037
@Test
4138
void hasForwardedUrl() {
4239
String forwardedUrl = "https://example.com/42";
40+
MockHttpServletResponse response = new MockHttpServletResponse();
4341
response.setForwardedUrl(forwardedUrl);
4442
assertThat(response).hasForwardedUrl(forwardedUrl);
4543
}
4644

4745
@Test
4846
void hasForwardedUrlWithWrongValue() {
4947
String forwardedUrl = "https://example.com/42";
48+
MockHttpServletResponse response = new MockHttpServletResponse();
5049
response.setForwardedUrl(forwardedUrl);
5150
assertThatExceptionOfType(AssertionError.class)
5251
.isThrownBy(() -> assertThat(response).hasForwardedUrl("another"))
@@ -56,13 +55,15 @@ void hasForwardedUrlWithWrongValue() {
5655
@Test
5756
void hasRedirectedUrl() {
5857
String redirectedUrl = "https://example.com/42";
58+
MockHttpServletResponse response = new MockHttpServletResponse();
5959
response.addHeader(HttpHeaders.LOCATION, redirectedUrl);
6060
assertThat(response).hasRedirectedUrl(redirectedUrl);
6161
}
6262

6363
@Test
6464
void hasRedirectedUrlWithWrongValue() {
6565
String redirectedUrl = "https://example.com/42";
66+
MockHttpServletResponse response = new MockHttpServletResponse();
6667
response.addHeader(HttpHeaders.LOCATION, redirectedUrl);
6768
assertThatExceptionOfType(AssertionError.class)
6869
.isThrownBy(() -> assertThat(response).hasRedirectedUrl("another"))
@@ -71,15 +72,17 @@ void hasRedirectedUrlWithWrongValue() {
7172

7273
@Test
7374
void bodyHasContent() throws UnsupportedEncodingException {
75+
MockHttpServletResponse response = new MockHttpServletResponse();
7476
response.getWriter().write("OK");
7577
assertThat(response).body().asString().isEqualTo("OK");
7678
}
7779

7880
@Test
7981
void bodyHasContentWithResponseCharacterEncoding() throws UnsupportedEncodingException {
80-
byte[] bytes = "OK".getBytes(UTF_8);
82+
byte[] bytes = "OK".getBytes(StandardCharsets.UTF_8);
83+
MockHttpServletResponse response = new MockHttpServletResponse();
8184
response.getWriter().write("OK");
82-
response.setContentType(UTF_8.name());
85+
response.setContentType(StandardCharsets.UTF_8.name());
8386
assertThat(response).body().isEqualTo(bytes);
8487
}
8588

spring-test/src/test/java/org/springframework/test/web/servlet/assertj/CookieMapAssertTests.java

+24-24
Original file line numberDiff line numberDiff line change
@@ -52,130 +52,130 @@ static void setup() {
5252

5353
@Test
5454
void containsCookieWhenCookieExistsShouldPass() {
55-
cookies().containsCookie("framework");
55+
assertThat(cookies()).containsCookie("framework");
5656
}
5757

5858
@Test
5959
void containsCookieWhenCookieMissingShouldFail() {
6060
assertThatExceptionOfType(AssertionError.class).isThrownBy(() ->
61-
cookies().containsCookie("missing"));
61+
assertThat(cookies()).containsCookie("missing"));
6262
}
6363

6464
@Test
6565
void containsCookiesWhenCookiesExistShouldPass() {
66-
cookies().containsCookies("framework", "age");
66+
assertThat(cookies()).containsCookies("framework", "age");
6767
}
6868

6969
@Test
7070
void containsCookiesWhenCookieMissingShouldFail() {
7171
assertThatExceptionOfType(AssertionError.class).isThrownBy(() ->
72-
cookies().containsCookies("framework", "missing"));
72+
assertThat(cookies()).containsCookies("framework", "missing"));
7373
}
7474

7575
@Test
7676
void doesNotContainCookieWhenCookieMissingShouldPass() {
77-
cookies().doesNotContainCookie("missing");
77+
assertThat(cookies()).doesNotContainCookie("missing");
7878
}
7979

8080
@Test
8181
void doesNotContainCookieWhenCookieExistsShouldFail() {
8282
assertThatExceptionOfType(AssertionError.class).isThrownBy(() ->
83-
cookies().doesNotContainCookie("framework"));
83+
assertThat(cookies()).doesNotContainCookie("framework"));
8484
}
8585

8686
@Test
8787
void doesNotContainCookiesWhenCookiesMissingShouldPass() {
88-
cookies().doesNotContainCookies("missing", "missing2");
88+
assertThat(cookies()).doesNotContainCookies("missing", "missing2");
8989
}
9090

9191
@Test
9292
void doesNotContainCookiesWhenAtLeastOneCookieExistShouldFail() {
9393
assertThatExceptionOfType(AssertionError.class).isThrownBy(() ->
94-
cookies().doesNotContainCookies("missing", "framework"));
94+
assertThat(cookies()).doesNotContainCookies("missing", "framework"));
9595
}
9696

9797
@Test
9898
void hasValueEqualsWhenCookieValueMatchesShouldPass() {
99-
cookies().hasValue("framework", "spring");
99+
assertThat(cookies()).hasValue("framework", "spring");
100100
}
101101

102102
@Test
103103
void hasValueEqualsWhenCookieValueDiffersShouldFail() {
104104
assertThatExceptionOfType(AssertionError.class).isThrownBy(() ->
105-
cookies().hasValue("framework", "other"));
105+
assertThat(cookies()).hasValue("framework", "other"));
106106
}
107107

108108
@Test
109109
void hasCookieSatisfyingWhenCookieValueMatchesShouldPass() {
110-
cookies().hasCookieSatisfying("framework", cookie ->
110+
assertThat(cookies()).hasCookieSatisfying("framework", cookie ->
111111
assertThat(cookie.getValue()).startsWith("spr"));
112112
}
113113

114114
@Test
115115
void hasCookieSatisfyingWhenCookieValueDiffersShouldFail() {
116116
assertThatExceptionOfType(AssertionError.class).isThrownBy(() ->
117-
cookies().hasCookieSatisfying("framework", cookie ->
117+
assertThat(cookies()).hasCookieSatisfying("framework", cookie ->
118118
assertThat(cookie.getValue()).startsWith("not")));
119119
}
120120

121121
@Test
122122
void hasMaxAgeWhenCookieAgeMatchesShouldPass() {
123-
cookies().hasMaxAge("age", Duration.ofMinutes(20));
123+
assertThat(cookies()).hasMaxAge("age", Duration.ofMinutes(20));
124124
}
125125

126126
@Test
127127
void hasMaxAgeWhenCookieAgeDiffersShouldFail() {
128128
assertThatExceptionOfType(AssertionError.class).isThrownBy(() ->
129-
cookies().hasMaxAge("age", Duration.ofMinutes(30)));
129+
assertThat(cookies()).hasMaxAge("age", Duration.ofMinutes(30)));
130130
}
131131

132132
@Test
133133
void pathWhenCookiePathMatchesShouldPass() {
134-
cookies().hasPath("path", "/spring");
134+
assertThat(cookies()).hasPath("path", "/spring");
135135
}
136136

137137
@Test
138138
void pathWhenCookiePathDiffersShouldFail() {
139139
assertThatExceptionOfType(AssertionError.class).isThrownBy(() ->
140-
cookies().hasPath("path", "/other"));
140+
assertThat(cookies()).hasPath("path", "/other"));
141141
}
142142

143143
@Test
144144
void hasDomainWhenCookieDomainMatchesShouldPass() {
145-
cookies().hasDomain("domain", "spring.io");
145+
assertThat(cookies()).hasDomain("domain", "spring.io");
146146
}
147147

148148
@Test
149149
void hasDomainWhenCookieDomainDiffersShouldFail() {
150150
assertThatExceptionOfType(AssertionError.class).isThrownBy(() ->
151-
cookies().hasDomain("domain", "example.org"));
151+
assertThat(cookies()).hasDomain("domain", "example.org"));
152152
}
153153

154154
@Test
155155
void isSecureWhenCookieSecureMatchesShouldPass() {
156-
cookies().isSecure("framework", true);
156+
assertThat(cookies()).isSecure("framework", true);
157157
}
158158

159159
@Test
160160
void isSecureWhenCookieSecureDiffersShouldFail() {
161161
assertThatExceptionOfType(AssertionError.class).isThrownBy(() ->
162-
cookies().isSecure("domain", true));
162+
assertThat(cookies()).isSecure("domain", true));
163163
}
164164

165165
@Test
166166
void isHttpOnlyWhenCookieHttpOnlyMatchesShouldPass() {
167-
cookies().isHttpOnly("framework", true);
167+
assertThat(cookies()).isHttpOnly("framework", true);
168168
}
169169

170170
@Test
171171
void isHttpOnlyWhenCookieHttpOnlyDiffersShouldFail() {
172172
assertThatExceptionOfType(AssertionError.class).isThrownBy(() ->
173-
cookies().isHttpOnly("domain", true));
173+
assertThat(cookies()).isHttpOnly("domain", true));
174174
}
175175

176176

177-
private static CookieMapAssert cookies() {
178-
return assertThat((AssertProvider<CookieMapAssert>) () -> new CookieMapAssert(cookies));
177+
private static AssertProvider<CookieMapAssert> cookies() {
178+
return () -> new CookieMapAssert(cookies);
179179
}
180180

181181
}

spring-test/src/test/java/org/springframework/test/web/servlet/assertj/HandlerResultAssertTests.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -128,12 +128,12 @@ private static Method method(Class<?> target, String name, Class<?>... parameter
128128
static class TestController {
129129

130130
@GetMapping("/greet")
131-
public ResponseEntity<String> greet() {
131+
ResponseEntity<String> greet() {
132132
return ResponseEntity.ok().body("Hello");
133133
}
134134

135135
@PostMapping("/update")
136-
public void update() {
136+
void update() {
137137
}
138138

139139
}

spring-test/src/test/java/org/springframework/test/web/servlet/assertj/ResponseBodyAssertTests.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@
1919

2020
import java.io.UnsupportedEncodingException;
2121
import java.nio.charset.Charset;
22+
import java.nio.charset.StandardCharsets;
2223

2324
import org.assertj.core.api.AssertProvider;
2425
import org.junit.jupiter.api.Test;
2526

2627
import org.springframework.mock.web.MockHttpServletResponse;
2728
import org.springframework.test.json.JsonContent;
2829

29-
import static java.nio.charset.StandardCharsets.UTF_8;
3030
import static org.assertj.core.api.Assertions.assertThat;
3131

3232
/**
@@ -40,8 +40,8 @@ class ResponseBodyAssertTests {
4040
@Test
4141
void isEqualToWithByteArray() {
4242
MockHttpServletResponse response = createResponse("hello");
43-
response.setCharacterEncoding(UTF_8.name());
44-
assertThat(fromResponse(response)).isEqualTo("hello".getBytes(UTF_8));
43+
response.setCharacterEncoding(StandardCharsets.UTF_8.name());
44+
assertThat(fromResponse(response)).isEqualTo("hello".getBytes(StandardCharsets.UTF_8));
4545
}
4646

4747
@Test

0 commit comments

Comments
 (0)