Backport selected refinements from the nullability efforts
Issue: SPR-15656
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2017 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.
|
||||
@@ -33,9 +33,7 @@ import org.springframework.util.Assert;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
|
||||
/**
|
||||
* <p>Mock implementation of the {@link javax.servlet.FilterChain} interface. Used
|
||||
* for testing the web framework; also useful for testing custom
|
||||
* {@link javax.servlet.Filter} implementations.
|
||||
* Mock implementation of the {@link javax.servlet.FilterChain} interface.
|
||||
*
|
||||
* <p>A {@link MockFilterChain} can be configured with one or more filters and a
|
||||
* Servlet to invoke. The first time the chain is called, it invokes all filters
|
||||
@@ -72,7 +70,6 @@ public class MockFilterChain implements FilterChain {
|
||||
|
||||
/**
|
||||
* Create a FilterChain with a Servlet.
|
||||
*
|
||||
* @param servlet the Servlet to invoke
|
||||
* @since 3.2
|
||||
*/
|
||||
@@ -82,7 +79,6 @@ public class MockFilterChain implements FilterChain {
|
||||
|
||||
/**
|
||||
* Create a {@code FilterChain} with Filter's and a Servlet.
|
||||
*
|
||||
* @param servlet the {@link Servlet} to invoke in this {@link FilterChain}
|
||||
* @param filters the {@link Filter}'s to invoke in this {@link FilterChain}
|
||||
* @since 3.2
|
||||
@@ -120,10 +116,7 @@ public class MockFilterChain implements FilterChain {
|
||||
public void doFilter(ServletRequest request, ServletResponse response) throws IOException, ServletException {
|
||||
Assert.notNull(request, "Request must not be null");
|
||||
Assert.notNull(response, "Response must not be null");
|
||||
|
||||
if (this.request != null) {
|
||||
throw new IllegalStateException("This FilterChain has already been called!");
|
||||
}
|
||||
Assert.state(this.request == null, "This FilterChain has already been called!");
|
||||
|
||||
if (this.iterator == null) {
|
||||
this.iterator = this.filters.iterator();
|
||||
|
||||
@@ -40,9 +40,7 @@ import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* Mock implementation of the {@link javax.servlet.jsp.PageContext} interface.
|
||||
*
|
||||
* <p>Used for testing the web framework; only necessary for testing
|
||||
* applications when testing custom JSP tags.
|
||||
* Only necessary for testing applications when testing custom JSP tags.
|
||||
*
|
||||
* <p>Note: Expects initialization via the constructor rather than via the
|
||||
* {@code PageContext.initialize} method. Does not support writing to a
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
* Copyright 2002-2017 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.
|
||||
@@ -55,6 +55,7 @@ class TransactionContext {
|
||||
|
||||
TransactionContext(TestContext testContext, PlatformTransactionManager transactionManager,
|
||||
TransactionDefinition transactionDefinition, boolean defaultRollback) {
|
||||
|
||||
this.testContext = testContext;
|
||||
this.transactionManager = transactionManager;
|
||||
this.transactionDefinition = transactionDefinition;
|
||||
@@ -62,6 +63,7 @@ class TransactionContext {
|
||||
this.flaggedForRollback = defaultRollback;
|
||||
}
|
||||
|
||||
|
||||
TransactionStatus getTransactionStatus() {
|
||||
return this.transactionStatus;
|
||||
}
|
||||
@@ -105,23 +107,22 @@ class TransactionContext {
|
||||
}
|
||||
|
||||
/**
|
||||
* Immediately force a <em>commit</em> or <em>rollback</em> of the transaction
|
||||
* for the configured {@linkplain #getTestContext test context}, according to
|
||||
* the {@linkplain #isFlaggedForRollback rollback flag}.
|
||||
* Immediately force a <em>commit</em> or <em>rollback</em> of the transaction for the
|
||||
* configured test context, according to the {@linkplain #isFlaggedForRollback rollback flag}.
|
||||
*/
|
||||
void endTransaction() {
|
||||
if (logger.isTraceEnabled()) {
|
||||
logger.trace(String.format(
|
||||
"Ending transaction for test context %s; transaction status [%s]; rollback [%s]", this.testContext,
|
||||
this.transactionStatus, flaggedForRollback));
|
||||
"Ending transaction for test context %s; transaction status [%s]; rollback [%s]",
|
||||
this.testContext, this.transactionStatus, this.flaggedForRollback));
|
||||
}
|
||||
if (this.transactionStatus == null) {
|
||||
throw new IllegalStateException(String.format(
|
||||
"Failed to end transaction for test context %s: transaction does not exist.", this.testContext));
|
||||
"Failed to end transaction for test context %s: transaction does not exist.", this.testContext));
|
||||
}
|
||||
|
||||
try {
|
||||
if (flaggedForRollback) {
|
||||
if (this.flaggedForRollback) {
|
||||
this.transactionManager.rollback(this.transactionStatus);
|
||||
}
|
||||
else {
|
||||
@@ -133,8 +134,8 @@ class TransactionContext {
|
||||
}
|
||||
|
||||
if (logger.isInfoEnabled()) {
|
||||
logger.info(String.format("%s transaction for test context %s.", (flaggedForRollback ? "Rolled back"
|
||||
: "Committed"), this.testContext));
|
||||
logger.info(String.format("%s transaction for test context %s.",
|
||||
(this.flaggedForRollback ? "Rolled back" : "Committed"), this.testContext));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
* Copyright 2002-2017 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.
|
||||
@@ -26,18 +26,18 @@ import org.springframework.core.NamedInheritableThreadLocal;
|
||||
*/
|
||||
class TransactionContextHolder {
|
||||
|
||||
private static final ThreadLocal<TransactionContext> currentTransactionContext = new NamedInheritableThreadLocal<TransactionContext>(
|
||||
"Test Transaction Context");
|
||||
private static final ThreadLocal<TransactionContext> currentTransactionContext =
|
||||
new NamedInheritableThreadLocal<TransactionContext>("Test Transaction Context");
|
||||
|
||||
|
||||
static TransactionContext getCurrentTransactionContext() {
|
||||
return currentTransactionContext.get();
|
||||
}
|
||||
|
||||
static void setCurrentTransactionContext(TransactionContext transactionContext) {
|
||||
currentTransactionContext.set(transactionContext);
|
||||
}
|
||||
|
||||
static TransactionContext getCurrentTransactionContext() {
|
||||
return currentTransactionContext.get();
|
||||
}
|
||||
|
||||
static TransactionContext removeCurrentTransactionContext() {
|
||||
synchronized (currentTransactionContext) {
|
||||
TransactionContext transactionContext = currentTransactionContext.get();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
* Copyright 2002-2017 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.
|
||||
@@ -34,7 +34,6 @@ public interface RequestBuilder {
|
||||
|
||||
/**
|
||||
* Build the request.
|
||||
*
|
||||
* @param servletContext the {@link ServletContext} to use to create the request
|
||||
* @return the request
|
||||
*/
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2017 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.
|
||||
@@ -85,8 +85,8 @@ public final class MockMvcWebConnection implements WebConnection {
|
||||
* to {@link javax.servlet.http.HttpServletRequest#getContextPath()}
|
||||
* which states that it can be an empty string and otherwise must start
|
||||
* with a "/" character and not end with a "/" character.
|
||||
* @param mockMvc the {@code MockMvc} instance to use; never {@code null}
|
||||
* @param webClient the {@link WebClient} to use. never {@code null}
|
||||
* @param mockMvc the {@code MockMvc} instance to use (never {@code null})
|
||||
* @param webClient the {@link WebClient} to use (never {@code null})
|
||||
* @param contextPath the contextPath to use
|
||||
*/
|
||||
public MockMvcWebConnection(MockMvc mockMvc, WebClient webClient, String contextPath) {
|
||||
|
||||
Reference in New Issue
Block a user