diff --git a/spring-aop/src/main/java/org/springframework/aop/framework/adapter/GlobalAdvisorAdapterRegistry.java b/spring-aop/src/main/java/org/springframework/aop/framework/adapter/GlobalAdvisorAdapterRegistry.java index 6662c3411b..0cd2d7ef9d 100644 --- a/spring-aop/src/main/java/org/springframework/aop/framework/adapter/GlobalAdvisorAdapterRegistry.java +++ b/spring-aop/src/main/java/org/springframework/aop/framework/adapter/GlobalAdvisorAdapterRegistry.java @@ -1,12 +1,12 @@ /* - * Copyright 2002-2005 the original author or authors. - * + * Copyright 2002-2012 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. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -21,6 +21,7 @@ package org.springframework.aop.framework.adapter; * * @author Rod Johnson * @author Juergen Hoeller + * @author Phillip Webb * @see DefaultAdvisorAdapterRegistry */ public abstract class GlobalAdvisorAdapterRegistry { @@ -28,13 +29,22 @@ public abstract class GlobalAdvisorAdapterRegistry { /** * Keep track of a single instance so we can return it to classes that request it. */ - private static final AdvisorAdapterRegistry instance = new DefaultAdvisorAdapterRegistry(); - + private static AdvisorAdapterRegistry instance = new DefaultAdvisorAdapterRegistry(); + /** - * Return the singleton DefaultAdvisorAdapterRegistry instance. + * Return the singleton {@link DefaultAdvisorAdapterRegistry} instance. */ public static AdvisorAdapterRegistry getInstance() { return instance; } + /** + * Reset the singleton {@link DefaultAdvisorAdapterRegistry}, removing any + * {@link AdvisorAdapterRegistry#registerAdvisorAdapter(AdvisorAdapter) registered} + * adapters. + */ + static void reset() { + instance = new DefaultAdvisorAdapterRegistry(); + } + } diff --git a/spring-context/src/test/java/org/springframework/aop/framework/adapter/AdvisorAdapterRegistrationTests.java b/spring-context/src/test/java/org/springframework/aop/framework/adapter/AdvisorAdapterRegistrationTests.java index a916a3baec..39dc7410b8 100644 --- a/spring-context/src/test/java/org/springframework/aop/framework/adapter/AdvisorAdapterRegistrationTests.java +++ b/spring-context/src/test/java/org/springframework/aop/framework/adapter/AdvisorAdapterRegistrationTests.java @@ -1,12 +1,12 @@ /* - * Copyright 2002-2005 the original author or authors. - * + * Copyright 2002-2012 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. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -23,6 +23,8 @@ import java.io.Serializable; import org.aopalliance.aop.Advice; import org.aopalliance.intercept.MethodInterceptor; import org.aopalliance.intercept.MethodInvocation; +import org.junit.After; +import org.junit.Before; import org.junit.Test; import org.springframework.aop.Advisor; import org.springframework.aop.BeforeAdvice; @@ -38,6 +40,12 @@ import org.springframework.context.support.ClassPathXmlApplicationContext; */ public final class AdvisorAdapterRegistrationTests { + @Before + @After + public void resetGlobalAdvisorAdapterRegistry() { + GlobalAdvisorAdapterRegistry.reset(); + } + @Test public void testAdvisorAdapterRegistrationManagerNotPresentInContext() { ClassPathXmlApplicationContext ctx = @@ -101,7 +109,7 @@ class SimpleBeforeAdviceAdapter implements AdvisorAdapter, Serializable { class SimpleBeforeAdviceImpl implements SimpleBeforeAdvice { - + private int invocationCounter; public void before() throws Throwable { @@ -116,9 +124,9 @@ class SimpleBeforeAdviceImpl implements SimpleBeforeAdvice { final class SimpleBeforeAdviceInterceptor implements MethodInterceptor { - + private SimpleBeforeAdvice advice; - + public SimpleBeforeAdviceInterceptor(SimpleBeforeAdvice advice) { this.advice = advice; } @@ -127,5 +135,4 @@ final class SimpleBeforeAdviceInterceptor implements MethodInterceptor { advice.before(); return mi.proceed(); } - -} \ No newline at end of file +} diff --git a/spring-test/src/test/java/org/springframework/test/context/junit4/spr9051/AnnotatedConfigClassesWithoutAtConfigurationTests.java b/spring-test/src/test/java/org/springframework/test/context/junit4/spr9051/AnnotatedConfigClassesWithoutAtConfigurationTests.java index 9548cb6496..58a3df2a63 100644 --- a/spring-test/src/test/java/org/springframework/test/context/junit4/spr9051/AnnotatedConfigClassesWithoutAtConfigurationTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/junit4/spr9051/AnnotatedConfigClassesWithoutAtConfigurationTests.java @@ -16,11 +16,13 @@ package org.springframework.test.context.junit4.spr9051; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; +import static org.hamcrest.Matchers.*; +import static org.hamcrest.Matchers.is; +import static org.junit.Assert.*; +import java.util.Arrays; +import java.util.HashSet; +import java.util.Set; import java.util.concurrent.atomic.AtomicInteger; import org.junit.Test; @@ -30,22 +32,24 @@ import org.springframework.context.annotation.Bean; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + /** * This set of tests refutes the claims made in * SPR-9051. - * + * *
The Claims: - * + * *
* When a {@code @ContextConfiguration} test class references a config class * missing an {@code @Configuration} annotation, {@code @Bean} dependencies are * wired successfully but the bean lifecycle is not applied (no init methods are * invoked, for example). Adding the missing {@code @Configuration} annotation - * solves the problem, however the problem and solution isn't obvious since + * solves the problem, however the problem and solution isn't obvious since * wiring/injection appeared to work. *- * + * * @author Sam Brannen + * @author Phillip Webb * @since 3.2 */ @RunWith(SpringJUnit4ClassRunner.class) @@ -85,18 +89,14 @@ public class AnnotatedConfigClassesWithoutAtConfigurationTests { @Autowired private LifecycleBean lifecycleBean; - @Test - public void simpleStringBean() { + public void testSPR_9051() throws Exception { assertNotNull(enigma); - assertEquals("enigma #1", enigma); - } - - @Test - public void beanWithLifecycleCallback() { assertNotNull(lifecycleBean); - assertEquals("enigma #2", lifecycleBean.getName()); assertTrue(lifecycleBean.isInitialized()); + Set