Use Supplier variants of Assert methods

See gh-22699
This commit is contained in:
dreis2211
2020-08-02 09:12:40 +02:00
committed by Stephane Nicoll
parent bb3066f61a
commit e49e2dfff1
17 changed files with 32 additions and 28 deletions

View File

@@ -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.
@@ -88,8 +88,7 @@ class AutoConfigurationSorter {
}
processing.add(current);
for (String after : classes.getClassesRequestedAfter(current)) {
Assert.state(!processing.contains(after),
"AutoConfigure cycle detected between " + current + " and " + after);
checkForCycles(processing, current, after);
if (!sorted.contains(after) && toSort.contains(after)) {
doSortByAfterAnnotation(classes, toSort, sorted, processing, after);
}
@@ -98,6 +97,11 @@ class AutoConfigurationSorter {
sorted.add(current);
}
private void checkForCycles(Set<String> processing, String current, String after) {
Assert.state(!processing.contains(after),
() -> "AutoConfigure cycle detected between " + current + " and " + after);
}
private static class AutoConfigurationClasses {
private final Map<String, AutoConfigurationClass> classes = new HashMap<>();

View File

@@ -111,7 +111,7 @@ class Saml2RelyingPartyRegistrationConfiguration {
private RSAPrivateKey readPrivateKey(Resource location) {
Assert.state(location != null, "No private key location specified");
Assert.state(location.exists(), "Private key location '" + location + "' does not exist");
Assert.state(location.exists(), () -> "Private key location '" + location + "' does not exist");
try (InputStream inputStream = location.getInputStream()) {
return RsaKeyConverters.pkcs8().convert(inputStream);
}
@@ -122,7 +122,7 @@ class Saml2RelyingPartyRegistrationConfiguration {
private X509Certificate readCertificate(Resource location) {
Assert.state(location != null, "No certificate location specified");
Assert.state(location.exists(), "Certificate location '" + location + "' does not exist");
Assert.state(location.exists(), () -> "Certificate location '" + location + "' does not exist");
try (InputStream inputStream = location.getInputStream()) {
return (X509Certificate) CertificateFactory.getInstance("X.509").generateCertificate(inputStream);
}

View File

@@ -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.
@@ -152,7 +152,7 @@ public abstract class AbstractTemplateViewResolverProperties extends AbstractVie
*/
public void applyToMvcViewResolver(Object viewResolver) {
Assert.isInstanceOf(AbstractTemplateViewResolver.class, viewResolver,
"ViewResolver is not an instance of AbstractTemplateViewResolver :" + viewResolver);
() -> "ViewResolver is not an instance of AbstractTemplateViewResolver :" + viewResolver);
AbstractTemplateViewResolver resolver = (AbstractTemplateViewResolver) viewResolver;
resolver.setPrefix(getPrefix());
resolver.setSuffix(getSuffix());

View File

@@ -168,7 +168,7 @@ public class UndertowWebServerFactoryCustomizer
return (map) -> map.forEach((key, value) -> {
Option<T> option = (Option<T>) this.nameLookup.get(getCanonicalName(key));
Assert.state(option != null,
"Unable to find '" + key + "' in " + ClassUtils.getShortClassName(this.source));
() -> "Unable to find '" + key + "' in " + ClassUtils.getShortClassName(this.source));
T parsed = option.parseValue(value, getClass().getClassLoader());
function.apply(option).accept(parsed);
});