Skip to content

Commit 1e42464

Browse files
committed
Polishing
1 parent 896f0d9 commit 1e42464

File tree

13 files changed

+95
-78
lines changed

13 files changed

+95
-78
lines changed

spring-aop/src/main/java/org/springframework/aop/interceptor/AsyncExecutionAspectSupport.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2014 the original author or authors.
2+
* Copyright 2002-2015 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -31,7 +31,7 @@
3131

3232
/**
3333
* Base class for asynchronous method execution aspects, such as
34-
* {@link org.springframework.scheduling.annotation.AnnotationAsyncExecutionInterceptor}
34+
* {@code org.springframework.scheduling.annotation.AnnotationAsyncExecutionInterceptor}
3535
* or {@code org.springframework.scheduling.aspectj.AnnotationAsyncExecutionAspect}.
3636
*
3737
* <p>Provides support for <i>executor qualification</i> on a method-by-method basis.

spring-context/src/test/java/org/springframework/scheduling/config/ExecutorBeanDefinitionParserTests.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2015 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -20,7 +20,6 @@
2020
import java.util.concurrent.Executor;
2121
import java.util.concurrent.FutureTask;
2222

23-
import static org.junit.Assert.*;
2423
import org.junit.Before;
2524
import org.junit.Test;
2625

@@ -32,6 +31,8 @@
3231
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
3332
import org.springframework.util.CustomizableThreadCreator;
3433

34+
import static org.junit.Assert.*;
35+
3536
/**
3637
* @author Mark Fisher
3738
* @author Juergen Hoeller
@@ -47,21 +48,23 @@ public void setup() {
4748
"executorContext.xml", ExecutorBeanDefinitionParserTests.class);
4849
}
4950

51+
5052
@Test
5153
public void defaultExecutor() throws Exception {
52-
Object executor = this.context.getBean("default");
54+
ThreadPoolTaskExecutor executor = this.context.getBean("default", ThreadPoolTaskExecutor.class);
5355
assertEquals(1, getCorePoolSize(executor));
5456
assertEquals(Integer.MAX_VALUE, getMaxPoolSize(executor));
5557
assertEquals(Integer.MAX_VALUE, getQueueCapacity(executor));
5658
assertEquals(60, getKeepAliveSeconds(executor));
5759
assertEquals(false, getAllowCoreThreadTimeOut(executor));
60+
5861
FutureTask<String> task = new FutureTask<String>(new Callable<String>() {
5962
@Override
6063
public String call() throws Exception {
6164
return "foo";
6265
}
6366
});
64-
((ThreadPoolTaskExecutor)executor).execute(task);
67+
executor.execute(task);
6568
assertEquals("foo", task.get());
6669
}
6770

spring-tx/src/test/java/org/springframework/transaction/interceptor/BeanFactoryTransactionTests.java

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2013 the original author or authors.
2+
* Copyright 2002-2015 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -20,10 +20,11 @@
2020
import java.lang.reflect.Proxy;
2121
import java.util.Map;
2222

23-
import junit.framework.TestCase;
24-
2523
import org.aopalliance.intercept.MethodInterceptor;
2624
import org.aopalliance.intercept.MethodInvocation;
25+
import org.junit.Before;
26+
import org.junit.Test;
27+
2728
import org.springframework.aop.support.AopUtils;
2829
import org.springframework.aop.support.StaticMethodMatcherPointcut;
2930
import org.springframework.aop.target.HotSwappableTargetSource;
@@ -40,51 +41,61 @@
4041
import org.springframework.transaction.TransactionException;
4142
import org.springframework.transaction.TransactionStatus;
4243

44+
import static org.junit.Assert.*;
4345
import static org.mockito.BDDMockito.*;
4446

47+
4548
/**
4649
* Test cases for AOP transaction management.
4750
*
4851
* @author Rod Johnson
52+
* @author Juergen Hoeller
4953
* @since 23.04.2003
5054
*/
51-
public class BeanFactoryTransactionTests extends TestCase {
55+
public class BeanFactoryTransactionTests {
5256

5357
private DefaultListableBeanFactory factory;
5458

55-
@Override
59+
60+
@Before
5661
public void setUp() {
5762
this.factory = new DefaultListableBeanFactory();
5863
new XmlBeanDefinitionReader(this.factory).loadBeanDefinitions(
5964
new ClassPathResource("transactionalBeanFactory.xml", getClass()));
6065
}
6166

67+
68+
@Test
6269
public void testGetsAreNotTransactionalWithProxyFactory1() throws NoSuchMethodException {
6370
ITestBean testBean = (ITestBean) factory.getBean("proxyFactory1");
6471
assertTrue("testBean is a dynamic proxy", Proxy.isProxyClass(testBean.getClass()));
6572
doTestGetsAreNotTransactional(testBean);
6673
}
6774

75+
@Test
6876
public void testGetsAreNotTransactionalWithProxyFactory2DynamicProxy() throws NoSuchMethodException {
6977
this.factory.preInstantiateSingletons();
7078
ITestBean testBean = (ITestBean) factory.getBean("proxyFactory2DynamicProxy");
7179
assertTrue("testBean is a dynamic proxy", Proxy.isProxyClass(testBean.getClass()));
7280
doTestGetsAreNotTransactional(testBean);
7381
}
7482

83+
@Test
7584
public void testGetsAreNotTransactionalWithProxyFactory2Cglib() throws NoSuchMethodException {
7685
ITestBean testBean = (ITestBean) factory.getBean("proxyFactory2Cglib");
7786
assertTrue("testBean is CGLIB advised", AopUtils.isCglibProxy(testBean));
7887
doTestGetsAreNotTransactional(testBean);
7988
}
8089

90+
@Test
8191
public void testProxyFactory2Lazy() throws NoSuchMethodException {
8292
ITestBean testBean = (ITestBean) factory.getBean("proxyFactory2Lazy");
8393
assertFalse(factory.containsSingleton("target"));
8494
assertEquals(666, testBean.getAge());
8595
assertTrue(factory.containsSingleton("target"));
8696
}
8797

98+
@Test
8899
public void testCglibTransactionProxyImplementsNoInterfaces() throws NoSuchMethodException {
89100
ImplementsNoInterfaces ini = (ImplementsNoInterfaces) factory.getBean("cglibNoInterfaces");
90101
assertTrue("testBean is CGLIB advised", AopUtils.isCglibProxy(ini));
@@ -99,6 +110,7 @@ public void testCglibTransactionProxyImplementsNoInterfaces() throws NoSuchMetho
99110
assertEquals(2, ptm.commits);
100111
}
101112

113+
@Test
102114
public void testGetsAreNotTransactionalWithProxyFactory3() throws NoSuchMethodException {
103115
ITestBean testBean = (ITestBean) factory.getBean("proxyFactory3");
104116
assertTrue("testBean is a full proxy", testBean instanceof DerivedTestBean);
@@ -158,14 +170,16 @@ public void rollback(TransactionStatus status) throws TransactionException {
158170
assertTrue(testBean.getAge() == age);
159171
}
160172

173+
@Test
161174
public void testGetBeansOfTypeWithAbstract() {
162-
Map beansOfType = factory.getBeansOfType(ITestBean.class, true, true);
175+
Map<String, ITestBean> beansOfType = factory.getBeansOfType(ITestBean.class, true, true);
163176
assertNotNull(beansOfType);
164177
}
165178

166179
/**
167180
* Check that we fail gracefully if the user doesn't set any transaction attributes.
168181
*/
182+
@Test
169183
public void testNoTransactionAttributeSource() {
170184
try {
171185
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
@@ -181,6 +195,7 @@ public void testNoTransactionAttributeSource() {
181195
/**
182196
* Test that we can set the target to a dynamic TargetSource.
183197
*/
198+
@Test
184199
public void testDynamicTargetSource() throws NoSuchMethodException {
185200
// Install facade
186201
CallCountingTransactionManager txMan = new CallCountingTransactionManager();
@@ -211,7 +226,7 @@ public static class InvocationCounterPointcut extends StaticMethodMatcherPointcu
211226
int counter = 0;
212227

213228
@Override
214-
public boolean matches(Method method, Class clazz) {
229+
public boolean matches(Method method, Class<?> clazz) {
215230
counter++;
216231
return true;
217232
}

spring-web/src/main/java/org/springframework/web/context/request/async/NoSupportAsyncWebRequest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2015 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -49,6 +49,7 @@ public boolean isAsyncStarted() {
4949
return false;
5050
}
5151

52+
5253
// Not supported
5354

5455
public void startAsync() {

spring-web/src/main/java/org/springframework/web/context/request/async/StandardServletAsyncWebRequest.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2015 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -20,7 +20,6 @@
2020
import java.util.ArrayList;
2121
import java.util.List;
2222
import java.util.concurrent.atomic.AtomicBoolean;
23-
2423
import javax.servlet.AsyncContext;
2524
import javax.servlet.AsyncEvent;
2625
import javax.servlet.AsyncListener;
@@ -36,7 +35,7 @@
3635
* <p>The servlet and all filters involved in an async request must have async
3736
* support enabled using the Servlet API or by adding an
3837
* {@code <async-support>true</async-support>} element to servlet and filter
39-
* declarations in web.xml
38+
* declarations in {@code web.xml}.
4039
*
4140
* @author Rossen Stoyanchev
4241
* @since 3.2
@@ -63,9 +62,9 @@ public StandardServletAsyncWebRequest(HttpServletRequest request, HttpServletRes
6362
super(request, response);
6463
}
6564

65+
6666
/**
67-
* {@inheritDoc}
68-
* <p>In Servlet 3 async processing, the timeout period begins after the
67+
* In Servlet 3 async processing, the timeout period begins after the
6968
* container processing thread has exited.
7069
*/
7170
public void setTimeout(Long timeout) {
@@ -82,7 +81,7 @@ public void addCompletionHandler(Runnable runnable) {
8281
}
8382

8483
public boolean isAsyncStarted() {
85-
return ((this.asyncContext != null) && getRequest().isAsyncStarted());
84+
return (this.asyncContext != null && getRequest().isAsyncStarted());
8685
}
8786

8887
/**
@@ -101,6 +100,7 @@ public void startAsync() {
101100
"or by adding \"<async-supported>true</async-supported>\" to servlet and " +
102101
"filter declarations in web.xml.");
103102
Assert.state(!isAsyncComplete(), "Async processing has already completed");
103+
104104
if (isAsyncStarted()) {
105105
return;
106106
}
@@ -116,6 +116,7 @@ public void dispatch() {
116116
this.asyncContext.dispatch();
117117
}
118118

119+
119120
// ---------------------------------------------------------------------
120121
// Implementation of AsyncListener methods
121122
// ---------------------------------------------------------------------

spring-web/src/main/java/org/springframework/web/context/request/async/WebAsyncUtils.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2015 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -13,6 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16+
1617
package org.springframework.web.context.request.async;
1718

1819
import java.lang.reflect.Constructor;
@@ -67,18 +68,17 @@ public static WebAsyncManager getAsyncManager(WebRequest webRequest) {
6768
}
6869

6970
/**
70-
* Create an AsyncWebRequest instance. By default an instance of
71-
* {@link StandardServletAsyncWebRequest} is created if running in Servlet
72-
* 3.0 (or higher) environment or as a fallback, an instance of
73-
* {@link NoSupportAsyncWebRequest} is returned.
74-
*
71+
* Create an AsyncWebRequest instance. By default, an instance of
72+
* {@link StandardServletAsyncWebRequest} gets created when running in
73+
* Servlet 3.0 (or higher) environment - as a fallback, an instance
74+
* of {@link NoSupportAsyncWebRequest} will be returned.
7575
* @param request the current request
7676
* @param response the current response
77-
* @return an AsyncWebRequest instance, never {@code null}
77+
* @return an AsyncWebRequest instance (never {@code null})
7878
*/
7979
public static AsyncWebRequest createAsyncWebRequest(HttpServletRequest request, HttpServletResponse response) {
80-
return ClassUtils.hasMethod(ServletRequest.class, "startAsync") ?
81-
createStandardServletAsyncWebRequest(request, response) : new NoSupportAsyncWebRequest(request, response);
80+
return (ClassUtils.hasMethod(ServletRequest.class, "startAsync") ?
81+
createStandardServletAsyncWebRequest(request, response) : new NoSupportAsyncWebRequest(request, response));
8282
}
8383

8484
private static AsyncWebRequest createStandardServletAsyncWebRequest(HttpServletRequest request, HttpServletResponse response) {
@@ -90,8 +90,8 @@ private static AsyncWebRequest createStandardServletAsyncWebRequest(HttpServletR
9090
}
9191
return (AsyncWebRequest) BeanUtils.instantiateClass(standardAsyncRequestConstructor, request, response);
9292
}
93-
catch (Throwable t) {
94-
throw new IllegalStateException("Failed to instantiate StandardServletAsyncWebRequest", t);
93+
catch (Throwable ex) {
94+
throw new IllegalStateException("Failed to instantiate StandardServletAsyncWebRequest", ex);
9595
}
9696
}
9797

spring-web/src/main/java/org/springframework/web/multipart/MultipartFile.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2015 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -94,6 +94,9 @@ public interface MultipartFile {
9494
* <p>If the file has been moved in the filesystem, this operation cannot
9595
* be invoked again. Therefore, call this method just once to be able to
9696
* work with any storage mechanism.
97+
* <p><strong>Note:</strong> when using Servlet 3.0 multipart support you
98+
* need to configure the location relative to which files will be copied
99+
* as explained in {@link javax.servlet.http.Part#write}.
97100
* @param dest the destination file
98101
* @throws IOException in case of reading or writing errors
99102
* @throws IllegalStateException if the file has already been moved

0 commit comments

Comments
 (0)