Skip to content

Commit

Permalink
Polishing
Browse files Browse the repository at this point in the history
Closes gh-26682
  • Loading branch information
Rebwon authored and sbrannen committed Mar 15, 2021
1 parent 70f0895 commit 7f422f2
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -55,7 +55,7 @@ void setup() {
@Test
void constructorNullServlet() {
assertThatIllegalArgumentException().isThrownBy(() ->
new MockFilterChain((Servlet) null));
new MockFilterChain(null));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2020 the original author or authors.
* Copyright 2002-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -19,6 +19,7 @@
import java.io.IOException;
import java.net.URL;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
Expand Down Expand Up @@ -112,7 +113,7 @@ void getContentAsStringWithoutSettingCharacterEncoding() throws IOException {
@Test
void setContentAndGetContentAsStringWithExplicitCharacterEncoding() throws IOException {
String palindrome = "ablE was I ere I saw Elba";
byte[] bytes = palindrome.getBytes("UTF-16");
byte[] bytes = palindrome.getBytes(StandardCharsets.UTF_16);
request.setCharacterEncoding("UTF-16");
request.setContent(bytes);
assertThat(request.getContentLength()).isEqualTo(bytes.length);
Expand Down Expand Up @@ -394,7 +395,7 @@ void getServerNameViaHostHeaderWithPort() {
void getServerNameWithInvalidIpv6AddressViaHostHeader() {
request.addHeader(HOST, "[::ffff:abcd:abcd"); // missing closing bracket
assertThatIllegalStateException()
.isThrownBy(() -> request.getServerName())
.isThrownBy(request::getServerName)
.withMessageStartingWith("Invalid Host header: ");
}

Expand Down Expand Up @@ -426,15 +427,15 @@ void getServerPortWithCustomPort() {
void getServerPortWithInvalidIpv6AddressViaHostHeader() {
request.addHeader(HOST, "[::ffff:abcd:abcd:8080"); // missing closing bracket
assertThatIllegalStateException()
.isThrownBy(() -> request.getServerPort())
.isThrownBy(request::getServerPort)
.withMessageStartingWith("Invalid Host header: ");
}

@Test
void getServerPortWithIpv6AddressAndInvalidPortViaHostHeader() {
request.addHeader(HOST, "[::ffff:abcd:abcd]:bogus"); // "bogus" is not a port number
assertThatExceptionOfType(NumberFormatException.class)
.isThrownBy(() -> request.getServerPort())
.isThrownBy(request::getServerPort)
.withMessageContaining("bogus");
}

Expand Down Expand Up @@ -521,7 +522,7 @@ void getRequestURLWithIpv6AddressViaServerNameWithPort() throws Exception {
void getRequestURLWithInvalidIpv6AddressViaHostHeader() {
request.addHeader(HOST, "[::ffff:abcd:abcd"); // missing closing bracket
assertThatIllegalStateException()
.isThrownBy(() -> request.getRequestURL())
.isThrownBy(request::getRequestURL)
.withMessageStartingWith("Invalid Host header: ");
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -49,10 +49,10 @@
* @author Rob Winch
* @author Sebastien Deleuze
*/
public class StandaloneMockMvcBuilderTests {
class StandaloneMockMvcBuilderTests {

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

@Test // SPR-13637
@SuppressWarnings("deprecation")
public void suffixPatternMatch() throws Exception {
void suffixPatternMatch() throws Exception {
TestStandaloneMockMvcBuilder builder = new TestStandaloneMockMvcBuilder(new PersonController());
builder.setUseSuffixPatternMatch(false);
builder.build();
Expand All @@ -86,44 +86,44 @@ public void suffixPatternMatch() throws Exception {
}

@Test // SPR-12553
public void applicationContextAttribute() {
void applicationContextAttribute() {
TestStandaloneMockMvcBuilder builder = new TestStandaloneMockMvcBuilder(new PlaceholderController());
builder.addPlaceholderValue("sys.login.ajax", "/foo");
WebApplicationContext wac = builder.initWebAppContext();
assertThat(WebApplicationContextUtils.getRequiredWebApplicationContext(wac.getServletContext())).isEqualTo(wac);
}

@Test
public void addFiltersFiltersNull() {
void addFiltersFiltersNull() {
StandaloneMockMvcBuilder builder = MockMvcBuilders.standaloneSetup(new PersonController());
assertThatIllegalArgumentException().isThrownBy(() ->
builder.addFilters((Filter[]) null));
}

@Test
public void addFiltersFiltersContainsNull() {
void addFiltersFiltersContainsNull() {
StandaloneMockMvcBuilder builder = MockMvcBuilders.standaloneSetup(new PersonController());
assertThatIllegalArgumentException().isThrownBy(() ->
builder.addFilters(new ContinueFilter(), (Filter) null));
builder.addFilters(new ContinueFilter(), null));
}

@Test
public void addFilterPatternsNull() {
void addFilterPatternsNull() {
StandaloneMockMvcBuilder builder = MockMvcBuilders.standaloneSetup(new PersonController());
assertThatIllegalArgumentException().isThrownBy(() ->
builder.addFilter(new ContinueFilter(), (String[]) null));
}

@Test
public void addFilterPatternContainsNull() {
void addFilterPatternContainsNull() {
StandaloneMockMvcBuilder builder = MockMvcBuilders.standaloneSetup(new PersonController());
assertThatIllegalArgumentException().isThrownBy(() ->
builder.addFilter(new ContinueFilter(), (String) null));
}

@Test // SPR-13375
@SuppressWarnings("rawtypes")
public void springHandlerInstantiator() {
void springHandlerInstantiator() {
TestStandaloneMockMvcBuilder builder = new TestStandaloneMockMvcBuilder(new PersonController());
builder.build();
SpringHandlerInstantiator instantiator = new SpringHandlerInstantiator(builder.wac.getAutowireCapableBeanFactory());
Expand Down Expand Up @@ -171,7 +171,7 @@ public String forward() {
}


private class ContinueFilter extends OncePerRequestFilter {
private static class ContinueFilter extends OncePerRequestFilter {

@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response,
Expand Down

0 comments on commit 7f422f2

Please sign in to comment.