Revisit Assert to avoid single-arg assert methods (with refined messages)

Issue: SPR-15196
This commit is contained in:
Juergen Hoeller
2017-01-30 22:15:53 +01:00
parent 768802fa96
commit 1b2dc3638f
118 changed files with 708 additions and 828 deletions

View File

@@ -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.
@@ -44,14 +44,15 @@ class DefaultCacheInvocationContext<A extends Annotation>
private final CacheInvocationParameter[] allParameters;
public DefaultCacheInvocationContext(JCacheOperation<A> operation,
Object target, Object[] args) {
public DefaultCacheInvocationContext(JCacheOperation<A> operation, Object target, Object[] args) {
this.operation = operation;
this.target = target;
this.args = args;
this.allParameters = operation.getAllParameters(args);
}
@Override
public JCacheOperation<A> getOperation() {
return this.operation;
@@ -94,17 +95,19 @@ class DefaultCacheInvocationContext<A extends Annotation>
@Override
public <T> T unwrap(Class<T> cls) {
throw new IllegalArgumentException("Could not unwrap to '" + cls.getName() + "'");
throw new IllegalArgumentException("Cannot unwrap to " + cls);
}
@Override
public String toString() {
final StringBuilder sb = new StringBuilder("CacheInvocationContext{");
sb.append("operation=").append(operation);
sb.append(", target=").append(target);
sb.append(", args=").append(Arrays.toString(args));
sb.append(", allParameters=").append(Arrays.toString(allParameters));
StringBuilder sb = new StringBuilder("CacheInvocationContext{");
sb.append("operation=").append(this.operation);
sb.append(", target=").append(this.target);
sb.append(", args=").append(Arrays.toString(this.args));
sb.append(", allParameters=").append(Arrays.toString(this.allParameters));
sb.append('}');
return sb.toString();
}
}

View File

@@ -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.
@@ -66,7 +66,7 @@ public class JCacheAspectSupport extends AbstractCacheInvoker implements Initial
public void setCacheOperationSource(JCacheOperationSource cacheOperationSource) {
Assert.notNull(cacheOperationSource);
Assert.notNull(cacheOperationSource, "JCacheOperationSource must not be null");
this.cacheOperationSource = cacheOperationSource;
}
@@ -80,7 +80,7 @@ public class JCacheAspectSupport extends AbstractCacheInvoker implements Initial
public void afterPropertiesSet() {
Assert.state(getCacheOperationSource() != null, "The 'cacheOperationSource' property is required: " +
"If there are no cacheable methods, then don't use a cache aspect.");
Assert.state(getErrorHandler() != null, "The 'errorHandler' is required");
Assert.state(getErrorHandler() != null, "The 'errorHandler' property is required");
this.cacheResultInterceptor = new CacheResultInterceptor(getErrorHandler());
this.cachePutInterceptor = new CachePutInterceptor(getErrorHandler());
@@ -128,23 +128,23 @@ public class JCacheAspectSupport extends AbstractCacheInvoker implements Initial
BasicOperation operation = context.getOperation();
if (operation instanceof CacheResultOperation) {
return cacheResultInterceptor.invoke(
return this.cacheResultInterceptor.invoke(
(CacheOperationInvocationContext<CacheResultOperation>) context, adapter);
}
else if (operation instanceof CachePutOperation) {
return cachePutInterceptor.invoke(
return this.cachePutInterceptor.invoke(
(CacheOperationInvocationContext<CachePutOperation>) context, adapter);
}
else if (operation instanceof CacheRemoveOperation) {
return cacheRemoveEntryInterceptor.invoke(
return this.cacheRemoveEntryInterceptor.invoke(
(CacheOperationInvocationContext<CacheRemoveOperation>) context, adapter);
}
else if (operation instanceof CacheRemoveAllOperation) {
return cacheRemoveAllInterceptor.invoke(
return this.cacheRemoveAllInterceptor.invoke(
(CacheOperationInvocationContext<CacheRemoveAllOperation>) context, adapter);
}
else {
throw new IllegalArgumentException("Could not handle " + operation);
throw new IllegalArgumentException("Cannot handle " + operation);
}
}

View File

@@ -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.
@@ -43,7 +43,6 @@ import org.springframework.core.io.Resource;
import org.springframework.core.io.ResourceLoader;
import org.springframework.core.io.support.PropertiesLoaderUtils;
import org.springframework.scheduling.SchedulingException;
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;
/**
@@ -105,6 +104,7 @@ public class SchedulerFactoryBean extends SchedulerAccessor implements FactoryBe
private static final ThreadLocal<DataSource> configTimeNonTransactionalDataSourceHolder =
new ThreadLocal<>();
/**
* Return the ResourceLoader for the currently configured Quartz Scheduler,
* to be used by ResourceLoaderClassLoadHelper.
@@ -210,7 +210,6 @@ public class SchedulerFactoryBean extends SchedulerAccessor implements FactoryBe
* @see #setQuartzProperties
*/
public void setSchedulerFactoryClass(Class<? extends SchedulerFactory> schedulerFactoryClass) {
Assert.isAssignable(SchedulerFactory.class, schedulerFactoryClass);
this.schedulerFactoryClass = schedulerFactoryClass;
}