Polish spring-context

- Cache interceptor internals now operate on collections of
   <? extends Cache> instead of <Cache>.
 - Deleted unused imports.
 - Deleted dead code.
 - Suppressed warnings for resource leaks related to not closing
   ApplicationContexts in tests.
 - Suppressed further non-issue warnings in tests.
This commit is contained in:
Sam Brannen
2013-11-11 12:09:50 +01:00
parent 5915b23e8a
commit d67fe1db86
27 changed files with 36 additions and 83 deletions

View File

@@ -37,21 +37,17 @@ import org.springframework.context.support.ClassPathXmlApplicationContext;
public final class BeanNamePointcutAtAspectTests {
private ITestBean testBean1;
private ITestBean testBean2;
private ITestBean testBean3;
private CounterAspect counterAspect;
@org.junit.Before
@SuppressWarnings("resource")
public void setUp() {
ClassPathXmlApplicationContext ctx =
new ClassPathXmlApplicationContext(getClass().getSimpleName() + ".xml", getClass());
counterAspect = (CounterAspect) ctx.getBean("counterAspect");
testBean1 = (ITestBean) ctx.getBean("testBean1");
testBean2 = (ITestBean) ctx.getBean("testBean2");
testBean3 = (ITestBean) ctx.getBean("testBean3");
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2013 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.
@@ -38,6 +38,7 @@ public final class DeclarationOrderIndependenceTests {
@Before
@SuppressWarnings("resource")
public void setUp() {
ClassPathXmlApplicationContext ctx =
new ClassPathXmlApplicationContext(getClass().getSimpleName() + ".xml", getClass());
@@ -83,11 +84,9 @@ public final class DeclarationOrderIndependenceTests {
/** public visibility is required */
public static class BeanNameAwareMixin implements BeanNameAware {
@SuppressWarnings("unused")
private String beanName;
/* (non-Javadoc)
* @see org.springframework.beans.factory.BeanNameAware#setBeanName(java.lang.String)
*/
@Override
public void setBeanName(String name) {
this.beanName = name;
@@ -146,17 +145,11 @@ class TopsyTurvyTargetImpl implements TopsyTurvyTarget {
private int x = 5;
/* (non-Javadoc)
* @see org.springframework.aop.aspectj.TopsyTurvyTarget#doSomething()
*/
@Override
public void doSomething() {
this.x = 10;
}
/* (non-Javadoc)
* @see org.springframework.aop.aspectj.TopsyTurvyTarget#getX()
*/
@Override
public int getX() {
return x;
@@ -171,25 +164,16 @@ class AspectCollaborator implements TopsyTurvyAspect.Collaborator {
public boolean aroundFired = false;
public boolean beforeFired = false;
/* (non-Javadoc)
* @see org.springframework.aop.aspectj.TopsyTurvyAspect.Collaborator#afterReturningAdviceFired()
*/
@Override
public void afterReturningAdviceFired() {
this.afterReturningFired = true;
}
/* (non-Javadoc)
* @see org.springframework.aop.aspectj.TopsyTurvyAspect.Collaborator#aroundAdviceFired()
*/
@Override
public void aroundAdviceFired() {
this.aroundFired = true;
}
/* (non-Javadoc)
* @see org.springframework.aop.aspectj.TopsyTurvyAspect.Collaborator#beforeAdviceFired()
*/
@Override
public void beforeAdviceFired() {
this.beforeFired = true;

View File

@@ -39,8 +39,6 @@ public final class DeclareParentsTests {
private ITestBean testBeanProxy;
private TestBean testBeanTarget;
private ApplicationContext ctx;
@Before
@@ -49,9 +47,6 @@ public final class DeclareParentsTests {
testBeanProxy = (ITestBean) ctx.getBean("testBean");
assertTrue(AopUtils.isAopProxy(testBeanProxy));
// we need the real target too, not just the proxy...
testBeanTarget = (TestBean) ((Advised) testBeanProxy).getTargetSource().getTarget();
}
@Test

View File

@@ -1776,7 +1776,6 @@ public abstract class AbstractAopProxyTests {
protected static class TestStaticPointcutAdvice extends StaticMethodMatcherPointcutAdvisor {
private String pattern;
private int count;
public TestStaticPointcutAdvice(MethodInterceptor mi, String pattern) {
super(mi);
@@ -1784,9 +1783,7 @@ public abstract class AbstractAopProxyTests {
}
@Override
public boolean matches(Method m, Class<?> targetClass) {
boolean run = m.getName().indexOf(pattern) != -1;
if (run) ++count;
return run;
return m.getName().indexOf(pattern) != -1;
}
}

View File

@@ -49,6 +49,7 @@ import test.mixin.Lockable;
* @author Dave Syer
* @author Chris Beams
*/
@SuppressWarnings("resource")
public final class AdvisorAutoProxyCreatorTests {
private static final Class<?> CLASS = AdvisorAutoProxyCreatorTests.class;
@@ -60,9 +61,6 @@ public final class AdvisorAutoProxyCreatorTests {
private static final String QUICK_TARGETSOURCE_CONTEXT = CLASSNAME + "-quick-targetsource.xml";
private static final String OPTIMIZED_CONTEXT = CLASSNAME + "-optimized.xml";
private static final String ADVISOR_APC_BEAN_NAME = "aapc";
private static final String TXMANAGER_BEAN_NAME = "txManager";
/**
* Return a bean factory with attributes and EnterpriseServices configured.
*/

View File

@@ -24,7 +24,6 @@ import java.util.Iterator;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.springframework.cache.annotation.AnnotationCacheOperationSource;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.cache.annotation.Caching;
@@ -39,6 +38,7 @@ import static org.junit.Assert.*;
/**
* @author Costin Leau
* @author Phillip Webb
* @author Sam Brannen
*/
public class ExpressionEvaluatorTests {
@@ -70,13 +70,12 @@ public class ExpressionEvaluatorTests {
}
@Test
@SuppressWarnings("unchecked")
public void testMultipleCachingEval() throws Exception {
AnnotatedClass target = new AnnotatedClass();
Method method = ReflectionUtils.findMethod(AnnotatedClass.class, "multipleCaching", Object.class,
Object.class);
Object[] args = new Object[] { new Object(), new Object() };
Collection caches = Collections.singleton(new ConcurrentMapCache("test"));
Collection<ConcurrentMapCache> caches = Collections.singleton(new ConcurrentMapCache("test"));
EvaluationContext evalCtx = eval.createEvaluationContext(caches, method, args, target, target.getClass());
Collection<CacheOperation> ops = getOps("multipleCaching");
@@ -116,8 +115,7 @@ public class ExpressionEvaluatorTests {
Method method = ReflectionUtils.findMethod(AnnotatedClass.class, "multipleCaching", Object.class,
Object.class);
Object[] args = new Object[] { new Object(), new Object() };
@SuppressWarnings("unchecked")
Collection caches = Collections.singleton(new ConcurrentMapCache("test"));
Collection<ConcurrentMapCache> caches = Collections.singleton(new ConcurrentMapCache("test"));
EvaluationContext context = eval.createEvaluationContext(caches, method, args, target, target.getClass(), result);
return context;
}

View File

@@ -20,9 +20,6 @@ import java.util.List;
import org.junit.Test;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.support.RootBeanDefinition;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;
@@ -34,6 +31,7 @@ import static org.junit.Assert.*;
* @author Phillip Webb
* @author Juergen Hoeller
*/
@SuppressWarnings("resource")
public class BeanMethodPolymorphismTests {
@Test

View File

@@ -120,8 +120,8 @@ public class ConfigurationClassPostProcessorTests {
beanFactory.registerBeanDefinition("config", new RootBeanDefinition(SingletonBeanConfig.class));
ConfigurationClassPostProcessor pp = new ConfigurationClassPostProcessor();
pp.postProcessBeanFactory(beanFactory);
Foo foo = beanFactory.getBean("foo", Foo.class);
TestBean bar = beanFactory.getBean("bar", TestBean.class);
beanFactory.getBean("foo", Foo.class);
beanFactory.getBean("bar", TestBean.class);
}
@Test

View File

@@ -19,10 +19,8 @@ package org.springframework.context.annotation;
import java.util.Map;
import org.junit.Test;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.config.InstantiationAwareBeanPostProcessorAdapter;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.support.RootBeanDefinition;
import static org.hamcrest.CoreMatchers.*;
@@ -39,6 +37,7 @@ import static org.junit.Assert.*;
* @author Chris Beams
* @author Oliver Gierke
*/
@SuppressWarnings("resource")
public class ConfigurationClassSpr8954Tests {
@Test

View File

@@ -25,6 +25,7 @@ import org.springframework.core.convert.converter.Converter;
*/
public class FooServiceDependentConverter implements Converter<String, org.springframework.tests.sample.beans.TestBean> {
@SuppressWarnings("unused")
private FooService fooService;
public void setFooService(FooService fooService) {

View File

@@ -23,7 +23,6 @@ import static org.junit.Assert.assertThat;
import java.lang.reflect.Method;
import org.junit.Test;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.util.ReflectionUtils;
/**

View File

@@ -25,15 +25,12 @@ import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.junit.Test;
import org.springframework.stereotype.Service;
import org.springframework.tests.sample.beans.TestBean;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import static org.junit.Assert.*;
/**
* Tests that @Import may be used both as a locally declared and meta-declared
* annotation, that all declarations are processed, and that any local declaration
@@ -42,6 +39,7 @@ import static org.junit.Assert.*;
* @author Chris Beams
* @since 3.1
*/
@SuppressWarnings("resource")
public class ImportAnnotationDetectionTests {
@Test

View File

@@ -21,6 +21,7 @@ package org.springframework.context.support;
*/
public class Assembler implements TestIF {
@SuppressWarnings("unused")
private Service service;
private Logic l;
private String name;

View File

@@ -69,7 +69,6 @@ public final class ClassPathXmlApplicationContextTests {
private static final String ALIAS_THAT_OVERRIDES_PARENT_CONTEXT = PATH + "aliasThatOverridesParent.xml";
private static final String ALIAS_FOR_PARENT_CONTEXT = PATH + "aliasForParent.xml";
private static final String TEST_PROPERTIES = "test.properties";
private static final String FQ_TEST_PROPERTIES = "classpath:org/springframework/beans/factory/xml/" + TEST_PROPERTIES;
@Test

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2013 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.
@@ -16,24 +16,20 @@
package org.springframework.context.support;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.BeanNameAware;
public class Logic implements BeanNameAware {
private Log log = LogFactory.getLog(Logic.class);
private String name;
@SuppressWarnings("unused")
private Assembler a;
public void setAssembler(Assembler a) {
this.a = a;
}
/* (non-Javadoc)
* @see org.springframework.beans.factory.BeanNameAware#setBeanName(java.lang.String)
*/
@Override
public void setBeanName(String name) {
this.name = name;

View File

@@ -292,7 +292,6 @@ public class DateTimeFormattingTests {
}
@SuppressWarnings("unused")
public static class DateTimeBean {
private LocalDate localDate;

View File

@@ -22,10 +22,10 @@ import java.util.Map;
import groovy.lang.DelegatingMetaClass;
import groovy.lang.GroovyObject;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.springframework.aop.support.AopUtils;
import org.springframework.aop.target.dynamic.Refreshable;
import org.springframework.beans.factory.BeanCreationException;
@@ -61,6 +61,7 @@ import static org.mockito.BDDMockito.*;
* @author Mark Fisher
* @author Chris Beams
*/
@SuppressWarnings("resource")
public class GroovyScriptFactoryTests {
@Before