Skip to content

Commit 7f422f2

Browse files
Rebwonsbrannen
authored andcommitted
Polishing
Closes gh-26682
1 parent 70f0895 commit 7f422f2

File tree

3 files changed

+21
-20
lines changed

3 files changed

+21
-20
lines changed

spring-test/src/test/java/org/springframework/mock/web/MockFilterChainTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -55,7 +55,7 @@ void setup() {
5555
@Test
5656
void constructorNullServlet() {
5757
assertThatIllegalArgumentException().isThrownBy(() ->
58-
new MockFilterChain((Servlet) null));
58+
new MockFilterChain(null));
5959
}
6060

6161
@Test

spring-test/src/test/java/org/springframework/mock/web/MockHttpServletRequestTests.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2020 the original author or authors.
2+
* Copyright 2002-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -19,6 +19,7 @@
1919
import java.io.IOException;
2020
import java.net.URL;
2121
import java.nio.charset.Charset;
22+
import java.nio.charset.StandardCharsets;
2223
import java.util.ArrayList;
2324
import java.util.Arrays;
2425
import java.util.Collections;
@@ -112,7 +113,7 @@ void getContentAsStringWithoutSettingCharacterEncoding() throws IOException {
112113
@Test
113114
void setContentAndGetContentAsStringWithExplicitCharacterEncoding() throws IOException {
114115
String palindrome = "ablE was I ere I saw Elba";
115-
byte[] bytes = palindrome.getBytes("UTF-16");
116+
byte[] bytes = palindrome.getBytes(StandardCharsets.UTF_16);
116117
request.setCharacterEncoding("UTF-16");
117118
request.setContent(bytes);
118119
assertThat(request.getContentLength()).isEqualTo(bytes.length);
@@ -394,7 +395,7 @@ void getServerNameViaHostHeaderWithPort() {
394395
void getServerNameWithInvalidIpv6AddressViaHostHeader() {
395396
request.addHeader(HOST, "[::ffff:abcd:abcd"); // missing closing bracket
396397
assertThatIllegalStateException()
397-
.isThrownBy(() -> request.getServerName())
398+
.isThrownBy(request::getServerName)
398399
.withMessageStartingWith("Invalid Host header: ");
399400
}
400401

@@ -426,15 +427,15 @@ void getServerPortWithCustomPort() {
426427
void getServerPortWithInvalidIpv6AddressViaHostHeader() {
427428
request.addHeader(HOST, "[::ffff:abcd:abcd:8080"); // missing closing bracket
428429
assertThatIllegalStateException()
429-
.isThrownBy(() -> request.getServerPort())
430+
.isThrownBy(request::getServerPort)
430431
.withMessageStartingWith("Invalid Host header: ");
431432
}
432433

433434
@Test
434435
void getServerPortWithIpv6AddressAndInvalidPortViaHostHeader() {
435436
request.addHeader(HOST, "[::ffff:abcd:abcd]:bogus"); // "bogus" is not a port number
436437
assertThatExceptionOfType(NumberFormatException.class)
437-
.isThrownBy(() -> request.getServerPort())
438+
.isThrownBy(request::getServerPort)
438439
.withMessageContaining("bogus");
439440
}
440441

@@ -521,7 +522,7 @@ void getRequestURLWithIpv6AddressViaServerNameWithPort() throws Exception {
521522
void getRequestURLWithInvalidIpv6AddressViaHostHeader() {
522523
request.addHeader(HOST, "[::ffff:abcd:abcd"); // missing closing bracket
523524
assertThatIllegalStateException()
524-
.isThrownBy(() -> request.getRequestURL())
525+
.isThrownBy(request::getRequestURL)
525526
.withMessageStartingWith("Invalid Host header: ");
526527
}
527528

spring-test/src/test/java/org/springframework/test/web/servlet/setup/StandaloneMockMvcBuilderTests.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -49,10 +49,10 @@
4949
* @author Rob Winch
5050
* @author Sebastien Deleuze
5151
*/
52-
public class StandaloneMockMvcBuilderTests {
52+
class StandaloneMockMvcBuilderTests {
5353

5454
@Test // SPR-10825
55-
public void placeHoldersInRequestMapping() throws Exception {
55+
void placeHoldersInRequestMapping() throws Exception {
5656
TestStandaloneMockMvcBuilder builder = new TestStandaloneMockMvcBuilder(new PlaceholderController());
5757
builder.addPlaceholderValue("sys.login.ajax", "/foo");
5858
builder.build();
@@ -68,7 +68,7 @@ public void placeHoldersInRequestMapping() throws Exception {
6868

6969
@Test // SPR-13637
7070
@SuppressWarnings("deprecation")
71-
public void suffixPatternMatch() throws Exception {
71+
void suffixPatternMatch() throws Exception {
7272
TestStandaloneMockMvcBuilder builder = new TestStandaloneMockMvcBuilder(new PersonController());
7373
builder.setUseSuffixPatternMatch(false);
7474
builder.build();
@@ -86,44 +86,44 @@ public void suffixPatternMatch() throws Exception {
8686
}
8787

8888
@Test // SPR-12553
89-
public void applicationContextAttribute() {
89+
void applicationContextAttribute() {
9090
TestStandaloneMockMvcBuilder builder = new TestStandaloneMockMvcBuilder(new PlaceholderController());
9191
builder.addPlaceholderValue("sys.login.ajax", "/foo");
9292
WebApplicationContext wac = builder.initWebAppContext();
9393
assertThat(WebApplicationContextUtils.getRequiredWebApplicationContext(wac.getServletContext())).isEqualTo(wac);
9494
}
9595

9696
@Test
97-
public void addFiltersFiltersNull() {
97+
void addFiltersFiltersNull() {
9898
StandaloneMockMvcBuilder builder = MockMvcBuilders.standaloneSetup(new PersonController());
9999
assertThatIllegalArgumentException().isThrownBy(() ->
100100
builder.addFilters((Filter[]) null));
101101
}
102102

103103
@Test
104-
public void addFiltersFiltersContainsNull() {
104+
void addFiltersFiltersContainsNull() {
105105
StandaloneMockMvcBuilder builder = MockMvcBuilders.standaloneSetup(new PersonController());
106106
assertThatIllegalArgumentException().isThrownBy(() ->
107-
builder.addFilters(new ContinueFilter(), (Filter) null));
107+
builder.addFilters(new ContinueFilter(), null));
108108
}
109109

110110
@Test
111-
public void addFilterPatternsNull() {
111+
void addFilterPatternsNull() {
112112
StandaloneMockMvcBuilder builder = MockMvcBuilders.standaloneSetup(new PersonController());
113113
assertThatIllegalArgumentException().isThrownBy(() ->
114114
builder.addFilter(new ContinueFilter(), (String[]) null));
115115
}
116116

117117
@Test
118-
public void addFilterPatternContainsNull() {
118+
void addFilterPatternContainsNull() {
119119
StandaloneMockMvcBuilder builder = MockMvcBuilders.standaloneSetup(new PersonController());
120120
assertThatIllegalArgumentException().isThrownBy(() ->
121121
builder.addFilter(new ContinueFilter(), (String) null));
122122
}
123123

124124
@Test // SPR-13375
125125
@SuppressWarnings("rawtypes")
126-
public void springHandlerInstantiator() {
126+
void springHandlerInstantiator() {
127127
TestStandaloneMockMvcBuilder builder = new TestStandaloneMockMvcBuilder(new PersonController());
128128
builder.build();
129129
SpringHandlerInstantiator instantiator = new SpringHandlerInstantiator(builder.wac.getAutowireCapableBeanFactory());
@@ -171,7 +171,7 @@ public String forward() {
171171
}
172172

173173

174-
private class ContinueFilter extends OncePerRequestFilter {
174+
private static class ContinueFilter extends OncePerRequestFilter {
175175

176176
@Override
177177
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response,

0 commit comments

Comments
 (0)