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

Issue: SPR-15196
(cherry picked from commit 1b2dc36)
This commit is contained in:
Juergen Hoeller
2017-01-30 22:15:53 +01:00
parent b386be1529
commit 28849e0987
85 changed files with 683 additions and 602 deletions

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.
@@ -177,7 +177,9 @@ public class SimpleClientHttpRequestFactory implements ClientHttpRequestFactory,
*/
protected HttpURLConnection openConnection(URL url, Proxy proxy) throws IOException {
URLConnection urlConnection = (proxy != null ? url.openConnection(proxy) : url.openConnection());
Assert.isInstanceOf(HttpURLConnection.class, urlConnection);
if (!HttpURLConnection.class.isInstance(urlConnection)) {
throw new IllegalStateException("HttpURLConnection required for [" + url + "] but got: " + urlConnection);
}
return (HttpURLConnection) urlConnection;
}

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.
@@ -60,16 +60,17 @@ public class MappingJackson2XmlHttpMessageConverter extends AbstractJackson2Http
super(objectMapper, new MediaType("application", "xml"),
new MediaType("text", "xml"),
new MediaType("application", "*+xml"));
Assert.isAssignable(XmlMapper.class, objectMapper.getClass());
Assert.isInstanceOf(XmlMapper.class, objectMapper, "XmlMapper required");
}
/**
* {@inheritDoc}
* The {@code objectMapper} parameter must be a {@link XmlMapper} instance.
* The {@code ObjectMapper} parameter must be a {@link XmlMapper} instance.
*/
@Override
public void setObjectMapper(ObjectMapper objectMapper) {
Assert.isAssignable(XmlMapper.class, objectMapper.getClass());
Assert.isInstanceOf(XmlMapper.class, objectMapper, "XmlMapper required");
super.setObjectMapper(objectMapper);
}

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.
@@ -180,7 +180,9 @@ public class ServletServerHttpRequest implements ServerHttpRequest {
@Override
public ServerHttpAsyncRequestControl getAsyncRequestControl(ServerHttpResponse response) {
if (this.asyncRequestControl == null) {
Assert.isInstanceOf(ServletServerHttpResponse.class, response);
if (!ServletServerHttpResponse.class.isInstance(response)) {
throw new IllegalArgumentException("Response must be a ServletServerHttpResponse: " + response.getClass());
}
ServletServerHttpResponse servletServerResponse = (ServletServerHttpResponse) response;
this.asyncRequestControl = new ServletServerHttpAsyncRequestControl(this, servletServerResponse);
}

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.
@@ -140,15 +140,15 @@ public class PathExtensionContentNegotiationStrategy extends AbstractMappingCont
/**
* A public method exposing the knowledge of the path extension strategy to
* resolve file extensions to a MediaType in this case for a given
* resolve file extensions to a {@link MediaType} in this case for a given
* {@link Resource}. The method first looks up any explicitly registered
* file extensions first and then falls back on JAF if available.
* @param resource the resource to look up
* @return the MediaType for the extension or {@code null}.
* @return the MediaType for the extension, or {@code null} if none found
* @since 4.3
*/
public MediaType getMediaTypeForResource(Resource resource) {
Assert.notNull(resource);
Assert.notNull(resource, "Resource must not be null");
MediaType mediaType = null;
String filename = resource.getFilename();
String extension = StringUtils.getFilenameExtension(filename);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2015 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.
@@ -64,7 +64,7 @@ public class UnsatisfiedServletRequestParameterException extends ServletRequestB
Map<String, String[]> actualParams) {
super("");
Assert.isTrue(!CollectionUtils.isEmpty(paramConditions));
Assert.notEmpty(paramConditions, "Parameter conditions must not be empty");
this.paramConditions = paramConditions;
this.actualParams = actualParams;
}

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.
@@ -40,7 +40,6 @@ import org.springframework.core.annotation.AnnotationAwareOrderComparator;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.support.PropertiesLoaderUtils;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
@@ -517,7 +516,10 @@ public class ContextLoader {
private Class<ApplicationContextInitializer<ConfigurableApplicationContext>> loadInitializerClass(String className) {
try {
Class<?> clazz = ClassUtils.forName(className, ClassUtils.getDefaultClassLoader());
Assert.isAssignable(ApplicationContextInitializer.class, clazz);
if (!ApplicationContextInitializer.class.isAssignableFrom(clazz)) {
throw new ApplicationContextException(
"Initializer class does not implement ApplicationContextInitializer interface: " + clazz);
}
return (Class<ApplicationContextInitializer<ConfigurableApplicationContext>>) clazz;
}
catch (ClassNotFoundException ex) {

View File

@@ -793,7 +793,7 @@ final class HierarchicalUriComponents extends UriComponents {
private final List<PathComponent> pathComponents;
public PathComponentComposite(List<PathComponent> pathComponents) {
Assert.notNull(pathComponents);
Assert.notNull(pathComponents, "PathComponent List must not be null");
this.pathComponents = pathComponents;
}