Fix mockito UnnecessaryStubbingException

This commit is contained in:
Rob Winch
2021-07-08 14:52:45 -05:00
parent 2a62c4d976
commit b6ff4d3674
22 changed files with 252 additions and 42 deletions

View File

@@ -23,7 +23,6 @@ import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
@@ -76,8 +75,7 @@ public class AuthenticationFilterTests {
@Mock
private RequestMatcher requestMatcher;
@BeforeEach
public void setup() {
private void givenResolveWillReturnAuthenticationManager() {
given(this.authenticationManagerResolver.resolve(any())).willReturn(this.authenticationManager);
}
@@ -131,6 +129,7 @@ public class AuthenticationFilterTests {
@Test
public void filterWhenAuthenticationManagerResolverDefaultsAndAuthenticationSuccessThenContinues()
throws Exception {
givenResolveWillReturnAuthenticationManager();
Authentication authentication = new TestingAuthenticationToken("test", "this", "ROLE");
given(this.authenticationConverter.convert(any())).willReturn(authentication);
given(this.authenticationManager.authenticate(any())).willReturn(authentication);
@@ -163,6 +162,7 @@ public class AuthenticationFilterTests {
@Test
public void filterWhenAuthenticationManagerResolverDefaultsAndAuthenticationFailThenUnauthorized()
throws Exception {
givenResolveWillReturnAuthenticationManager();
Authentication authentication = new TestingAuthenticationToken("test", "this", "ROLE");
given(this.authenticationConverter.convert(any())).willReturn(authentication);
given(this.authenticationManager.authenticate(any())).willThrow(new BadCredentialsException("failed"));
@@ -191,6 +191,7 @@ public class AuthenticationFilterTests {
@Test
public void filterWhenConvertAndAuthenticationSuccessThenSuccess() throws Exception {
givenResolveWillReturnAuthenticationManager();
Authentication authentication = new TestingAuthenticationToken("test", "this", "ROLE_USER");
given(this.authenticationConverter.convert(any())).willReturn(authentication);
given(this.authenticationManager.authenticate(any())).willReturn(authentication);
@@ -208,6 +209,7 @@ public class AuthenticationFilterTests {
@Test
public void filterWhenConvertAndAuthenticationEmptyThenServerError() throws Exception {
givenResolveWillReturnAuthenticationManager();
Authentication authentication = new TestingAuthenticationToken("test", "this", "ROLE_USER");
given(this.authenticationConverter.convert(any())).willReturn(authentication);
given(this.authenticationManager.authenticate(any())).willReturn(null);

View File

@@ -56,8 +56,6 @@ public class LazyCsrfTokenRepositoryTests {
@BeforeEach
public void setup() {
this.token = new DefaultCsrfToken("header", "param", "token");
given(this.delegate.generateToken(this.request)).willReturn(this.token);
given(this.request.getAttribute(HttpServletResponse.class.getName())).willReturn(this.response);
}
@Test
@@ -73,6 +71,8 @@ public class LazyCsrfTokenRepositoryTests {
@Test
public void generateTokenGetTokenSavesToken() {
given(this.delegate.generateToken(this.request)).willReturn(this.token);
given(this.request.getAttribute(HttpServletResponse.class.getName())).willReturn(this.response);
CsrfToken newToken = this.repository.generateToken(this.request);
newToken.getToken();
verify(this.delegate).saveToken(this.token, this.request, this.response);

View File

@@ -77,15 +77,19 @@ public class DebugFilterTests {
@BeforeEach
public void setUp() {
given(this.request.getHeaderNames()).willReturn(Collections.enumeration(Collections.<String>emptyList()));
given(this.request.getServletPath()).willReturn("/login");
this.filter = new DebugFilter(this.fcp);
ReflectionTestUtils.setField(this.filter, "logger", this.logger);
this.requestAttr = DebugFilter.ALREADY_FILTERED_ATTR_NAME;
}
private void setupMocks() {
given(this.request.getHeaderNames()).willReturn(Collections.enumeration(Collections.<String>emptyList()));
given(this.request.getServletPath()).willReturn("/login");
}
@Test
public void doFilterProcessesRequests() throws Exception {
setupMocks();
this.filter.doFilter(this.request, this.response, this.filterChain);
verify(this.logger).info(anyString());
verify(this.request).setAttribute(this.requestAttr, Boolean.TRUE);
@@ -97,6 +101,7 @@ public class DebugFilterTests {
// SEC-1901
@Test
public void doFilterProcessesForwardedRequests() throws Exception {
setupMocks();
given(this.request.getAttribute(this.requestAttr)).willReturn(Boolean.TRUE);
HttpServletRequest request = new DebugRequestWrapper(this.request);
this.filter.doFilter(request, this.response, this.filterChain);
@@ -107,6 +112,7 @@ public class DebugFilterTests {
@Test
public void doFilterDoesNotWrapWithDebugRequestWrapperAgain() throws Exception {
setupMocks();
given(this.request.getAttribute(this.requestAttr)).willReturn(Boolean.TRUE);
HttpServletRequest fireWalledRequest = new HttpServletRequestWrapper(new DebugRequestWrapper(this.request));
this.filter.doFilter(fireWalledRequest, this.response, this.filterChain);

View File

@@ -21,7 +21,6 @@ import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
@@ -60,9 +59,11 @@ public class DelegatingServerAuthenticationSuccessHandlerTests {
@Mock
private Authentication authentication;
@BeforeEach
public void setup() {
private void givenDelegate1WillReturnMock() {
given(this.delegate1.onAuthenticationSuccess(any(), any())).willReturn(this.delegate1Result.mono());
}
private void givenDelegate2WillReturnMock() {
given(this.delegate2.onAuthenticationSuccess(any(), any())).willReturn(this.delegate2Result.mono());
}
@@ -80,6 +81,7 @@ public class DelegatingServerAuthenticationSuccessHandlerTests {
@Test
public void onAuthenticationSuccessWhenSingleThenExecuted() {
givenDelegate1WillReturnMock();
DelegatingServerAuthenticationSuccessHandler handler = new DelegatingServerAuthenticationSuccessHandler(
this.delegate1);
handler.onAuthenticationSuccess(this.exchange, this.authentication).block();
@@ -88,6 +90,8 @@ public class DelegatingServerAuthenticationSuccessHandlerTests {
@Test
public void onAuthenticationSuccessWhenMultipleThenExecuted() {
givenDelegate1WillReturnMock();
givenDelegate2WillReturnMock();
DelegatingServerAuthenticationSuccessHandler handler = new DelegatingServerAuthenticationSuccessHandler(
this.delegate1, this.delegate2);
handler.onAuthenticationSuccess(this.exchange, this.authentication).block();

View File

@@ -16,7 +16,6 @@
package org.springframework.security.web.server.authentication;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
@@ -46,13 +45,13 @@ public class ServerFormLoginAuthenticationConverterTests {
private ServerFormLoginAuthenticationConverter converter = new ServerFormLoginAuthenticationConverter();
@BeforeEach
public void setup() {
public void setupMocks() {
given(this.exchange.getFormData()).willReturn(Mono.just(this.data));
}
@Test
public void applyWhenUsernameAndPasswordThenCreatesTokenSuccess() {
setupMocks();
String username = "username";
String password = "password";
this.data.add("username", username);
@@ -65,6 +64,7 @@ public class ServerFormLoginAuthenticationConverterTests {
@Test
public void applyWhenCustomParametersAndUsernameAndPasswordThenCreatesTokenSuccess() {
setupMocks();
String usernameParameter = "j_username";
String passwordParameter = "j_password";
String username = "username";
@@ -81,6 +81,7 @@ public class ServerFormLoginAuthenticationConverterTests {
@Test
public void applyWhenNoDataThenCreatesTokenSuccess() {
setupMocks();
Authentication authentication = this.converter.convert(this.exchange).block();
assertThat(authentication.getName()).isNullOrEmpty();
assertThat(authentication.getCredentials()).isNull();

View File

@@ -53,6 +53,9 @@ public class ServerX509AuthenticationConverterTests {
public void setUp() throws Exception {
this.request = MockServerHttpRequest.get("/");
this.certificate = X509TestUtils.buildTestCertificate();
}
private void givenExtractPrincipalWillReturn() {
given(this.principalExtractor.extractPrincipal(any())).willReturn("Luke Taylor");
}
@@ -65,6 +68,7 @@ public class ServerX509AuthenticationConverterTests {
@Test
public void shouldReturnAuthenticationForValidCertificate() {
givenExtractPrincipalWillReturn();
this.request.sslInfo(new MockSslInfo(this.certificate));
Authentication authentication = this.converter.convert(MockServerWebExchange.from(this.request.build()))
.block();

View File

@@ -22,7 +22,6 @@ import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
@@ -61,10 +60,12 @@ public class DelegatingServerLogoutHandlerTests {
@Mock
private Authentication authentication;
@BeforeEach
public void setup() {
private void givenDelegate1WillReturn() {
given(this.delegate1.logout(any(WebFilterExchange.class), any(Authentication.class)))
.willReturn(this.delegate1Result.mono());
}
private void givenDelegate2WillReturn() {
given(this.delegate2.logout(any(WebFilterExchange.class), any(Authentication.class)))
.willReturn(this.delegate2Result.mono());
}
@@ -92,6 +93,7 @@ public class DelegatingServerLogoutHandlerTests {
@Test
public void logoutWhenSingleThenExecuted() {
givenDelegate1WillReturn();
DelegatingServerLogoutHandler handler = new DelegatingServerLogoutHandler(this.delegate1);
handler.logout(this.exchange, this.authentication).block();
this.delegate1Result.assertWasSubscribed();
@@ -99,6 +101,8 @@ public class DelegatingServerLogoutHandlerTests {
@Test
public void logoutWhenMultipleThenExecuted() {
givenDelegate1WillReturn();
givenDelegate2WillReturn();
DelegatingServerLogoutHandler handler = new DelegatingServerLogoutHandler(this.delegate1, this.delegate2);
handler.logout(this.exchange, this.authentication).block();
this.delegate1Result.assertWasSubscribed();

View File

@@ -74,9 +74,6 @@ public class ExceptionTranslationWebFilterTests {
@BeforeEach
public void setup() {
given(this.exchange.getResponse()).willReturn(new MockServerHttpResponse());
given(this.deniedHandler.handle(any(), any())).willReturn(this.deniedPublisher.mono());
given(this.entryPoint.commence(any(), any())).willReturn(this.entryPointPublisher.mono());
this.filter.setAuthenticationEntryPoint(this.entryPoint);
this.filter.setAccessDeniedHandler(this.deniedHandler);
}
@@ -100,6 +97,7 @@ public class ExceptionTranslationWebFilterTests {
@Test
public void filterWhenAccessDeniedExceptionAndNotAuthenticatedThenHandled() {
given(this.entryPoint.commence(any(), any())).willReturn(this.entryPointPublisher.mono());
given(this.exchange.getPrincipal()).willReturn(Mono.empty());
given(this.chain.filter(this.exchange)).willReturn(Mono.error(new AccessDeniedException("Not Authorized")));
StepVerifier.create(this.filter.filter(this.exchange, this.chain)).verifyComplete();
@@ -109,6 +107,7 @@ public class ExceptionTranslationWebFilterTests {
@Test
public void filterWhenDefaultsAndAccessDeniedExceptionAndAuthenticatedThenForbidden() {
given(this.exchange.getResponse()).willReturn(new MockServerHttpResponse());
this.filter = new ExceptionTranslationWebFilter();
given(this.exchange.getPrincipal()).willReturn(Mono.just(this.principal));
given(this.chain.filter(this.exchange)).willReturn(Mono.error(new AccessDeniedException("Not Authorized")));
@@ -118,6 +117,7 @@ public class ExceptionTranslationWebFilterTests {
@Test
public void filterWhenDefaultsAndAccessDeniedExceptionAndNotAuthenticatedThenUnauthorized() {
given(this.exchange.getResponse()).willReturn(new MockServerHttpResponse());
this.filter = new ExceptionTranslationWebFilter();
given(this.exchange.getPrincipal()).willReturn(Mono.empty());
given(this.chain.filter(this.exchange)).willReturn(Mono.error(new AccessDeniedException("Not Authorized")));
@@ -127,6 +127,8 @@ public class ExceptionTranslationWebFilterTests {
@Test
public void filterWhenAccessDeniedExceptionAndAuthenticatedThenHandled() {
given(this.deniedHandler.handle(any(), any())).willReturn(this.deniedPublisher.mono());
given(this.entryPoint.commence(any(), any())).willReturn(this.entryPointPublisher.mono());
given(this.exchange.getPrincipal()).willReturn(Mono.just(this.principal));
given(this.chain.filter(this.exchange)).willReturn(Mono.error(new AccessDeniedException("Not Authorized")));
StepVerifier.create(this.filter.filter(this.exchange, this.chain)).expectComplete().verify();
@@ -136,6 +138,7 @@ public class ExceptionTranslationWebFilterTests {
@Test
public void filterWhenAccessDeniedExceptionAndAnonymousAuthenticatedThenHandled() {
given(this.entryPoint.commence(any(), any())).willReturn(this.entryPointPublisher.mono());
given(this.exchange.getPrincipal()).willReturn(Mono.just(this.anonymousPrincipal));
given(this.chain.filter(this.exchange)).willReturn(Mono.error(new AccessDeniedException("Not Authorized")));
StepVerifier.create(this.filter.filter(this.exchange, this.chain)).expectComplete().verify();

View File

@@ -67,7 +67,6 @@ public class ReactorContextWebFilterTests {
public void setup() {
this.filter = new ReactorContextWebFilter(this.repository);
this.handler = WebTestHandler.bindToWebFilters(this.filter);
given(this.repository.load(any())).willReturn(this.securityContext.mono());
}
@Test
@@ -77,12 +76,14 @@ public class ReactorContextWebFilterTests {
@Test
public void filterWhenNoPrincipalAccessThenNoInteractions() {
given(this.repository.load(any())).willReturn(this.securityContext.mono());
this.handler.exchange(this.exchange);
this.securityContext.assertWasNotSubscribed();
}
@Test
public void filterWhenGetPrincipalMonoThenNoInteractions() {
given(this.repository.load(any())).willReturn(this.securityContext.mono());
this.handler = WebTestHandler.bindToWebFilters(this.filter, (e, c) -> {
ReactiveSecurityContextHolder.getContext();
return c.filter(e);
@@ -105,6 +106,7 @@ public class ReactorContextWebFilterTests {
@Test
// gh-4962
public void filterWhenMainContextThenDoesNotOverride() {
given(this.repository.load(any())).willReturn(this.securityContext.mono());
String contextKey = "main";
WebFilter mainContextWebFilter = (e, c) -> c.filter(e).subscriberContext(Context.of(contextKey, true));
WebFilterChain chain = new DefaultWebFilterChain((e) -> Mono.empty(), mainContextWebFilter, this.filter);

View File

@@ -57,7 +57,6 @@ public class CsrfServerLogoutHandlerTests {
this.exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").build());
this.filterExchange = new WebFilterExchange(this.exchange, this.filterChain);
this.handler = new CsrfServerLogoutHandler(this.csrfTokenRepository);
given(this.csrfTokenRepository.saveToken(this.exchange, null)).willReturn(Mono.empty());
}
@Test
@@ -68,6 +67,7 @@ public class CsrfServerLogoutHandlerTests {
@Test
public void logoutRemovesCsrfToken() {
given(this.csrfTokenRepository.saveToken(this.exchange, null)).willReturn(Mono.empty());
this.handler.logout(this.filterExchange, new TestingAuthenticationToken("user", "password", "ROLE_USER"))
.block();
verify(this.csrfTokenRepository).saveToken(this.exchange, null);

View File

@@ -55,11 +55,11 @@ public class HttpsRedirectWebFilterTests {
@BeforeEach
public void configureFilter() {
this.filter = new HttpsRedirectWebFilter();
given(this.chain.filter(any(ServerWebExchange.class))).willReturn(Mono.empty());
}
@Test
public void filterWhenExchangeIsInsecureThenRedirects() {
given(this.chain.filter(any(ServerWebExchange.class))).willReturn(Mono.empty());
ServerWebExchange exchange = get("http://localhost");
this.filter.filter(exchange, this.chain).block();
assertThat(statusCode(exchange)).isEqualTo(302);
@@ -68,6 +68,7 @@ public class HttpsRedirectWebFilterTests {
@Test
public void filterWhenExchangeIsSecureThenNoRedirect() {
given(this.chain.filter(any(ServerWebExchange.class))).willReturn(Mono.empty());
ServerWebExchange exchange = get("https://localhost");
this.filter.filter(exchange, this.chain).block();
assertThat(exchange.getResponse().getStatusCode()).isNull();
@@ -75,6 +76,7 @@ public class HttpsRedirectWebFilterTests {
@Test
public void filterWhenExchangeMismatchesThenNoRedirect() {
given(this.chain.filter(any(ServerWebExchange.class))).willReturn(Mono.empty());
ServerWebExchangeMatcher matcher = mock(ServerWebExchangeMatcher.class);
given(matcher.matches(any(ServerWebExchange.class)))
.willReturn(ServerWebExchangeMatcher.MatchResult.notMatch());
@@ -86,6 +88,7 @@ public class HttpsRedirectWebFilterTests {
@Test
public void filterWhenExchangeMatchesAndRequestIsInsecureThenRedirects() {
given(this.chain.filter(any(ServerWebExchange.class))).willReturn(Mono.empty());
ServerWebExchangeMatcher matcher = mock(ServerWebExchangeMatcher.class);
given(matcher.matches(any(ServerWebExchange.class))).willReturn(ServerWebExchangeMatcher.MatchResult.match());
this.filter.setRequiresHttpsRedirectMatcher(matcher);
@@ -98,6 +101,7 @@ public class HttpsRedirectWebFilterTests {
@Test
public void filterWhenRequestIsInsecureThenPortMapperRemapsPort() {
given(this.chain.filter(any(ServerWebExchange.class))).willReturn(Mono.empty());
PortMapper portMapper = mock(PortMapper.class);
given(portMapper.lookupHttpsPort(314)).willReturn(159);
this.filter.setPortMapper(portMapper);
@@ -110,12 +114,14 @@ public class HttpsRedirectWebFilterTests {
@Test
public void filterWhenRequestIsInsecureAndNoPortMappingThenThrowsIllegalState() {
given(this.chain.filter(any(ServerWebExchange.class))).willReturn(Mono.empty());
ServerWebExchange exchange = get("http://localhost:1234");
assertThatIllegalStateException().isThrownBy(() -> this.filter.filter(exchange, this.chain).block());
}
@Test
public void filterWhenInsecureRequestHasAPathThenRedirects() {
given(this.chain.filter(any(ServerWebExchange.class))).willReturn(Mono.empty());
ServerWebExchange exchange = get("http://localhost:8080/path/page.html?query=string");
this.filter.filter(exchange, this.chain).block();
assertThat(statusCode(exchange)).isEqualTo(302);

View File

@@ -59,18 +59,26 @@ public class OnCommittedResponseWrapperTests {
OnCommittedResponseWrapperTests.this.committed = true;
}
};
}
private void givenGetWriterThenReturn() throws IOException {
given(this.delegate.getWriter()).willReturn(this.writer);
}
private void givenGetOutputStreamThenReturn() throws IOException {
given(this.delegate.getOutputStream()).willReturn(this.out);
}
@Test
public void printWriterHashCode() throws Exception {
givenGetWriterThenReturn();
int expected = this.writer.hashCode();
assertThat(this.response.getWriter().hashCode()).isEqualTo(expected);
}
@Test
public void printWriterCheckError() throws Exception {
givenGetWriterThenReturn();
boolean expected = true;
given(this.writer.checkError()).willReturn(expected);
assertThat(this.response.getWriter().checkError()).isEqualTo(expected);
@@ -78,6 +86,7 @@ public class OnCommittedResponseWrapperTests {
@Test
public void printWriterWriteInt() throws Exception {
givenGetWriterThenReturn();
int expected = 1;
this.response.getWriter().write(expected);
verify(this.writer).write(expected);
@@ -85,6 +94,7 @@ public class OnCommittedResponseWrapperTests {
@Test
public void printWriterWriteCharIntInt() throws Exception {
givenGetWriterThenReturn();
char[] buff = new char[0];
int off = 2;
int len = 3;
@@ -94,6 +104,7 @@ public class OnCommittedResponseWrapperTests {
@Test
public void printWriterWriteChar() throws Exception {
givenGetWriterThenReturn();
char[] buff = new char[0];
this.response.getWriter().write(buff);
verify(this.writer).write(buff);
@@ -101,6 +112,7 @@ public class OnCommittedResponseWrapperTests {
@Test
public void printWriterWriteStringIntInt() throws Exception {
givenGetWriterThenReturn();
String s = "";
int off = 2;
int len = 3;
@@ -110,6 +122,7 @@ public class OnCommittedResponseWrapperTests {
@Test
public void printWriterWriteString() throws Exception {
givenGetWriterThenReturn();
String s = "";
this.response.getWriter().write(s);
verify(this.writer).write(s);
@@ -117,6 +130,7 @@ public class OnCommittedResponseWrapperTests {
@Test
public void printWriterPrintBoolean() throws Exception {
givenGetWriterThenReturn();
boolean b = true;
this.response.getWriter().print(b);
verify(this.writer).print(b);
@@ -124,6 +138,7 @@ public class OnCommittedResponseWrapperTests {
@Test
public void printWriterPrintChar() throws Exception {
givenGetWriterThenReturn();
char c = 1;
this.response.getWriter().print(c);
verify(this.writer).print(c);
@@ -131,6 +146,7 @@ public class OnCommittedResponseWrapperTests {
@Test
public void printWriterPrintInt() throws Exception {
givenGetWriterThenReturn();
int i = 1;
this.response.getWriter().print(i);
verify(this.writer).print(i);
@@ -138,6 +154,7 @@ public class OnCommittedResponseWrapperTests {
@Test
public void printWriterPrintLong() throws Exception {
givenGetWriterThenReturn();
long l = 1;
this.response.getWriter().print(l);
verify(this.writer).print(l);
@@ -145,6 +162,7 @@ public class OnCommittedResponseWrapperTests {
@Test
public void printWriterPrintFloat() throws Exception {
givenGetWriterThenReturn();
float f = 1;
this.response.getWriter().print(f);
verify(this.writer).print(f);
@@ -152,6 +170,7 @@ public class OnCommittedResponseWrapperTests {
@Test
public void printWriterPrintDouble() throws Exception {
givenGetWriterThenReturn();
double x = 1;
this.response.getWriter().print(x);
verify(this.writer).print(x);
@@ -159,6 +178,7 @@ public class OnCommittedResponseWrapperTests {
@Test
public void printWriterPrintCharArray() throws Exception {
givenGetWriterThenReturn();
char[] x = new char[0];
this.response.getWriter().print(x);
verify(this.writer).print(x);
@@ -166,6 +186,7 @@ public class OnCommittedResponseWrapperTests {
@Test
public void printWriterPrintString() throws Exception {
givenGetWriterThenReturn();
String x = "1";
this.response.getWriter().print(x);
verify(this.writer).print(x);
@@ -173,6 +194,7 @@ public class OnCommittedResponseWrapperTests {
@Test
public void printWriterPrintObject() throws Exception {
givenGetWriterThenReturn();
Object x = "1";
this.response.getWriter().print(x);
verify(this.writer).print(x);
@@ -180,12 +202,14 @@ public class OnCommittedResponseWrapperTests {
@Test
public void printWriterPrintln() throws Exception {
givenGetWriterThenReturn();
this.response.getWriter().println();
verify(this.writer).println();
}
@Test
public void printWriterPrintlnBoolean() throws Exception {
givenGetWriterThenReturn();
boolean b = true;
this.response.getWriter().println(b);
verify(this.writer).println(b);
@@ -193,6 +217,7 @@ public class OnCommittedResponseWrapperTests {
@Test
public void printWriterPrintlnChar() throws Exception {
givenGetWriterThenReturn();
char c = 1;
this.response.getWriter().println(c);
verify(this.writer).println(c);
@@ -200,6 +225,7 @@ public class OnCommittedResponseWrapperTests {
@Test
public void printWriterPrintlnInt() throws Exception {
givenGetWriterThenReturn();
int i = 1;
this.response.getWriter().println(i);
verify(this.writer).println(i);
@@ -207,6 +233,7 @@ public class OnCommittedResponseWrapperTests {
@Test
public void printWriterPrintlnLong() throws Exception {
givenGetWriterThenReturn();
long l = 1;
this.response.getWriter().println(l);
verify(this.writer).println(l);
@@ -214,6 +241,7 @@ public class OnCommittedResponseWrapperTests {
@Test
public void printWriterPrintlnFloat() throws Exception {
givenGetWriterThenReturn();
float f = 1;
this.response.getWriter().println(f);
verify(this.writer).println(f);
@@ -221,6 +249,7 @@ public class OnCommittedResponseWrapperTests {
@Test
public void printWriterPrintlnDouble() throws Exception {
givenGetWriterThenReturn();
double x = 1;
this.response.getWriter().println(x);
verify(this.writer).println(x);
@@ -228,6 +257,7 @@ public class OnCommittedResponseWrapperTests {
@Test
public void printWriterPrintlnCharArray() throws Exception {
givenGetWriterThenReturn();
char[] x = new char[0];
this.response.getWriter().println(x);
verify(this.writer).println(x);
@@ -235,6 +265,7 @@ public class OnCommittedResponseWrapperTests {
@Test
public void printWriterPrintlnString() throws Exception {
givenGetWriterThenReturn();
String x = "1";
this.response.getWriter().println(x);
verify(this.writer).println(x);
@@ -242,6 +273,7 @@ public class OnCommittedResponseWrapperTests {
@Test
public void printWriterPrintlnObject() throws Exception {
givenGetWriterThenReturn();
Object x = "1";
this.response.getWriter().println(x);
verify(this.writer).println(x);
@@ -249,6 +281,7 @@ public class OnCommittedResponseWrapperTests {
@Test
public void printWriterPrintfStringObjectVargs() throws Exception {
givenGetWriterThenReturn();
String format = "format";
Object[] args = new Object[] { "1" };
this.response.getWriter().printf(format, args);
@@ -257,6 +290,7 @@ public class OnCommittedResponseWrapperTests {
@Test
public void printWriterPrintfLocaleStringObjectVargs() throws Exception {
givenGetWriterThenReturn();
Locale l = Locale.US;
String format = "format";
Object[] args = new Object[] { "1" };
@@ -266,6 +300,7 @@ public class OnCommittedResponseWrapperTests {
@Test
public void printWriterFormatStringObjectVargs() throws Exception {
givenGetWriterThenReturn();
String format = "format";
Object[] args = new Object[] { "1" };
this.response.getWriter().format(format, args);
@@ -274,6 +309,7 @@ public class OnCommittedResponseWrapperTests {
@Test
public void printWriterFormatLocaleStringObjectVargs() throws Exception {
givenGetWriterThenReturn();
Locale l = Locale.US;
String format = "format";
Object[] args = new Object[] { "1" };
@@ -283,6 +319,7 @@ public class OnCommittedResponseWrapperTests {
@Test
public void printWriterAppendCharSequence() throws Exception {
givenGetWriterThenReturn();
String x = "a";
this.response.getWriter().append(x);
verify(this.writer).append(x);
@@ -290,6 +327,7 @@ public class OnCommittedResponseWrapperTests {
@Test
public void printWriterAppendCharSequenceIntInt() throws Exception {
givenGetWriterThenReturn();
String x = "abcdef";
int start = 1;
int end = 3;
@@ -299,6 +337,7 @@ public class OnCommittedResponseWrapperTests {
@Test
public void printWriterAppendChar() throws Exception {
givenGetWriterThenReturn();
char x = 1;
this.response.getWriter().append(x);
verify(this.writer).append(x);
@@ -307,12 +346,14 @@ public class OnCommittedResponseWrapperTests {
// servletoutputstream
@Test
public void outputStreamHashCode() throws Exception {
givenGetOutputStreamThenReturn();
int expected = this.out.hashCode();
assertThat(this.response.getOutputStream().hashCode()).isEqualTo(expected);
}
@Test
public void outputStreamWriteInt() throws Exception {
givenGetOutputStreamThenReturn();
int expected = 1;
this.response.getOutputStream().write(expected);
verify(this.out).write(expected);
@@ -320,6 +361,7 @@ public class OnCommittedResponseWrapperTests {
@Test
public void outputStreamWriteByte() throws Exception {
givenGetOutputStreamThenReturn();
byte[] expected = new byte[0];
this.response.getOutputStream().write(expected);
verify(this.out).write(expected);
@@ -327,6 +369,7 @@ public class OnCommittedResponseWrapperTests {
@Test
public void outputStreamWriteByteIntInt() throws Exception {
givenGetOutputStreamThenReturn();
int start = 1;
int end = 2;
byte[] expected = new byte[0];
@@ -336,6 +379,7 @@ public class OnCommittedResponseWrapperTests {
@Test
public void outputStreamPrintBoolean() throws Exception {
givenGetOutputStreamThenReturn();
boolean b = true;
this.response.getOutputStream().print(b);
verify(this.out).print(b);
@@ -343,6 +387,7 @@ public class OnCommittedResponseWrapperTests {
@Test
public void outputStreamPrintChar() throws Exception {
givenGetOutputStreamThenReturn();
char c = 1;
this.response.getOutputStream().print(c);
verify(this.out).print(c);
@@ -350,6 +395,7 @@ public class OnCommittedResponseWrapperTests {
@Test
public void outputStreamPrintInt() throws Exception {
givenGetOutputStreamThenReturn();
int i = 1;
this.response.getOutputStream().print(i);
verify(this.out).print(i);
@@ -357,6 +403,7 @@ public class OnCommittedResponseWrapperTests {
@Test
public void outputStreamPrintLong() throws Exception {
givenGetOutputStreamThenReturn();
long l = 1;
this.response.getOutputStream().print(l);
verify(this.out).print(l);
@@ -364,6 +411,7 @@ public class OnCommittedResponseWrapperTests {
@Test
public void outputStreamPrintFloat() throws Exception {
givenGetOutputStreamThenReturn();
float f = 1;
this.response.getOutputStream().print(f);
verify(this.out).print(f);
@@ -371,6 +419,7 @@ public class OnCommittedResponseWrapperTests {
@Test
public void outputStreamPrintDouble() throws Exception {
givenGetOutputStreamThenReturn();
double x = 1;
this.response.getOutputStream().print(x);
verify(this.out).print(x);
@@ -378,6 +427,7 @@ public class OnCommittedResponseWrapperTests {
@Test
public void outputStreamPrintString() throws Exception {
givenGetOutputStreamThenReturn();
String x = "1";
this.response.getOutputStream().print(x);
verify(this.out).print(x);
@@ -385,12 +435,14 @@ public class OnCommittedResponseWrapperTests {
@Test
public void outputStreamPrintln() throws Exception {
givenGetOutputStreamThenReturn();
this.response.getOutputStream().println();
verify(this.out).println();
}
@Test
public void outputStreamPrintlnBoolean() throws Exception {
givenGetOutputStreamThenReturn();
boolean b = true;
this.response.getOutputStream().println(b);
verify(this.out).println(b);
@@ -398,6 +450,7 @@ public class OnCommittedResponseWrapperTests {
@Test
public void outputStreamPrintlnChar() throws Exception {
givenGetOutputStreamThenReturn();
char c = 1;
this.response.getOutputStream().println(c);
verify(this.out).println(c);
@@ -405,6 +458,7 @@ public class OnCommittedResponseWrapperTests {
@Test
public void outputStreamPrintlnInt() throws Exception {
givenGetOutputStreamThenReturn();
int i = 1;
this.response.getOutputStream().println(i);
verify(this.out).println(i);
@@ -412,6 +466,7 @@ public class OnCommittedResponseWrapperTests {
@Test
public void outputStreamPrintlnLong() throws Exception {
givenGetOutputStreamThenReturn();
long l = 1;
this.response.getOutputStream().println(l);
verify(this.out).println(l);
@@ -419,6 +474,7 @@ public class OnCommittedResponseWrapperTests {
@Test
public void outputStreamPrintlnFloat() throws Exception {
givenGetOutputStreamThenReturn();
float f = 1;
this.response.getOutputStream().println(f);
verify(this.out).println(f);
@@ -426,6 +482,7 @@ public class OnCommittedResponseWrapperTests {
@Test
public void outputStreamPrintlnDouble() throws Exception {
givenGetOutputStreamThenReturn();
double x = 1;
this.response.getOutputStream().println(x);
verify(this.out).println(x);
@@ -433,6 +490,7 @@ public class OnCommittedResponseWrapperTests {
@Test
public void outputStreamPrintlnString() throws Exception {
givenGetOutputStreamThenReturn();
String x = "1";
this.response.getOutputStream().println(x);
verify(this.out).println(x);
@@ -443,6 +501,7 @@ public class OnCommittedResponseWrapperTests {
// gh-3823
@Test
public void contentLengthPrintWriterWriteNullCommits() throws Exception {
givenGetWriterThenReturn();
String expected = null;
this.response.setContentLength(String.valueOf(expected).length() + 1);
this.response.getWriter().write(expected);
@@ -453,6 +512,7 @@ public class OnCommittedResponseWrapperTests {
@Test
public void contentLengthPrintWriterWriteIntCommits() throws Exception {
givenGetWriterThenReturn();
int expected = 1;
this.response.setContentLength(String.valueOf(expected).length());
this.response.getWriter().write(expected);
@@ -461,6 +521,7 @@ public class OnCommittedResponseWrapperTests {
@Test
public void contentLengthPrintWriterWriteIntMultiDigitCommits() throws Exception {
givenGetWriterThenReturn();
int expected = 10000;
this.response.setContentLength(String.valueOf(expected).length());
this.response.getWriter().write(expected);
@@ -469,6 +530,7 @@ public class OnCommittedResponseWrapperTests {
@Test
public void contentLengthPlus1PrintWriterWriteIntMultiDigitCommits() throws Exception {
givenGetWriterThenReturn();
int expected = 10000;
this.response.setContentLength(String.valueOf(expected).length() + 1);
this.response.getWriter().write(expected);
@@ -479,6 +541,7 @@ public class OnCommittedResponseWrapperTests {
@Test
public void contentLengthPrintWriterWriteCharIntIntCommits() throws Exception {
givenGetWriterThenReturn();
char[] buff = new char[0];
int off = 2;
int len = 3;
@@ -489,6 +552,7 @@ public class OnCommittedResponseWrapperTests {
@Test
public void contentLengthPrintWriterWriteCharCommits() throws Exception {
givenGetWriterThenReturn();
char[] buff = new char[4];
this.response.setContentLength(buff.length);
this.response.getWriter().write(buff);
@@ -497,6 +561,7 @@ public class OnCommittedResponseWrapperTests {
@Test
public void contentLengthPrintWriterWriteStringIntIntCommits() throws Exception {
givenGetWriterThenReturn();
String s = "";
int off = 2;
int len = 3;
@@ -507,6 +572,7 @@ public class OnCommittedResponseWrapperTests {
@Test
public void contentLengthPrintWriterWriteStringCommits() throws IOException {
givenGetWriterThenReturn();
String body = "something";
this.response.setContentLength(body.length());
this.response.getWriter().write(body);
@@ -515,6 +581,7 @@ public class OnCommittedResponseWrapperTests {
@Test
public void printWriterWriteStringContentLengthCommits() throws IOException {
givenGetWriterThenReturn();
String body = "something";
this.response.getWriter().write(body);
this.response.setContentLength(body.length());
@@ -523,6 +590,7 @@ public class OnCommittedResponseWrapperTests {
@Test
public void printWriterWriteStringDoesNotCommit() throws IOException {
givenGetWriterThenReturn();
String body = "something";
this.response.getWriter().write(body);
assertThat(this.committed).isFalse();
@@ -530,6 +598,7 @@ public class OnCommittedResponseWrapperTests {
@Test
public void contentLengthPrintWriterPrintBooleanCommits() throws Exception {
givenGetWriterThenReturn();
boolean b = true;
this.response.setContentLength(1);
this.response.getWriter().print(b);
@@ -538,6 +607,7 @@ public class OnCommittedResponseWrapperTests {
@Test
public void contentLengthPrintWriterPrintCharCommits() throws Exception {
givenGetWriterThenReturn();
char c = 1;
this.response.setContentLength(1);
this.response.getWriter().print(c);
@@ -546,6 +616,7 @@ public class OnCommittedResponseWrapperTests {
@Test
public void contentLengthPrintWriterPrintIntCommits() throws Exception {
givenGetWriterThenReturn();
int i = 1234;
this.response.setContentLength(String.valueOf(i).length());
this.response.getWriter().print(i);
@@ -554,6 +625,7 @@ public class OnCommittedResponseWrapperTests {
@Test
public void contentLengthPrintWriterPrintLongCommits() throws Exception {
givenGetWriterThenReturn();
long l = 12345;
this.response.setContentLength(String.valueOf(l).length());
this.response.getWriter().print(l);
@@ -562,6 +634,7 @@ public class OnCommittedResponseWrapperTests {
@Test
public void contentLengthPrintWriterPrintFloatCommits() throws Exception {
givenGetWriterThenReturn();
float f = 12345;
this.response.setContentLength(String.valueOf(f).length());
this.response.getWriter().print(f);
@@ -570,6 +643,7 @@ public class OnCommittedResponseWrapperTests {
@Test
public void contentLengthPrintWriterPrintDoubleCommits() throws Exception {
givenGetWriterThenReturn();
double x = 1.2345;
this.response.setContentLength(String.valueOf(x).length());
this.response.getWriter().print(x);
@@ -578,6 +652,7 @@ public class OnCommittedResponseWrapperTests {
@Test
public void contentLengthPrintWriterPrintCharArrayCommits() throws Exception {
givenGetWriterThenReturn();
char[] x = new char[10];
this.response.setContentLength(x.length);
this.response.getWriter().print(x);
@@ -586,6 +661,7 @@ public class OnCommittedResponseWrapperTests {
@Test
public void contentLengthPrintWriterPrintStringCommits() throws Exception {
givenGetWriterThenReturn();
String x = "12345";
this.response.setContentLength(x.length());
this.response.getWriter().print(x);
@@ -594,6 +670,7 @@ public class OnCommittedResponseWrapperTests {
@Test
public void contentLengthPrintWriterPrintObjectCommits() throws Exception {
givenGetWriterThenReturn();
Object x = "12345";
this.response.setContentLength(String.valueOf(x).length());
this.response.getWriter().print(x);
@@ -602,6 +679,7 @@ public class OnCommittedResponseWrapperTests {
@Test
public void contentLengthPrintWriterPrintlnCommits() throws Exception {
givenGetWriterThenReturn();
this.response.setContentLength(NL.length());
this.response.getWriter().println();
assertThat(this.committed).isTrue();
@@ -609,6 +687,7 @@ public class OnCommittedResponseWrapperTests {
@Test
public void contentLengthPrintWriterPrintlnBooleanCommits() throws Exception {
givenGetWriterThenReturn();
boolean b = true;
this.response.setContentLength(1);
this.response.getWriter().println(b);
@@ -617,6 +696,7 @@ public class OnCommittedResponseWrapperTests {
@Test
public void contentLengthPrintWriterPrintlnCharCommits() throws Exception {
givenGetWriterThenReturn();
char c = 1;
this.response.setContentLength(1);
this.response.getWriter().println(c);
@@ -625,6 +705,7 @@ public class OnCommittedResponseWrapperTests {
@Test
public void contentLengthPrintWriterPrintlnIntCommits() throws Exception {
givenGetWriterThenReturn();
int i = 12345;
this.response.setContentLength(String.valueOf(i).length());
this.response.getWriter().println(i);
@@ -633,6 +714,7 @@ public class OnCommittedResponseWrapperTests {
@Test
public void contentLengthPrintWriterPrintlnLongCommits() throws Exception {
givenGetWriterThenReturn();
long l = 12345678;
this.response.setContentLength(String.valueOf(l).length());
this.response.getWriter().println(l);
@@ -641,6 +723,7 @@ public class OnCommittedResponseWrapperTests {
@Test
public void contentLengthPrintWriterPrintlnFloatCommits() throws Exception {
givenGetWriterThenReturn();
float f = 1234;
this.response.setContentLength(String.valueOf(f).length());
this.response.getWriter().println(f);
@@ -649,6 +732,7 @@ public class OnCommittedResponseWrapperTests {
@Test
public void contentLengthPrintWriterPrintlnDoubleCommits() throws Exception {
givenGetWriterThenReturn();
double x = 1;
this.response.setContentLength(String.valueOf(x).length());
this.response.getWriter().println(x);
@@ -657,6 +741,7 @@ public class OnCommittedResponseWrapperTests {
@Test
public void contentLengthPrintWriterPrintlnCharArrayCommits() throws Exception {
givenGetWriterThenReturn();
char[] x = new char[20];
this.response.setContentLength(x.length);
this.response.getWriter().println(x);
@@ -665,6 +750,7 @@ public class OnCommittedResponseWrapperTests {
@Test
public void contentLengthPrintWriterPrintlnStringCommits() throws Exception {
givenGetWriterThenReturn();
String x = "1";
this.response.setContentLength(String.valueOf(x).length());
this.response.getWriter().println(x);
@@ -673,6 +759,7 @@ public class OnCommittedResponseWrapperTests {
@Test
public void contentLengthPrintWriterPrintlnObjectCommits() throws Exception {
givenGetWriterThenReturn();
Object x = "1";
this.response.setContentLength(String.valueOf(x).length());
this.response.getWriter().println(x);
@@ -681,6 +768,7 @@ public class OnCommittedResponseWrapperTests {
@Test
public void contentLengthPrintWriterAppendCharSequenceCommits() throws Exception {
givenGetWriterThenReturn();
String x = "a";
this.response.setContentLength(String.valueOf(x).length());
this.response.getWriter().append(x);
@@ -689,6 +777,7 @@ public class OnCommittedResponseWrapperTests {
@Test
public void contentLengthPrintWriterAppendCharSequenceIntIntCommits() throws Exception {
givenGetWriterThenReturn();
String x = "abcdef";
int start = 1;
int end = 3;
@@ -699,6 +788,7 @@ public class OnCommittedResponseWrapperTests {
@Test
public void contentLengthPrintWriterAppendCharCommits() throws Exception {
givenGetWriterThenReturn();
char x = 1;
this.response.setContentLength(1);
this.response.getWriter().append(x);
@@ -707,6 +797,7 @@ public class OnCommittedResponseWrapperTests {
@Test
public void contentLengthOutputStreamWriteIntCommits() throws Exception {
givenGetOutputStreamThenReturn();
int expected = 1;
this.response.setContentLength(String.valueOf(expected).length());
this.response.getOutputStream().write(expected);
@@ -715,6 +806,7 @@ public class OnCommittedResponseWrapperTests {
@Test
public void contentLengthOutputStreamWriteIntMultiDigitCommits() throws Exception {
givenGetOutputStreamThenReturn();
int expected = 10000;
this.response.setContentLength(String.valueOf(expected).length());
this.response.getOutputStream().write(expected);
@@ -723,6 +815,7 @@ public class OnCommittedResponseWrapperTests {
@Test
public void contentLengthPlus1OutputStreamWriteIntMultiDigitCommits() throws Exception {
givenGetOutputStreamThenReturn();
int expected = 10000;
this.response.setContentLength(String.valueOf(expected).length() + 1);
this.response.getOutputStream().write(expected);
@@ -734,6 +827,7 @@ public class OnCommittedResponseWrapperTests {
// gh-171
@Test
public void contentLengthPlus1OutputStreamWriteByteArrayMultiDigitCommits() throws Exception {
givenGetOutputStreamThenReturn();
String expected = "{\n" + " \"parameterName\" : \"_csrf\",\n"
+ " \"token\" : \"06300b65-c4aa-4c8f-8cda-39ee17f545a0\",\n" + " \"headerName\" : \"X-CSRF-TOKEN\"\n"
+ "}";
@@ -746,6 +840,7 @@ public class OnCommittedResponseWrapperTests {
@Test
public void contentLengthOutputStreamPrintBooleanCommits() throws Exception {
givenGetOutputStreamThenReturn();
boolean b = true;
this.response.setContentLength(1);
this.response.getOutputStream().print(b);
@@ -754,6 +849,7 @@ public class OnCommittedResponseWrapperTests {
@Test
public void contentLengthOutputStreamPrintCharCommits() throws Exception {
givenGetOutputStreamThenReturn();
char c = 1;
this.response.setContentLength(1);
this.response.getOutputStream().print(c);
@@ -762,6 +858,7 @@ public class OnCommittedResponseWrapperTests {
@Test
public void contentLengthOutputStreamPrintIntCommits() throws Exception {
givenGetOutputStreamThenReturn();
int i = 1234;
this.response.setContentLength(String.valueOf(i).length());
this.response.getOutputStream().print(i);
@@ -770,6 +867,7 @@ public class OnCommittedResponseWrapperTests {
@Test
public void contentLengthOutputStreamPrintLongCommits() throws Exception {
givenGetOutputStreamThenReturn();
long l = 12345;
this.response.setContentLength(String.valueOf(l).length());
this.response.getOutputStream().print(l);
@@ -778,6 +876,7 @@ public class OnCommittedResponseWrapperTests {
@Test
public void contentLengthOutputStreamPrintFloatCommits() throws Exception {
givenGetOutputStreamThenReturn();
float f = 12345;
this.response.setContentLength(String.valueOf(f).length());
this.response.getOutputStream().print(f);
@@ -786,6 +885,7 @@ public class OnCommittedResponseWrapperTests {
@Test
public void contentLengthOutputStreamPrintDoubleCommits() throws Exception {
givenGetOutputStreamThenReturn();
double x = 1.2345;
this.response.setContentLength(String.valueOf(x).length());
this.response.getOutputStream().print(x);
@@ -794,6 +894,7 @@ public class OnCommittedResponseWrapperTests {
@Test
public void contentLengthOutputStreamPrintStringCommits() throws Exception {
givenGetOutputStreamThenReturn();
String x = "12345";
this.response.setContentLength(x.length());
this.response.getOutputStream().print(x);
@@ -802,6 +903,7 @@ public class OnCommittedResponseWrapperTests {
@Test
public void contentLengthOutputStreamPrintlnCommits() throws Exception {
givenGetOutputStreamThenReturn();
this.response.setContentLength(NL.length());
this.response.getOutputStream().println();
assertThat(this.committed).isTrue();
@@ -809,6 +911,7 @@ public class OnCommittedResponseWrapperTests {
@Test
public void contentLengthOutputStreamPrintlnBooleanCommits() throws Exception {
givenGetOutputStreamThenReturn();
boolean b = true;
this.response.setContentLength(1);
this.response.getOutputStream().println(b);
@@ -817,6 +920,7 @@ public class OnCommittedResponseWrapperTests {
@Test
public void contentLengthOutputStreamPrintlnCharCommits() throws Exception {
givenGetOutputStreamThenReturn();
char c = 1;
this.response.setContentLength(1);
this.response.getOutputStream().println(c);
@@ -825,6 +929,7 @@ public class OnCommittedResponseWrapperTests {
@Test
public void contentLengthOutputStreamPrintlnIntCommits() throws Exception {
givenGetOutputStreamThenReturn();
int i = 12345;
this.response.setContentLength(String.valueOf(i).length());
this.response.getOutputStream().println(i);
@@ -833,6 +938,7 @@ public class OnCommittedResponseWrapperTests {
@Test
public void contentLengthOutputStreamPrintlnLongCommits() throws Exception {
givenGetOutputStreamThenReturn();
long l = 12345678;
this.response.setContentLength(String.valueOf(l).length());
this.response.getOutputStream().println(l);
@@ -841,6 +947,7 @@ public class OnCommittedResponseWrapperTests {
@Test
public void contentLengthOutputStreamPrintlnFloatCommits() throws Exception {
givenGetOutputStreamThenReturn();
float f = 1234;
this.response.setContentLength(String.valueOf(f).length());
this.response.getOutputStream().println(f);
@@ -849,6 +956,7 @@ public class OnCommittedResponseWrapperTests {
@Test
public void contentLengthOutputStreamPrintlnDoubleCommits() throws Exception {
givenGetOutputStreamThenReturn();
double x = 1;
this.response.setContentLength(String.valueOf(x).length());
this.response.getOutputStream().println(x);
@@ -857,6 +965,7 @@ public class OnCommittedResponseWrapperTests {
@Test
public void contentLengthOutputStreamPrintlnStringCommits() throws Exception {
givenGetOutputStreamThenReturn();
String x = "1";
this.response.setContentLength(String.valueOf(x).length());
this.response.getOutputStream().println(x);
@@ -872,6 +981,7 @@ public class OnCommittedResponseWrapperTests {
@Test
public void contentLengthOutputStreamWriteStringCommits() throws IOException {
givenGetOutputStreamThenReturn();
String body = "something";
this.response.setContentLength(body.length());
this.response.getOutputStream().print(body);
@@ -881,6 +991,7 @@ public class OnCommittedResponseWrapperTests {
// gh-7261
@Test
public void contentLengthLongOutputStreamWriteStringCommits() throws IOException {
givenGetOutputStreamThenReturn();
String body = "something";
this.response.setContentLengthLong(body.length());
this.response.getOutputStream().print(body);
@@ -889,6 +1000,7 @@ public class OnCommittedResponseWrapperTests {
@Test
public void addHeaderContentLengthPrintWriterWriteStringCommits() throws Exception {
givenGetWriterThenReturn();
int expected = 1234;
this.response.addHeader("Content-Length", String.valueOf(String.valueOf(expected).length()));
this.response.getWriter().write(expected);
@@ -897,6 +1009,7 @@ public class OnCommittedResponseWrapperTests {
@Test
public void bufferSizePrintWriterWriteCommits() throws Exception {
givenGetWriterThenReturn();
String expected = "1234567890";
given(this.response.getBufferSize()).willReturn(expected.length());
this.response.getWriter().write(expected);
@@ -905,6 +1018,7 @@ public class OnCommittedResponseWrapperTests {
@Test
public void bufferSizeCommitsOnce() throws Exception {
givenGetWriterThenReturn();
String expected = "1234567890";
given(this.response.getBufferSize()).willReturn(expected.length());
this.response.getWriter().write(expected);

View File

@@ -57,12 +57,12 @@ public class TextEscapeUtilsTests {
*/
@Test
public void validSurrogatePairIsAccepted() {
assertThat(TextEscapeUtils.escapeEntities("abc\uD801a")).isEqualTo("abc&#66560;a");
assertThat(TextEscapeUtils.escapeEntities("abc\uD801\uDC00a")).isEqualTo("abc&#66560;a");
}
@Test
public void undefinedSurrogatePairIsIgnored() {
assertThat(TextEscapeUtils.escapeEntities("abc\uD888a")).isEqualTo("abca");
assertThat(TextEscapeUtils.escapeEntities("abc\uD888\uDC00a")).isEqualTo("abca");
}
}