Polishing

This commit is contained in:
Juergen Hoeller 2014-04-29 15:45:56 +02:00
parent a0658c5832
commit e510f6393a
3 changed files with 23 additions and 26 deletions

View File

@ -16,8 +16,6 @@
package org.springframework.scheduling.annotation;
import static org.junit.Assert.*;
import java.lang.reflect.Method;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutionException;
@ -37,6 +35,8 @@ import org.springframework.core.io.ClassPathResource;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.util.ReflectionUtils;
import static org.junit.Assert.*;
/**
* @author Mark Fisher
* @author Juergen Hoeller
@ -57,7 +57,7 @@ public class AsyncAnnotationBeanPostProcessorTests {
public void invokedAsynchronously() {
ConfigurableApplicationContext context = initContext(
new RootBeanDefinition(AsyncAnnotationBeanPostProcessor.class));
ITestBean testBean = (ITestBean) context.getBean("target");
ITestBean testBean = context.getBean("target", ITestBean.class);
testBean.test();
Thread mainThread = Thread.currentThread();
testBean.await(3000);
@ -74,7 +74,7 @@ public class AsyncAnnotationBeanPostProcessorTests {
executor.afterPropertiesSet();
processorDefinition.getPropertyValues().add("executor", executor);
ConfigurableApplicationContext context = initContext(processorDefinition);
ITestBean testBean = (ITestBean) context.getBean("target");
ITestBean testBean = context.getBean("target", ITestBean.class);
testBean.test();
testBean.await(3000);
Thread asyncThread = testBean.getThread();
@ -87,14 +87,14 @@ public class AsyncAnnotationBeanPostProcessorTests {
GenericXmlApplicationContext context = new GenericXmlApplicationContext();
context.load(new ClassPathResource("taskNamespaceTests.xml", getClass()));
context.refresh();
ITestBean testBean = (ITestBean) context.getBean("target");
ITestBean testBean = context.getBean("target", ITestBean.class);
testBean.test();
testBean.await(3000);
Thread asyncThread = testBean.getThread();
assertTrue(asyncThread.getName().startsWith("testExecutor"));
TestableAsyncUncaughtExceptionHandler exceptionHandler = (TestableAsyncUncaughtExceptionHandler)
context.getBean("exceptionHandler");
TestableAsyncUncaughtExceptionHandler exceptionHandler =
context.getBean("exceptionHandler", TestableAsyncUncaughtExceptionHandler.class);
assertFalse("handler should not have been called yet", exceptionHandler.isCalled());
testBean.failWithVoid();
@ -114,12 +114,12 @@ public class AsyncAnnotationBeanPostProcessorTests {
try {
result.get();
}
catch (InterruptedException e) {
fail("Should not have failed with InterruptedException");
catch (InterruptedException ex) {
fail("Should not have failed with InterruptedException: " + ex);
}
catch (ExecutionException e) {
catch (ExecutionException ex) {
// expected
assertEquals("Wrong exception cause", UnsupportedOperationException.class, e.getCause().getClass());
assertEquals("Wrong exception cause", UnsupportedOperationException.class, ex.getCause().getClass());
}
}
@ -162,8 +162,7 @@ public class AsyncAnnotationBeanPostProcessorTests {
}
}
private ConfigurableApplicationContext initContext(
BeanDefinition asyncAnnotationBeanPostProcessorDefinition) {
private ConfigurableApplicationContext initContext(BeanDefinition asyncAnnotationBeanPostProcessorDefinition) {
StaticApplicationContext context = new StaticApplicationContext();
BeanDefinition targetDefinition =
new RootBeanDefinition(AsyncAnnotationBeanPostProcessorTests.TestBean.class);
@ -173,6 +172,7 @@ public class AsyncAnnotationBeanPostProcessorTests {
return context;
}
private static interface ITestBean {
Thread getThread();
@ -227,9 +227,11 @@ public class AsyncAnnotationBeanPostProcessorTests {
}
private static class DirectExecutor implements Executor {
@Override
public void execute(Runnable r) {
r.run();
}
}
}

View File

@ -275,10 +275,8 @@ public abstract class AnnotationUtils {
* @param visited the set of annotations that have already been visited
* @return the annotation if found, or {@code null} if not found
*/
private static <A extends Annotation> A findAnnotation(Class<?> clazz, Class<A> annotationType,
Set<Annotation> visited) {
private static <A extends Annotation> A findAnnotation(Class<?> clazz, Class<A> annotationType, Set<Annotation> visited) {
Assert.notNull(clazz, "Class must not be null");
if (isAnnotationDeclaredLocally(annotationType, clazz)) {
return clazz.getAnnotation(annotationType);
}
@ -426,7 +424,6 @@ public abstract class AnnotationUtils {
/**
* Determine if the supplied {@link Annotation} is defined in the
* {@code java.lang.annotation} package.
*
* @param annotation the annotation to check; never {@code null}
* @return {@code true} if the annotation is in the {@code java.lang.annotation} package
*/

View File

@ -77,9 +77,8 @@ public abstract class PropertySource<T> {
/**
* Create a new {@code PropertySource} with the given name and with a new {@code Object}
* instance as the underlying source.
* <p>Often useful in testing scenarios when creating
* anonymous implementations that never query an actual source, but rather return
* hard-coded values.
* <p>Often useful in testing scenarios when creating anonymous implementations that
* never query an actual source but rather return hard-coded values.
*/
@SuppressWarnings("unchecked")
public PropertySource(String name) {
@ -103,9 +102,9 @@ public abstract class PropertySource<T> {
/**
* Return whether this {@code PropertySource} contains the given name.
* <p>This implementation simply checks for a null return value
* from {@link #getProperty(String)}. Subclasses may wish to
* implement a more efficient algorithm if possible.
* <p>This implementation simply checks for a {@code null} return value
* from {@link #getProperty(String)}. Subclasses may wish to implement
* a more efficient algorithm if possible.
* @param name the property name to find
*/
public boolean containsProperty(String name) {
@ -146,7 +145,7 @@ public abstract class PropertySource<T> {
/**
* Produce concise output (type and name) if the current log level does not include
* debug. If debug is enabled, produce verbose output including hash code of the
* debug. If debug is enabled, produce verbose output including the hash code of the
* PropertySource instance and every name/value property pair.
* <p>This variable verbosity is useful as a property source such as system properties
* or environment variables may contain an arbitrary number of property pairs,
@ -221,8 +220,7 @@ public abstract class PropertySource<T> {
static class ComparisonPropertySource extends StubPropertySource {
private static final String USAGE_ERROR =
"ComparisonPropertySource instances are for collection comparison " +
"use only";
"ComparisonPropertySource instances are for use with collection comparison only";
public ComparisonPropertySource(String name) {
super(name);