Polish assertions

This commit is contained in:
Stephane Nicoll 2022-06-21 07:57:11 +02:00
parent 93b340e563
commit 0f4205adbf
16 changed files with 61 additions and 61 deletions

View File

@ -58,7 +58,7 @@ public class AotFactoriesLoader {
* @param beanFactory the bean factory to use
*/
public AotFactoriesLoader(ListableBeanFactory beanFactory) {
Assert.notNull(beanFactory, "BeanFactory must not be null");
Assert.notNull(beanFactory, "'beanFactory' must not be null");
ClassLoader classLoader = (beanFactory instanceof ConfigurableBeanFactory configurableBeanFactory)
? configurableBeanFactory.getBeanClassLoader() : null;
this.beanFactory = beanFactory;
@ -76,8 +76,8 @@ public class AotFactoriesLoader {
public AotFactoriesLoader(ListableBeanFactory beanFactory,
SpringFactoriesLoader factoriesLoader) {
Assert.notNull(beanFactory, "BeanFactory must not be null");
Assert.notNull(factoriesLoader, "FactoriesLoader must not be null");
Assert.notNull(beanFactory, "'beanFactory' must not be null");
Assert.notNull(factoriesLoader, "'factoriesLoader' must not be null");
this.beanFactory = beanFactory;
this.factoriesLoader = factoriesLoader;
}

View File

@ -80,7 +80,7 @@ public interface AutowiredArguments {
* @return a new {@link AutowiredArguments} instance
*/
static AutowiredArguments of(Object[] arguments) {
Assert.notNull(arguments, "Arguments must not be null");
Assert.notNull(arguments, "'arguments' must not be null");
return () -> arguments;
}

View File

@ -66,8 +66,8 @@ public class AutowiredArgumentsCodeGenerator {
public CodeBlock generateCode(Class<?>[] parameterTypes, int startIndex,
String variableName) {
Assert.notNull(parameterTypes, "ParameterTypes must not be null");
Assert.notNull(variableName, "VariableName must not be null");
Assert.notNull(parameterTypes, "'parameterTypes' must not be null");
Assert.notNull(variableName, "'variableName' must not be null");
boolean ambiguous = isAmbiguous();
CodeBlock.Builder builder = CodeBlock.builder();
for (int i = startIndex; i < parameterTypes.length; i++) {

View File

@ -64,7 +64,7 @@ public final class AutowiredFieldValueResolver extends AutowiredElementResolver
private AutowiredFieldValueResolver(String fieldName, boolean required,
@Nullable String shortcut) {
Assert.hasText(fieldName, "FieldName must not be empty");
Assert.hasText(fieldName, "'fieldName' must not be empty");
this.fieldName = fieldName;
this.required = required;
this.shortcut = shortcut;
@ -110,8 +110,8 @@ public final class AutowiredFieldValueResolver extends AutowiredElementResolver
* @param action the action to execute with the resolved field value
*/
public <T> void resolve(RegisteredBean registeredBean, ThrowingConsumer<T> action) {
Assert.notNull(registeredBean, "RegisteredBean must not be null");
Assert.notNull(action, "Action must not be null");
Assert.notNull(registeredBean, "'registeredBean' must not be null");
Assert.notNull(action, "'action' must not be null");
T resolved = resolve(registeredBean);
if (resolved != null) {
action.accept(resolved);
@ -150,7 +150,7 @@ public final class AutowiredFieldValueResolver extends AutowiredElementResolver
*/
@Nullable
public Object resolveObject(RegisteredBean registeredBean) {
Assert.notNull(registeredBean, "RegisteredBean must not be null");
Assert.notNull(registeredBean, "'registeredBean' must not be null");
return resolveValue(registeredBean, getField(registeredBean));
}
@ -161,8 +161,8 @@ public final class AutowiredFieldValueResolver extends AutowiredElementResolver
* @param instance the bean instance
*/
public void resolveAndSet(RegisteredBean registeredBean, Object instance) {
Assert.notNull(registeredBean, "RegisteredBean must not be null");
Assert.notNull(instance, "Instance must not be null");
Assert.notNull(registeredBean, "'registeredBean' must not be null");
Assert.notNull(instance, "'instance' must not be null");
Field field = getField(registeredBean);
Object resolved = resolveValue(registeredBean, field);
if (resolved != null) {

View File

@ -94,9 +94,9 @@ public final class AutowiredInstantiationArgumentsResolver extends AutowiredElem
public static AutowiredInstantiationArgumentsResolver forConstructor(
Class<?>... parameterTypes) {
Assert.notNull(parameterTypes, "ParameterTypes must not be null");
Assert.notNull(parameterTypes, "'parameterTypes' must not be null");
Assert.noNullElements(parameterTypes,
"ParameterTypes must not contain null elements");
"'parameterTypes' must not contain null elements");
return new AutowiredInstantiationArgumentsResolver(
new ConstructorLookup(parameterTypes), null);
}
@ -112,11 +112,11 @@ public final class AutowiredInstantiationArgumentsResolver extends AutowiredElem
public static AutowiredInstantiationArgumentsResolver forFactoryMethod(
Class<?> declaringClass, String methodName, Class<?>... parameterTypes) {
Assert.notNull(declaringClass, "DeclaringClass must not be null");
Assert.hasText(methodName, "MethodName must not be empty");
Assert.notNull(parameterTypes, "ParameterTypes must not be null");
Assert.notNull(declaringClass, "'declaringClass' must not be null");
Assert.hasText(methodName, "'methodName' must not be empty");
Assert.notNull(parameterTypes, "'parameterTypes' must not be null");
Assert.noNullElements(parameterTypes,
"ParameterTypes must not contain null elements");
"'parameterTypes' must not contain null elements");
return new AutowiredInstantiationArgumentsResolver(
new FactoryMethodLookup(declaringClass, methodName, parameterTypes),
null);
@ -149,8 +149,8 @@ public final class AutowiredInstantiationArgumentsResolver extends AutowiredElem
public <T> T resolve(RegisteredBean registeredBean,
ThrowingFunction<AutowiredArguments, T> generator) {
Assert.notNull(registeredBean, "RegisteredBean must not be null");
Assert.notNull(generator, "Action must not be null");
Assert.notNull(registeredBean, "'registeredBean' must not be null");
Assert.notNull(generator, "'action' must not be null");
AutowiredArguments resolved = resolveArguments(registeredBean,
this.lookup.get(registeredBean));
return generator.apply(resolved);
@ -162,7 +162,7 @@ public final class AutowiredInstantiationArgumentsResolver extends AutowiredElem
* @return the resolved constructor or factory method arguments
*/
public AutowiredArguments resolve(RegisteredBean registeredBean) {
Assert.notNull(registeredBean, "RegisteredBean must not be null");
Assert.notNull(registeredBean, "'registeredBean' must not be null");
return resolveArguments(registeredBean, this.lookup.get(registeredBean));
}
@ -188,8 +188,8 @@ public final class AutowiredInstantiationArgumentsResolver extends AutowiredElem
public <T> T resolveAndInstantiate(RegisteredBean registeredBean,
Class<T> requiredType) {
Assert.notNull(registeredBean, "RegisteredBean must not be null");
Assert.notNull(registeredBean, "RequiredType must not be null");
Assert.notNull(registeredBean, "'registeredBean' must not be null");
Assert.notNull(registeredBean, "'requiredType' must not be null");
Executable executable = this.lookup.get(registeredBean);
AutowiredArguments arguments = resolveArguments(registeredBean, executable);
Object instance = instantiate(registeredBean.getBeanFactory(), executable,

View File

@ -69,7 +69,7 @@ public final class AutowiredMethodArgumentsResolver extends AutowiredElementReso
private AutowiredMethodArgumentsResolver(String methodName, Class<?>[] parameterTypes,
boolean required, @Nullable String[] shortcuts) {
Assert.hasText(methodName, "MethodName must not be empty");
Assert.hasText(methodName, "'methodName' must not be empty");
this.methodName = methodName;
this.parameterTypes = parameterTypes;
this.required = required;
@ -126,8 +126,8 @@ public final class AutowiredMethodArgumentsResolver extends AutowiredElementReso
public void resolve(RegisteredBean registeredBean,
ThrowingConsumer<AutowiredArguments> action) {
Assert.notNull(registeredBean, "RegisteredBean must not be null");
Assert.notNull(action, "Action must not be null");
Assert.notNull(registeredBean, "'registeredBean' must not be null");
Assert.notNull(action, "'action' must not be null");
AutowiredArguments resolved = resolve(registeredBean);
if (resolved != null) {
action.accept(resolved);
@ -141,7 +141,7 @@ public final class AutowiredMethodArgumentsResolver extends AutowiredElementReso
*/
@Nullable
public AutowiredArguments resolve(RegisteredBean registeredBean) {
Assert.notNull(registeredBean, "RegisteredBean must not be null");
Assert.notNull(registeredBean, "'registeredBean' must not be null");
return resolveArguments(registeredBean, getMethod(registeredBean));
}
@ -152,8 +152,8 @@ public final class AutowiredMethodArgumentsResolver extends AutowiredElementReso
* @param instance the bean instance
*/
public void resolveAndInvoke(RegisteredBean registeredBean, Object instance) {
Assert.notNull(registeredBean, "RegisteredBean must not be null");
Assert.notNull(instance, "Instance must not be null");
Assert.notNull(registeredBean, "'registeredBean' must not be null");
Assert.notNull(instance, "'instance' must not be null");
Method method = getMethod(registeredBean);
AutowiredArguments resolved = resolveArguments(registeredBean, method);
if (resolved != null) {

View File

@ -53,7 +53,7 @@ public abstract class BeanRegistrationCodeFragments {
protected BeanRegistrationCodeFragments(BeanRegistrationCodeFragments codeFragments) {
Assert.notNull(codeFragments, "CodeFragments must not be null");
Assert.notNull(codeFragments, "'codeFragments' must not be null");
this.codeFragments = codeFragments;
}

View File

@ -75,7 +75,7 @@ class BeanRegistrationCodeGenerator implements BeanRegistrationCode {
@Override
public void addInstancePostProcessor(MethodReference methodReference) {
Assert.notNull(methodReference, "MethodReference must not be null");
Assert.notNull(methodReference, "'methodReference' must not be null");
this.instancePostProcessors.add(methodReference);
}

View File

@ -74,8 +74,8 @@ public final class RegisteredBean {
public static RegisteredBean of(ConfigurableBeanFactory beanFactory,
String beanName) {
Assert.notNull(beanFactory, "BeanFactory must not be null");
Assert.hasLength(beanName, "BeanName must not be empty");
Assert.notNull(beanFactory, "'beanFactory' must not be null");
Assert.hasLength(beanName, "'beanName' must not be empty");
return new RegisteredBean(beanFactory, () -> beanName, false,
() -> (RootBeanDefinition) beanFactory.getMergedBeanDefinition(beanName),
null);
@ -90,7 +90,7 @@ public final class RegisteredBean {
public static RegisteredBean ofInnerBean(RegisteredBean parent,
BeanDefinitionHolder innerBean) {
Assert.notNull(innerBean, "InnerBean must not be null");
Assert.notNull(innerBean, "'innerBean' must not be null");
return ofInnerBean(parent, innerBean.getBeanName(),
innerBean.getBeanDefinition());
}
@ -118,8 +118,8 @@ public final class RegisteredBean {
public static RegisteredBean ofInnerBean(RegisteredBean parent,
@Nullable String innerBeanName, BeanDefinition innerBeanDefinition) {
Assert.notNull(parent, "Parent must not be null");
Assert.notNull(innerBeanDefinition, "InnerBeanDefinition must not be null");
Assert.notNull(parent, "'parent' must not be null");
Assert.notNull(innerBeanDefinition, "'innerBeanDefinition' must not be null");
InnerBeanResolver resolver = new InnerBeanResolver(parent, innerBeanName,
innerBeanDefinition);
Supplier<String> beanName = StringUtils.hasLength(innerBeanName)

View File

@ -39,7 +39,7 @@ class AotFactoriesLoaderTests {
void createWhenBeanFactoryIsNullThrowsException() {
assertThatIllegalArgumentException()
.isThrownBy(() -> new AotFactoriesLoader(null))
.withMessage("BeanFactory must not be null");
.withMessage("'beanFactory' must not be null");
}
@Test
@ -47,7 +47,7 @@ class AotFactoriesLoaderTests {
ListableBeanFactory beanFactory = new DefaultListableBeanFactory();
assertThatIllegalArgumentException()
.isThrownBy(() -> new AotFactoriesLoader(beanFactory, null))
.withMessage("FactoriesLoader must not be null");
.withMessage("'factoriesLoader' must not be null");
}
@Test

View File

@ -45,7 +45,7 @@ class AutowiredFieldValueResolverTests {
@Test
void forFieldWhenFieldNameIsEmptyThrowsException() {
String message = "FieldName must not be empty";
String message = "'fieldName' must not be empty";
assertThatIllegalArgumentException()
.isThrownBy(() -> AutowiredFieldValueResolver.forField(null))
.withMessage(message);
@ -64,7 +64,7 @@ class AutowiredFieldValueResolverTests {
void resolveWhenRegisteredBeanIsNullThrowsException() {
assertThatIllegalArgumentException().isThrownBy(
() -> AutowiredFieldValueResolver.forField("string").resolve(null))
.withMessage("RegisteredBean must not be null");
.withMessage("'registeredBean' must not be null");
}
@Test
@ -122,7 +122,7 @@ class AutowiredFieldValueResolverTests {
assertThatIllegalArgumentException()
.isThrownBy(() -> AutowiredFieldValueResolver.forField("string")
.resolveAndSet(registeredBean, null))
.withMessage("Instance must not be null");
.withMessage("'instance' must not be null");
}
@Test
@ -141,7 +141,7 @@ class AutowiredFieldValueResolverTests {
assertThatIllegalArgumentException()
.isThrownBy(() -> AutowiredFieldValueResolver.forField("string")
.resolve(registeredBean, (ThrowingConsumer<Object>) null))
.withMessage("Action must not be null");
.withMessage("'action' must not be null");
}
@Test

View File

@ -76,7 +76,7 @@ class AutowiredInstantiationArgumentsResolverTests {
assertThatIllegalArgumentException()
.isThrownBy(() -> AutowiredInstantiationArgumentsResolver
.forConstructor((Class<?>[]) null))
.withMessage("ParameterTypes must not be null");
.withMessage("'parameterTypes' must not be null");
}
@Test
@ -84,7 +84,7 @@ class AutowiredInstantiationArgumentsResolverTests {
assertThatIllegalArgumentException()
.isThrownBy(() -> AutowiredInstantiationArgumentsResolver
.forConstructor(String.class, null))
.withMessage("ParameterTypes must not contain null elements");
.withMessage("'parameterTypes' must not contain null elements");
}
@Test
@ -104,7 +104,7 @@ class AutowiredInstantiationArgumentsResolverTests {
assertThatIllegalArgumentException()
.isThrownBy(() -> AutowiredInstantiationArgumentsResolver
.forFactoryMethod(null, "test"))
.withMessage("DeclaringClass must not be null");
.withMessage("'declaringClass' must not be null");
}
@Test
@ -112,7 +112,7 @@ class AutowiredInstantiationArgumentsResolverTests {
assertThatIllegalArgumentException()
.isThrownBy(() -> AutowiredInstantiationArgumentsResolver
.forFactoryMethod(SingleArgFactory.class, ""))
.withMessage("MethodName must not be empty");
.withMessage("'methodName' must not be empty");
}
@Test
@ -121,7 +121,7 @@ class AutowiredInstantiationArgumentsResolverTests {
.isThrownBy(
() -> AutowiredInstantiationArgumentsResolver.forFactoryMethod(
SingleArgFactory.class, "single", (Class<?>[]) null))
.withMessage("ParameterTypes must not be null");
.withMessage("'parameterTypes' must not be null");
}
@Test
@ -130,7 +130,7 @@ class AutowiredInstantiationArgumentsResolverTests {
.isThrownBy(
() -> AutowiredInstantiationArgumentsResolver.forFactoryMethod(
SingleArgFactory.class, "single", String.class, null))
.withMessage("ParameterTypes must not contain null elements");
.withMessage("'parameterTypes' must not contain null elements");
}
@Test
@ -153,7 +153,7 @@ class AutowiredInstantiationArgumentsResolverTests {
RegisteredBean registerBean = source.registerBean(this.beanFactory);
assertThatIllegalArgumentException()
.isThrownBy(() -> resolver.resolve(registerBean, null))
.withMessage("Action must not be null");
.withMessage("'action' must not be null");
}
@Test
@ -174,7 +174,7 @@ class AutowiredInstantiationArgumentsResolverTests {
AutowiredInstantiationArgumentsResolver resolver = AutowiredInstantiationArgumentsResolver
.forConstructor(String.class);
assertThatIllegalArgumentException().isThrownBy(() -> resolver.resolve(null))
.withMessage("RegisteredBean must not be null");
.withMessage("'registeredBean' must not be null");
}
@ParameterizedResolverTest(Sources.SINGLE_ARG)

View File

@ -47,7 +47,7 @@ class AutowiredMethodArgumentsResolverTests {
@Test
void forMethodWhenMethodNameIsEmptyThrowsException() {
String message = "MethodName must not be empty";
String message = "'methodName' must not be empty";
assertThatIllegalArgumentException()
.isThrownBy(() -> AutowiredMethodArgumentsResolver.forMethod(null))
.withMessage(message);
@ -68,7 +68,7 @@ class AutowiredMethodArgumentsResolverTests {
assertThatIllegalArgumentException()
.isThrownBy(() -> AutowiredMethodArgumentsResolver
.forMethod("injectString", String.class).resolve(null))
.withMessage("RegisteredBean must not be null");
.withMessage("'registeredBean' must not be null");
}
@Test
@ -134,7 +134,7 @@ class AutowiredMethodArgumentsResolverTests {
.isThrownBy(() -> AutowiredMethodArgumentsResolver
.forMethod("injectString", String.class)
.resolveAndInvoke(registeredBean, null))
.withMessage("Instance must not be null");
.withMessage("'instance' must not be null");
}
@Test
@ -155,7 +155,7 @@ class AutowiredMethodArgumentsResolverTests {
.isThrownBy(() -> AutowiredMethodArgumentsResolver
.forMethod("injectString", String.class)
.resolve(registeredBean, null))
.withMessage("Action must not be null");
.withMessage("'action' must not be null");
}
@Test

View File

@ -51,14 +51,14 @@ class RegisteredBeanTests {
void ofWhenBeanFactoryIsNullThrowsException() {
assertThatIllegalArgumentException()
.isThrownBy(() -> RegisteredBean.of(null, "bd"))
.withMessage("BeanFactory must not be null");
.withMessage("'beanFactory' must not be null");
}
@Test
void ofWhenBeanNameIsEmptyThrowsException() {
assertThatIllegalArgumentException()
.isThrownBy(() -> RegisteredBean.of(this.beanFactory, null))
.withMessage("BeanName must not be empty");
.withMessage("'beanName' must not be empty");
}
@Test
@ -66,7 +66,7 @@ class RegisteredBeanTests {
RegisteredBean parent = RegisteredBean.of(this.beanFactory, "bd");
assertThatIllegalArgumentException().isThrownBy(
() -> RegisteredBean.ofInnerBean(parent, (BeanDefinitionHolder) null))
.withMessage("InnerBean must not be null");
.withMessage("'innerBean' must not be null");
}
@Test
@ -74,7 +74,7 @@ class RegisteredBeanTests {
assertThatIllegalArgumentException()
.isThrownBy(() -> RegisteredBean.ofInnerBean(null,
new RootBeanDefinition(TestInnerBean.class)))
.withMessage("Parent must not be null");
.withMessage("'parent' must not be null");
}
@Test
@ -82,7 +82,7 @@ class RegisteredBeanTests {
RegisteredBean parent = RegisteredBean.of(this.beanFactory, "bd");
assertThatIllegalArgumentException()
.isThrownBy(() -> RegisteredBean.ofInnerBean(parent, "ib", null))
.withMessage("InnerBeanDefinition must not be null");
.withMessage("'innerBeanDefinition' must not be null");
}
@Test

View File

@ -42,7 +42,7 @@ final class SimpleTypeReference extends AbstractTypeReference {
}
static SimpleTypeReference of(String className) {
Assert.notNull(className, "ClassName must not be null");
Assert.notNull(className, "'className' must not be null");
if (!isValidClassName(className)) {
throw new IllegalStateException("Invalid class name '" + className + "'");
}

View File

@ -69,7 +69,7 @@ public final class TypeHint implements ConditionalHint {
* @return a builder
*/
public static Builder of(TypeReference type) {
Assert.notNull(type, "Type must not be null");
Assert.notNull(type, "'type' must not be null");
return new Builder(type);
}