Use Supplier<String> support in Assert in spring-test
This commit makes use of the new Supplier<String> variants of utility
methods in org.springframework.util.Assert within the spring-test
module.
Issue: SPR-14450
@ -137,12 +138,10 @@ public class SimpleNamingContextBuilder implements InitialContextFactoryBuilder
@@ -137,12 +138,10 @@ public class SimpleNamingContextBuilder implements InitialContextFactoryBuilder
@ -68,9 +69,7 @@ public class MockExpressionEvaluator extends javax.servlet.jsp.el.ExpressionEval
@@ -68,9 +69,7 @@ public class MockExpressionEvaluator extends javax.servlet.jsp.el.ExpressionEval
@ -78,9 +77,7 @@ public class MockExpressionEvaluator extends javax.servlet.jsp.el.ExpressionEval
@@ -78,9 +77,7 @@ public class MockExpressionEvaluator extends javax.servlet.jsp.el.ExpressionEval
@ -328,9 +328,7 @@ public class MockHttpServletRequest implements HttpServletRequest {
@@ -328,9 +328,7 @@ public class MockHttpServletRequest implements HttpServletRequest {
thrownewIllegalStateException("Request is not active anymore");
}
Assert.state(this.active,"Request is not active anymore");
}
@ -807,9 +805,7 @@ public class MockHttpServletRequest implements HttpServletRequest {
@@ -807,9 +805,7 @@ public class MockHttpServletRequest implements HttpServletRequest {
@ -181,17 +181,13 @@ public class MockHttpServletResponse implements HttpServletResponse {
@@ -181,17 +181,13 @@ public class MockHttpServletResponse implements HttpServletResponse {
@Override
publicServletOutputStreamgetOutputStream(){
if(!this.outputStreamAccessAllowed){
thrownewIllegalStateException("OutputStream access not allowed");
}
Assert.state(this.outputStreamAccessAllowed,"OutputStream access not allowed");
@ -275,9 +271,7 @@ public class MockHttpServletResponse implements HttpServletResponse {
@@ -275,9 +271,7 @@ public class MockHttpServletResponse implements HttpServletResponse {
@Override
publicvoidresetBuffer(){
if(isCommitted()){
thrownewIllegalStateException("Cannot reset buffer - response is already committed");
}
Assert.state(!isCommitted(),"Cannot reset buffer - response is already committed");
this.content.reset();
}
@ -456,9 +450,7 @@ public class MockHttpServletResponse implements HttpServletResponse {
@@ -456,9 +450,7 @@ public class MockHttpServletResponse implements HttpServletResponse {
thrownewIllegalStateException("Cannot set error status - response is already committed");
}
Assert.state(!isCommitted(),"Cannot set error status - response is already committed");
this.status=status;
this.errorMessage=errorMessage;
setCommitted(true);
@ -466,18 +458,14 @@ public class MockHttpServletResponse implements HttpServletResponse {
@@ -466,18 +458,14 @@ public class MockHttpServletResponse implements HttpServletResponse {
@Override
publicvoidsendError(intstatus)throwsIOException{
if(isCommitted()){
thrownewIllegalStateException("Cannot set error status - response is already committed");
}
Assert.state(!isCommitted(),"Cannot set error status - response is already committed");
@ -627,10 +615,8 @@ public class MockHttpServletResponse implements HttpServletResponse {
@@ -627,10 +615,8 @@ public class MockHttpServletResponse implements HttpServletResponse {
publicStringgetIncludedUrl(){
intcount=this.includedUrls.size();
if(count>1){
thrownewIllegalStateException(
"More than 1 URL included - check getIncludedUrls instead: "+this.includedUrls);
}
Assert.state(count<=1,
()->"More than 1 URL included - check getIncludedUrls instead: "+this.includedUrls);
@ -59,9 +59,7 @@ public class MockRequestDispatcher implements RequestDispatcher {
@@ -59,9 +59,7 @@ public class MockRequestDispatcher implements RequestDispatcher {
@ -355,9 +355,8 @@ public class MockServletContext implements ServletContext {
@@ -355,9 +355,8 @@ public class MockServletContext implements ServletContext {
@ -201,16 +202,12 @@ public class SqlScriptsTestExecutionListener extends AbstractTestExecutionListen
@@ -201,16 +202,12 @@ public class SqlScriptsTestExecutionListener extends AbstractTestExecutionListen
thrownewIllegalStateException(String.format("Failed to execute SQL scripts for test context %s: "
+"cannot execute SQL scripts using Transaction Mode "
+"[%s] without a PlatformTransactionManager.",testContext,TransactionMode.ISOLATED));
}
Assert.state(!newTxRequired,()->String.format("Failed to execute SQL scripts for test context %s: "+
"cannot execute SQL scripts using Transaction Mode "+
"[%s] without a PlatformTransactionManager.",testContext,TransactionMode.ISOLATED));
if(dataSource==null){
thrownewIllegalStateException(String.format("Failed to execute SQL scripts for test context %s: "
+"supply at least a DataSource or PlatformTransactionManager.",testContext));
}
Assert.state(dataSource!=null,()->String.format("Failed to execute SQL scripts for test context %s: "+
"supply at least a DataSource or PlatformTransactionManager.",testContext));
// Execute scripts directly against the DataSource
populator.execute(dataSource);
@ -228,11 +225,9 @@ public class SqlScriptsTestExecutionListener extends AbstractTestExecutionListen
@@ -228,11 +225,9 @@ public class SqlScriptsTestExecutionListener extends AbstractTestExecutionListen
if(dataSource==null){
dataSource=dataSourceFromTxMgr;
if(dataSource==null){
thrownewIllegalStateException(String.format("Failed to execute SQL scripts for test context %s: "
+"could not obtain DataSource from transaction manager [%s] (named '%s').",testContext,
Assert.state(dataSource!=null,()->String.format("Failed to execute SQL scripts for test context %s: "+
"could not obtain DataSource from transaction manager [%s] (named '%s').",testContext,
@ -100,15 +101,12 @@ public class SpringJUnit4ClassRunner extends BlockJUnit4ClassRunner {
@@ -100,15 +101,12 @@ public class SpringJUnit4ClassRunner extends BlockJUnit4ClassRunner {
thrownewIllegalStateException("SpringJUnit4ClassRunner requires JUnit 4.12 or higher.");
}
Assert.state(withRulesMethod!=null,"SpringJUnit4ClassRunner requires JUnit 4.12 or higher.");
ReflectionUtils.makeAccessible(withRulesMethod);
}
@ -118,14 +116,12 @@ public class SpringJUnit4ClassRunner extends BlockJUnit4ClassRunner {
@@ -118,14 +116,12 @@ public class SpringJUnit4ClassRunner extends BlockJUnit4ClassRunner {
@ -178,11 +178,9 @@ public abstract class AbstractDelegatingSmartContextLoader implements SmartConte
@@ -178,11 +178,9 @@ public abstract class AbstractDelegatingSmartContextLoader implements SmartConte
@ -195,11 +193,9 @@ public abstract class AbstractDelegatingSmartContextLoader implements SmartConte
@@ -195,11 +193,9 @@ public abstract class AbstractDelegatingSmartContextLoader implements SmartConte
@ -237,12 +233,10 @@ public abstract class AbstractDelegatingSmartContextLoader implements SmartConte
@@ -237,12 +233,10 @@ public abstract class AbstractDelegatingSmartContextLoader implements SmartConte
Assert.notNull(mergedConfig,"mergedConfig must not be null");
@ -387,13 +387,11 @@ public abstract class AbstractTestContextBootstrapper implements TestContextBoot
@@ -387,13 +387,11 @@ public abstract class AbstractTestContextBootstrapper implements TestContextBoot
@ -463,9 +461,7 @@ public abstract class AbstractTestContextBootstrapper implements TestContextBoot
@@ -463,9 +461,7 @@ public abstract class AbstractTestContextBootstrapper implements TestContextBoot
@ -161,9 +161,7 @@ public class TransactionalTestExecutionListener extends AbstractTestExecutionLis
@@ -161,9 +161,7 @@ public class TransactionalTestExecutionListener extends AbstractTestExecutionLis
Assert.notNull(testMethod,"The test method of the supplied TestContext must not be null");
@ -183,11 +181,9 @@ public class TransactionalTestExecutionListener extends AbstractTestExecutionLis
@@ -183,11 +181,9 @@ public class TransactionalTestExecutionListener extends AbstractTestExecutionLis
@ -104,12 +104,10 @@ public abstract class AbstractGenericWebContextLoader extends AbstractContextLoa
@@ -104,12 +104,10 @@ public abstract class AbstractGenericWebContextLoader extends AbstractContextLoa
@ -191,11 +192,9 @@ public class ServletTestExecutionListener extends AbstractTestExecutionListener
@@ -191,11 +192,9 @@ public class ServletTestExecutionListener extends AbstractTestExecutionListener
@ -88,9 +88,7 @@ public class DefaultRequestExpectation implements RequestExpectation {
@@ -88,9 +88,7 @@ public class DefaultRequestExpectation implements RequestExpectation {
@ -111,12 +111,8 @@ public final class MockMvcWebConnection implements WebConnection {
@@ -111,12 +111,8 @@ public final class MockMvcWebConnection implements WebConnection {
if(contextPath==null||"".equals(contextPath)){
return;
}
if(!contextPath.startsWith("/")){
thrownewIllegalArgumentException("contextPath '"+contextPath+"' must start with '/'.");
}
if(contextPath.endsWith("/")){
thrownewIllegalArgumentException("contextPath '"+contextPath+"' must not end with '/'.");
}
Assert.isTrue(contextPath.startsWith("/"),()->"contextPath '"+contextPath+"' must start with '/'.");
Assert.isTrue(!contextPath.endsWith("/"),()->"contextPath '"+contextPath+"' must not end with '/'.");