Polishing

This commit is contained in:
Juergen Hoeller 2017-02-22 16:32:21 +01:00
parent a48a956c0c
commit c734c3a3fe
6 changed files with 59 additions and 64 deletions

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.
@ -214,7 +214,7 @@ class CglibAopProxy implements AopProxy, Serializable {
"Common causes of this problem include using a final class or a non-visible class",
ex);
}
catch (Exception ex) {
catch (Throwable ex) {
// TargetSource.getTarget() failed
throw new AopConfigException("Unexpected AOP exception", ex);
}
@ -256,7 +256,7 @@ class CglibAopProxy implements AopProxy, Serializable {
* methods across ClassLoaders, and writes warnings to the log for each one found.
*/
private void doValidateClass(Class<?> proxySuperClass, ClassLoader proxyClassLoader) {
if (Object.class != proxySuperClass) {
if (proxySuperClass != Object.class) {
Method[] methods = proxySuperClass.getDeclaredMethods();
for (Method method : methods) {
int mod = method.getModifiers();

View File

@ -66,18 +66,17 @@ import static org.junit.Assert.*;
*/
public class ConfigurationClassPostProcessorTests {
private DefaultListableBeanFactory beanFactory;
private final DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
@Before
public void setUp() {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
public void setup() {
QualifierAnnotationAutowireCandidateResolver acr = new QualifierAnnotationAutowireCandidateResolver();
acr.setBeanFactory(bf);
bf.setAutowireCandidateResolver(acr);
this.beanFactory = bf;
acr.setBeanFactory(this.beanFactory);
this.beanFactory.setAutowireCandidateResolver(acr);
}
/**
* Enhanced {@link Configuration} classes are only necessary for respecting
* certain bean semantics, like singleton-scoping, scoped proxies, etc.
@ -950,7 +949,6 @@ public class ConfigurationClassPostProcessorTests {
}
}
@Configuration
public static class RawRepositoryConfiguration {

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2013 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.
@ -22,11 +22,11 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.junit.After;
import org.junit.Test;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.context.ApplicationContext;
import org.springframework.core.type.AnnotatedTypeMetadata;
import org.springframework.core.type.AnnotationMetadata;
import org.springframework.util.Assert;
@ -38,24 +38,15 @@ import static org.junit.Assert.*;
*/
public class Spr11202Tests {
private AnnotationConfigApplicationContext context;
@After
public void close() {
if (context != null) {
context.close();
}
}
@Test // Fails
@Test
public void testWithImporter() {
context = new AnnotationConfigApplicationContext(Wrapper.class);
ApplicationContext context = new AnnotationConfigApplicationContext(Wrapper.class);
assertEquals("foo", context.getBean("value"));
}
@Test // Passes
@Test
public void testWithoutImporter() {
context = new AnnotationConfigApplicationContext(Config.class);
ApplicationContext context = new AnnotationConfigApplicationContext(Config.class);
assertEquals("foo", context.getBean("value"));
}
@ -65,6 +56,7 @@ public class Spr11202Tests {
protected static class Wrapper {
}
protected static class Selector implements ImportSelector {
@Override
@ -73,6 +65,7 @@ public class Spr11202Tests {
}
}
@Configuration
protected static class Config {
@ -95,6 +88,7 @@ public class Spr11202Tests {
}
}
protected static class NoBarCondition implements Condition {
@Override
@ -106,12 +100,14 @@ public class Spr11202Tests {
}
}
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Target(ElementType.TYPE)
protected static @interface Bar {
protected @interface Bar {
}
protected static class FooFactoryBean implements FactoryBean<Foo>, InitializingBean {
private Foo foo = new Foo();
@ -137,6 +133,7 @@ public class Spr11202Tests {
}
}
protected static class Foo {
private String name;

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 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.
@ -32,6 +32,7 @@ import static org.junit.Assert.*;
* @author Chris Beams
*/
public class Spr6602Tests {
@Test
public void testXmlBehavior() throws Exception {
doAssertions(new ClassPathXmlApplicationContext("Spr6602Tests-context.xml", Spr6602Tests.class));
@ -59,8 +60,10 @@ public class Spr6602Tests {
assertThat(bar3, is(not(bar4)));
}
@Configuration
public static class FooConfig {
@Bean
public Foo foo() throws Exception {
return new Foo(barFactory().getObject());
@ -72,7 +75,9 @@ public class Spr6602Tests {
}
}
public static class Foo {
final Bar bar;
public Foo(Bar bar) {
@ -80,9 +85,11 @@ public class Spr6602Tests {
}
}
public static class Bar {
}
public static class BarFactory implements FactoryBean<Bar> {
@Override
@ -102,4 +109,4 @@ public class Spr6602Tests {
}
}
}

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.
@ -63,8 +63,8 @@ import org.springframework.tests.sample.beans.TestBean;
import static org.junit.Assert.*;
/**
* Miscellaneous system tests covering {@link Bean} naming, aliases, scoping and error
* handling within {@link Configuration} class definitions.
* Miscellaneous system tests covering {@link Bean} naming, aliases, scoping and
* error handling within {@link Configuration} class definitions.
*
* @author Chris Beams
* @author Juergen Hoeller
@ -72,30 +72,6 @@ import static org.junit.Assert.*;
*/
public class ConfigurationClassProcessingTests {
/**
* Creates a new {@link BeanFactory}, populates it with a {@link BeanDefinition} for
* each of the given {@link Configuration} <var>configClasses</var>, and then
* post-processes the factory using JavaConfig's {@link ConfigurationClassPostProcessor}.
* When complete, the factory is ready to service requests for any {@link Bean} methods
* declared by <var>configClasses</var>.
*/
private DefaultListableBeanFactory initBeanFactory(Class<?>... configClasses) {
DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
for (Class<?> configClass : configClasses) {
String configBeanName = configClass.getName();
factory.registerBeanDefinition(configBeanName, new RootBeanDefinition(configClass));
}
ConfigurationClassPostProcessor ccpp = new ConfigurationClassPostProcessor();
ccpp.postProcessBeanDefinitionRegistry(factory);
ccpp.postProcessBeanFactory(factory);
RequiredAnnotationBeanPostProcessor rapp = new RequiredAnnotationBeanPostProcessor();
rapp.setBeanFactory(factory);
factory.addBeanPostProcessor(rapp);
factory.freezeConfiguration();
return factory;
}
@Rule
public final ExpectedException exception = ExpectedException.none();
@ -267,6 +243,30 @@ public class ConfigurationClassProcessingTests {
}
/**
* Creates a new {@link BeanFactory}, populates it with a {@link BeanDefinition}
* for each of the given {@link Configuration} {@code configClasses}, and then
* post-processes the factory using JavaConfig's {@link ConfigurationClassPostProcessor}.
* When complete, the factory is ready to service requests for any {@link Bean} methods
* declared by {@code configClasses}.
*/
private DefaultListableBeanFactory initBeanFactory(Class<?>... configClasses) {
DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
for (Class<?> configClass : configClasses) {
String configBeanName = configClass.getName();
factory.registerBeanDefinition(configBeanName, new RootBeanDefinition(configClass));
}
ConfigurationClassPostProcessor ccpp = new ConfigurationClassPostProcessor();
ccpp.postProcessBeanDefinitionRegistry(factory);
ccpp.postProcessBeanFactory(factory);
RequiredAnnotationBeanPostProcessor rapp = new RequiredAnnotationBeanPostProcessor();
rapp.setBeanFactory(factory);
factory.addBeanPostProcessor(rapp);
factory.freezeConfiguration();
return factory;
}
@Configuration
static class ConfigWithBeanWithCustomName {

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.
@ -1543,14 +1543,8 @@ public class AnnotationUtilsTests {
assertArrayEquals(new char[] { 'x', 'y', 'z' }, chars);
}
@SafeVarargs
// The following "varargs" suppression is necessary for javac from OpenJDK
// (1.8.0_60-b27); however, Eclipse warns that it's unnecessary. See the following
// Eclipse issues for details.
//
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=344783
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=349669#c10
// @SuppressWarnings("varargs")
static <T> T[] asArray(T... arr) {
return arr;
}
@ -1996,7 +1990,6 @@ public class AnnotationUtilsTests {
static class GroupOfCharsClass {
}
@Retention(RetentionPolicy.RUNTIME)
@interface AliasForWithMissingAttributeDeclaration {