Browse Source

Polishing

pull/25598/head
Juergen Hoeller 6 years ago
parent
commit
7622d1e3fa
  1. 2
      spring-core/src/main/java/org/springframework/core/CollectionFactory.java
  2. 4
      spring-jdbc/src/main/java/org/springframework/jdbc/core/support/AbstractLobStreamingResultSetExtractor.java
  3. 4
      spring-jdbc/src/main/java/org/springframework/jdbc/object/SqlFunction.java
  4. 2
      spring-oxm/src/main/java/org/springframework/oxm/jaxb/Jaxb2Marshaller.java
  5. 20
      spring-test/src/main/java/org/springframework/mock/web/MockServletContext.java
  6. 4
      spring-tx/src/main/java/org/springframework/transaction/interceptor/MethodMapTransactionAttributeSource.java
  7. 40
      spring-web/src/test/java/org/springframework/mock/web/test/MockServletContext.java

2
spring-core/src/main/java/org/springframework/core/CollectionFactory.java

@ -43,7 +43,7 @@ import org.springframework.util.MultiValueMap; @@ -43,7 +43,7 @@ import org.springframework.util.MultiValueMap;
import org.springframework.util.ReflectionUtils;
/**
* Factory for collections that is aware of Java 5, Java 6, and Spring collection types.
* Factory for collections that is aware of common Java and Spring collection types.
*
* <p>Mainly for internal use within the framework.
*

4
spring-jdbc/src/main/java/org/springframework/jdbc/core/support/AbstractLobStreamingResultSetExtractor.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2019 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.
@ -79,7 +79,7 @@ public abstract class AbstractLobStreamingResultSetExtractor<T> implements Resul @@ -79,7 +79,7 @@ public abstract class AbstractLobStreamingResultSetExtractor<T> implements Resul
}
}
catch (IOException ex) {
throw new LobRetrievalFailureException("Couldn't stream LOB content", ex);
throw new LobRetrievalFailureException("Could not stream LOB content", ex);
}
}
return null;

4
spring-jdbc/src/main/java/org/springframework/jdbc/object/SqlFunction.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2019 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.
@ -160,7 +160,7 @@ public class SqlFunction<T> extends MappingSqlQuery<T> { @@ -160,7 +160,7 @@ public class SqlFunction<T> extends MappingSqlQuery<T> {
public int run(Object... parameters) {
Object obj = super.findObject(parameters);
if (!(obj instanceof Number)) {
throw new TypeMismatchDataAccessException("Couldn't convert result object [" + obj + "] to int");
throw new TypeMismatchDataAccessException("Could not convert result object [" + obj + "] to int");
}
return ((Number) obj).intValue();
}

2
spring-oxm/src/main/java/org/springframework/oxm/jaxb/Jaxb2Marshaller.java

@ -1019,7 +1019,7 @@ public class Jaxb2Marshaller implements MimeMarshaller, MimeUnmarshaller, Generi @@ -1019,7 +1019,7 @@ public class Jaxb2Marshaller implements MimeMarshaller, MimeUnmarshaller, Generi
return FileCopyUtils.copyToByteArray(dataHandler.getInputStream());
}
catch (IOException ex) {
throw new UnmarshallingFailureException("Couldn't read attachment", ex);
throw new UnmarshallingFailureException("Could not read attachment", ex);
}
}

20
spring-test/src/main/java/org/springframework/mock/web/MockServletContext.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2018 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.
@ -311,7 +311,9 @@ public class MockServletContext implements ServletContext { @@ -311,7 +311,9 @@ public class MockServletContext implements ServletContext {
return resourcePaths;
}
catch (IOException ex) {
logger.warn("Couldn't get resource paths for " + resource, ex);
if (logger.isWarnEnabled()) {
logger.warn("Could not get resource paths for " + resource, ex);
}
return null;
}
}
@ -330,7 +332,9 @@ public class MockServletContext implements ServletContext { @@ -330,7 +332,9 @@ public class MockServletContext implements ServletContext {
throw ex;
}
catch (IOException ex) {
logger.warn("Couldn't get URL for " + resource, ex);
if (logger.isWarnEnabled()) {
logger.warn("Could not get URL for " + resource, ex);
}
return null;
}
}
@ -346,7 +350,9 @@ public class MockServletContext implements ServletContext { @@ -346,7 +350,9 @@ public class MockServletContext implements ServletContext {
return resource.getInputStream();
}
catch (IOException ex) {
logger.warn("Couldn't open InputStream for " + resource, ex);
if (logger.isWarnEnabled()) {
logger.warn("Could not open InputStream for " + resource, ex);
}
return null;
}
}
@ -414,8 +420,8 @@ public class MockServletContext implements ServletContext { @@ -414,8 +420,8 @@ public class MockServletContext implements ServletContext {
registerNamedDispatcher(this.defaultServletName, new MockRequestDispatcher(this.defaultServletName));
}
@Override
@Deprecated
@Override
@Nullable
public Servlet getServlet(String name) {
return null;
@ -457,7 +463,9 @@ public class MockServletContext implements ServletContext { @@ -457,7 +463,9 @@ public class MockServletContext implements ServletContext {
return resource.getFile().getAbsolutePath();
}
catch (IOException ex) {
logger.warn("Couldn't determine real path of resource " + resource, ex);
if (logger.isWarnEnabled()) {
logger.warn("Could not determine real path of resource " + resource, ex);
}
return null;
}
}

4
spring-tx/src/main/java/org/springframework/transaction/interceptor/MethodMapTransactionAttributeSource.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 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.
@ -153,7 +153,7 @@ public class MethodMapTransactionAttributeSource @@ -153,7 +153,7 @@ public class MethodMapTransactionAttributeSource
}
if (matchingMethods.isEmpty()) {
throw new IllegalArgumentException(
"Couldn't find method '" + mappedName + "' on class [" + clazz.getName() + "]");
"Could not find method '" + mappedName + "' on class [" + clazz.getName() + "]");
}
// Register all matching methods

40
spring-web/src/test/java/org/springframework/mock/web/test/MockServletContext.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2018 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.
@ -48,6 +48,7 @@ import org.springframework.core.io.Resource; @@ -48,6 +48,7 @@ import org.springframework.core.io.Resource;
import org.springframework.core.io.ResourceLoader;
import org.springframework.http.MediaType;
import org.springframework.http.MediaTypeFactory;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
import org.springframework.util.MimeType;
@ -129,14 +130,17 @@ public class MockServletContext implements ServletContext { @@ -129,14 +130,17 @@ public class MockServletContext implements ServletContext {
private final Set<String> declaredRoles = new LinkedHashSet<>();
@Nullable
private Set<SessionTrackingMode> sessionTrackingModes;
private final SessionCookieConfig sessionCookieConfig = new MockSessionCookieConfig();
private int sessionTimeout;
@Nullable
private String requestCharacterEncoding;
@Nullable
private String responseCharacterEncoding;
private final Map<String, MediaType> mimeTypes = new LinkedHashMap<>();
@ -165,7 +169,7 @@ public class MockServletContext implements ServletContext { @@ -165,7 +169,7 @@ public class MockServletContext implements ServletContext {
* and no base path.
* @param resourceLoader the ResourceLoader to use (or null for the default)
*/
public MockServletContext(ResourceLoader resourceLoader) {
public MockServletContext(@Nullable ResourceLoader resourceLoader) {
this("", resourceLoader);
}
@ -178,7 +182,7 @@ public class MockServletContext implements ServletContext { @@ -178,7 +182,7 @@ public class MockServletContext implements ServletContext {
* @param resourceLoader the ResourceLoader to use (or null for the default)
* @see #registerNamedDispatcher
*/
public MockServletContext(String resourceBasePath, ResourceLoader resourceLoader) {
public MockServletContext(String resourceBasePath, @Nullable ResourceLoader resourceLoader) {
this.resourceLoader = (resourceLoader != null ? resourceLoader : new DefaultResourceLoader());
this.resourceBasePath = resourceBasePath;
@ -262,6 +266,7 @@ public class MockServletContext implements ServletContext { @@ -262,6 +266,7 @@ public class MockServletContext implements ServletContext {
}
@Override
@Nullable
public String getMimeType(String filePath) {
String extension = StringUtils.getFilenameExtension(filePath);
if (this.mimeTypes.containsKey(extension)) {
@ -285,6 +290,7 @@ public class MockServletContext implements ServletContext { @@ -285,6 +290,7 @@ public class MockServletContext implements ServletContext {
}
@Override
@Nullable
public Set<String> getResourcePaths(String path) {
String actualPath = (path.endsWith("/") ? path : path + "/");
Resource resource = this.resourceLoader.getResource(getResourceLocation(actualPath));
@ -305,12 +311,15 @@ public class MockServletContext implements ServletContext { @@ -305,12 +311,15 @@ public class MockServletContext implements ServletContext {
return resourcePaths;
}
catch (IOException ex) {
logger.warn("Couldn't get resource paths for " + resource, ex);
if (logger.isWarnEnabled()) {
logger.warn("Could not get resource paths for " + resource, ex);
}
return null;
}
}
@Override
@Nullable
public URL getResource(String path) throws MalformedURLException {
Resource resource = this.resourceLoader.getResource(getResourceLocation(path));
if (!resource.exists()) {
@ -323,12 +332,15 @@ public class MockServletContext implements ServletContext { @@ -323,12 +332,15 @@ public class MockServletContext implements ServletContext {
throw ex;
}
catch (IOException ex) {
logger.warn("Couldn't get URL for " + resource, ex);
if (logger.isWarnEnabled()) {
logger.warn("Could not get URL for " + resource, ex);
}
return null;
}
}
@Override
@Nullable
public InputStream getResourceAsStream(String path) {
Resource resource = this.resourceLoader.getResource(getResourceLocation(path));
if (!resource.exists()) {
@ -338,7 +350,9 @@ public class MockServletContext implements ServletContext { @@ -338,7 +350,9 @@ public class MockServletContext implements ServletContext {
return resource.getInputStream();
}
catch (IOException ex) {
logger.warn("Couldn't open InputStream for " + resource, ex);
if (logger.isWarnEnabled()) {
logger.warn("Could not open InputStream for " + resource, ex);
}
return null;
}
}
@ -406,8 +420,9 @@ public class MockServletContext implements ServletContext { @@ -406,8 +420,9 @@ public class MockServletContext implements ServletContext {
registerNamedDispatcher(this.defaultServletName, new MockRequestDispatcher(this.defaultServletName));
}
@Override
@Deprecated
@Override
@Nullable
public Servlet getServlet(String name) {
return null;
}
@ -441,13 +456,16 @@ public class MockServletContext implements ServletContext { @@ -441,13 +456,16 @@ public class MockServletContext implements ServletContext {
}
@Override
@Nullable
public String getRealPath(String path) {
Resource resource = this.resourceLoader.getResource(getResourceLocation(path));
try {
return resource.getFile().getAbsolutePath();
}
catch (IOException ex) {
logger.warn("Couldn't determine real path of resource " + resource, ex);
if (logger.isWarnEnabled()) {
logger.warn("Could not determine real path of resource " + resource, ex);
}
return null;
}
}
@ -484,6 +502,7 @@ public class MockServletContext implements ServletContext { @@ -484,6 +502,7 @@ public class MockServletContext implements ServletContext {
}
@Override
@Nullable
public Object getAttribute(String name) {
Assert.notNull(name, "Attribute name must not be null");
return this.attributes.get(name);
@ -495,7 +514,7 @@ public class MockServletContext implements ServletContext { @@ -495,7 +514,7 @@ public class MockServletContext implements ServletContext {
}
@Override
public void setAttribute(String name, Object value) {
public void setAttribute(String name, @Nullable Object value) {
Assert.notNull(name, "Attribute name must not be null");
if (value != null) {
this.attributes.put(name, value);
@ -521,6 +540,7 @@ public class MockServletContext implements ServletContext { @@ -521,6 +540,7 @@ public class MockServletContext implements ServletContext {
}
@Override
@Nullable
public ClassLoader getClassLoader() {
return ClassUtils.getDefaultClassLoader();
}
@ -630,6 +650,7 @@ public class MockServletContext implements ServletContext { @@ -630,6 +650,7 @@ public class MockServletContext implements ServletContext {
* @see javax.servlet.ServletContext#getServletRegistration(java.lang.String)
*/
@Override
@Nullable
public ServletRegistration getServletRegistration(String servletName) {
return null;
}
@ -668,6 +689,7 @@ public class MockServletContext implements ServletContext { @@ -668,6 +689,7 @@ public class MockServletContext implements ServletContext {
* @see javax.servlet.ServletContext#getFilterRegistration(java.lang.String)
*/
@Override
@Nullable
public FilterRegistration getFilterRegistration(String filterName) {
return null;
}

Loading…
Cancel
Save