Use Supplier variants of Assert methods
See gh-22699
This commit is contained in:
committed by
Stephane Nicoll
parent
bb3066f61a
commit
e49e2dfff1
@@ -105,7 +105,7 @@ class ConfigDataLoaders {
|
||||
}
|
||||
}
|
||||
}
|
||||
Assert.state(result != null, "No loader found for location '" + location + "'");
|
||||
Assert.state(result != null, () -> "No loader found for location '" + location + "'");
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
* Copyright 2012-2020 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.
|
||||
@@ -92,7 +92,7 @@ public class DelegatingApplicationContextInitializer
|
||||
Class<?> requireContextClass = GenericTypeResolver.resolveTypeArgument(initializerClass,
|
||||
ApplicationContextInitializer.class);
|
||||
Assert.isAssignable(requireContextClass, contextClass,
|
||||
String.format(
|
||||
() -> String.format(
|
||||
"Could not add context initializer [%s] as its generic parameter [%s] is not assignable "
|
||||
+ "from the type of application context used by this context loader [%s]: ",
|
||||
initializerClass.getName(), requireContextClass.getName(), contextClass.getName()));
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
* Copyright 2012-2020 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.
|
||||
@@ -81,7 +81,7 @@ public class DelegatingApplicationListener implements ApplicationListener<Applic
|
||||
try {
|
||||
Class<?> clazz = ClassUtils.forName(className, ClassUtils.getDefaultClassLoader());
|
||||
Assert.isAssignable(ApplicationListener.class, clazz,
|
||||
"class [" + className + "] must implement ApplicationListener");
|
||||
() -> "class [" + className + "] must implement ApplicationListener");
|
||||
listeners.add((ApplicationListener<ApplicationEvent>) BeanUtils.instantiateClass(clazz));
|
||||
}
|
||||
catch (Exception ex) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
* Copyright 2012-2020 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.
|
||||
@@ -249,7 +249,7 @@ public final class ConfigurationPropertiesBean {
|
||||
static ConfigurationPropertiesBean forValueObject(Class<?> beanClass, String beanName) {
|
||||
ConfigurationPropertiesBean propertiesBean = create(beanName, null, beanClass, null);
|
||||
Assert.state(propertiesBean != null && propertiesBean.getBindMethod() == BindMethod.VALUE_OBJECT,
|
||||
"Bean '" + beanName + "' is not a @ConfigurationProperties value object");
|
||||
() -> "Bean '" + beanName + "' is not a @ConfigurationProperties value object");
|
||||
return propertiesBean;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
* Copyright 2012-2020 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.
|
||||
@@ -67,9 +67,9 @@ class ConfigurationPropertiesBindConstructorProvider implements BindConstructorP
|
||||
for (Constructor<?> candidate : candidates) {
|
||||
if (MergedAnnotations.from(candidate).isPresent(ConstructorBinding.class)) {
|
||||
Assert.state(candidate.getParameterCount() > 0,
|
||||
type.getName() + " declares @ConstructorBinding on a no-args constructor");
|
||||
() -> type.getName() + " declares @ConstructorBinding on a no-args constructor");
|
||||
Assert.state(constructor == null,
|
||||
type.getName() + " has more than one @ConstructorBinding constructor");
|
||||
() -> type.getName() + " has more than one @ConstructorBinding constructor");
|
||||
constructor = candidate;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ public enum PeriodStyle {
|
||||
}
|
||||
Matcher matcher = matcher(value);
|
||||
Assert.state(matcher.matches(), "Does not match simple period pattern");
|
||||
Assert.isTrue(hasAtLeastOneGroupValue(matcher), "'" + value + "' is not a valid simple period");
|
||||
Assert.isTrue(hasAtLeastOneGroupValue(matcher), () -> "'" + value + "' is not a valid simple period");
|
||||
int years = parseInt(matcher, 1);
|
||||
int months = parseInt(matcher, 2);
|
||||
int weeks = parseInt(matcher, 3);
|
||||
|
||||
@@ -100,8 +100,8 @@ public class VolumeMountDirectoryPropertySource extends EnumerablePropertySource
|
||||
|
||||
private VolumeMountDirectoryPropertySource(String name, Path sourceDirectory, Set<Option> options) {
|
||||
super(name, sourceDirectory);
|
||||
Assert.isTrue(Files.exists(sourceDirectory), "Directory '" + sourceDirectory + "' does not exist");
|
||||
Assert.isTrue(Files.isDirectory(sourceDirectory), "File '" + sourceDirectory + "' is not a directory");
|
||||
Assert.isTrue(Files.exists(sourceDirectory), () -> "Directory '" + sourceDirectory + "' does not exist");
|
||||
Assert.isTrue(Files.isDirectory(sourceDirectory), () -> "File '" + sourceDirectory + "' is not a directory");
|
||||
this.propertyFiles = PropertyFile.findAll(sourceDirectory, options);
|
||||
this.options = options;
|
||||
this.names = StringUtils.toStringArray(this.propertyFiles.keySet());
|
||||
|
||||
@@ -286,7 +286,7 @@ public class LogbackLoggingSystem extends Slf4JLoggingSystem {
|
||||
private LoggerContext getLoggerContext() {
|
||||
ILoggerFactory factory = StaticLoggerBinder.getSingleton().getLoggerFactory();
|
||||
Assert.isInstanceOf(LoggerContext.class, factory,
|
||||
String.format(
|
||||
() -> String.format(
|
||||
"LoggerFactory is not a Logback LoggerContext but Logback is on "
|
||||
+ "the classpath. Either remove Logback or the competing "
|
||||
+ "implementation (%s loaded from %s). If you are using "
|
||||
|
||||
Reference in New Issue
Block a user