From 1fd6248d84ab33e16bf7221583028a5bad3ab0a6 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Fri, 27 Jul 2018 17:46:21 +0200 Subject: [PATCH] Polishing --- .../PropertiesBeanDefinitionReaderTests.java | 17 +++++++------- .../aop/aspectj/AfterAdviceBindingTests.java | 6 +++-- .../AfterReturningAdviceBindingTests.java | 10 +++----- .../AfterThrowingAdviceBindingTests.java | 9 ++++---- .../AspectAndAdvicePrecedenceTests.java | 5 ++-- ...AspectJExpressionPointcutAdvisorTests.java | 6 +++-- .../BeanNamePointcutAtAspectTests.java | 6 ++--- .../aop/aspectj/BeanNamePointcutTests.java | 4 ++-- .../aop/aspectj/BeforeAdviceBindingTests.java | 9 +++----- .../DeclarationOrderIndependenceTests.java | 15 +++++------- .../DeclareParentsDelegateRefTests.java | 7 +++--- .../aop/aspectj/DeclareParentsTests.java | 23 ++++++++----------- .../aop/aspectj/ProceedTests.java | 7 +++--- .../SharedPointcutWithArgsMismatchTests.java | 9 ++++---- .../SubtypeSensitiveMatchingTests.java | 12 ++++++++-- .../aspectj/TargetPointcutSelectionTests.java | 7 ++---- ...tSelectionOnlyPointcutsAtAspectJTests.java | 10 ++++---- ...sAndTargetSelectionOnlyPointcutsTests.java | 10 ++++---- .../autoproxy/AnnotationBindingTests.java | 4 ++-- .../AtAspectJAnnotationBindingTests.java | 4 ++-- ...fterReturningGenericTypeMatchingTests.java | 7 +++--- .../GenericBridgeMethodMatchingTests.java | 6 ++--- .../GenericParameterMatchingTests.java | 6 ++--- 23 files changed, 97 insertions(+), 102 deletions(-) diff --git a/spring-beans/src/test/java/org/springframework/beans/factory/support/PropertiesBeanDefinitionReaderTests.java b/spring-beans/src/test/java/org/springframework/beans/factory/support/PropertiesBeanDefinitionReaderTests.java index f8dbf4c1dbc..2479b0177d7 100644 --- a/spring-beans/src/test/java/org/springframework/beans/factory/support/PropertiesBeanDefinitionReaderTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/factory/support/PropertiesBeanDefinitionReaderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2015 the original author or authors. + * Copyright 2002-2018 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. @@ -30,29 +30,28 @@ public class PropertiesBeanDefinitionReaderTests { private final DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory(); - private final PropertiesBeanDefinitionReader reader = new PropertiesBeanDefinitionReader( - beanFactory); + private final PropertiesBeanDefinitionReader reader = new PropertiesBeanDefinitionReader(this.beanFactory); @Test public void withSimpleConstructorArg() { this.reader.loadBeanDefinitions(new ClassPathResource("simpleConstructorArg.properties", getClass())); - TestBean bean = (TestBean)this.beanFactory.getBean("testBean"); + TestBean bean = (TestBean) this.beanFactory.getBean("testBean"); assertEquals("Rob Harrop", bean.getName()); } @Test - public void withConstructorArgRef() throws Exception { + public void withConstructorArgRef() { this.reader.loadBeanDefinitions(new ClassPathResource("refConstructorArg.properties", getClass())); - TestBean rob = (TestBean)this.beanFactory.getBean("rob"); - TestBean sally = (TestBean)this.beanFactory.getBean("sally"); + TestBean rob = (TestBean) this.beanFactory.getBean("rob"); + TestBean sally = (TestBean) this.beanFactory.getBean("sally"); assertEquals(sally, rob.getSpouse()); } @Test - public void withMultipleConstructorsArgs() throws Exception { + public void withMultipleConstructorsArgs() { this.reader.loadBeanDefinitions(new ClassPathResource("multiConstructorArgs.properties", getClass())); - TestBean bean = (TestBean)this.beanFactory.getBean("testBean"); + TestBean bean = (TestBean) this.beanFactory.getBean("testBean"); assertEquals("Rob Harrop", bean.getName()); assertEquals(23, bean.getAge()); } diff --git a/spring-context/src/test/java/org/springframework/aop/aspectj/AfterAdviceBindingTests.java b/spring-context/src/test/java/org/springframework/aop/aspectj/AfterAdviceBindingTests.java index bbf0dfcb8a0..e52d19e5250 100644 --- a/spring-context/src/test/java/org/springframework/aop/aspectj/AfterAdviceBindingTests.java +++ b/spring-context/src/test/java/org/springframework/aop/aspectj/AfterAdviceBindingTests.java @@ -44,10 +44,11 @@ public class AfterAdviceBindingTests { private TestBean testBeanTarget; + @Before - public void setUp() throws Exception { + public void setup() throws Exception { ClassPathXmlApplicationContext ctx = - new ClassPathXmlApplicationContext(getClass().getSimpleName() + ".xml", getClass()); + new ClassPathXmlApplicationContext(getClass().getSimpleName() + ".xml", getClass()); AdviceBindingTestAspect afterAdviceAspect = (AdviceBindingTestAspect) ctx.getBean("testAspect"); testBeanProxy = (ITestBean) ctx.getBean("testBean"); @@ -60,6 +61,7 @@ public class AfterAdviceBindingTests { afterAdviceAspect.setCollaborator(mockCollaborator); } + @Test public void testOneIntArg() { testBeanProxy.setAge(5); diff --git a/spring-context/src/test/java/org/springframework/aop/aspectj/AfterReturningAdviceBindingTests.java b/spring-context/src/test/java/org/springframework/aop/aspectj/AfterReturningAdviceBindingTests.java index d811a87994b..cd410db92ac 100644 --- a/spring-context/src/test/java/org/springframework/aop/aspectj/AfterReturningAdviceBindingTests.java +++ b/spring-context/src/test/java/org/springframework/aop/aspectj/AfterReturningAdviceBindingTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2018 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. @@ -48,14 +48,10 @@ public class AfterReturningAdviceBindingTests { private AfterReturningAdviceBindingCollaborator mockCollaborator; - public void setAfterReturningAdviceAspect(AfterReturningAdviceBindingTestAspect anAspect) { - this.afterAdviceAspect = anAspect; - } - @Before - public void setUp() throws Exception { + public void setup() throws Exception { ClassPathXmlApplicationContext ctx = - new ClassPathXmlApplicationContext(getClass().getSimpleName() + ".xml", getClass()); + new ClassPathXmlApplicationContext(getClass().getSimpleName() + ".xml", getClass()); afterAdviceAspect = (AfterReturningAdviceBindingTestAspect) ctx.getBean("testAspect"); diff --git a/spring-context/src/test/java/org/springframework/aop/aspectj/AfterThrowingAdviceBindingTests.java b/spring-context/src/test/java/org/springframework/aop/aspectj/AfterThrowingAdviceBindingTests.java index 997162274f8..4526dd89d9e 100644 --- a/spring-context/src/test/java/org/springframework/aop/aspectj/AfterThrowingAdviceBindingTests.java +++ b/spring-context/src/test/java/org/springframework/aop/aspectj/AfterThrowingAdviceBindingTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2018 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. @@ -39,10 +39,11 @@ public class AfterThrowingAdviceBindingTests { private AfterThrowingAdviceBindingCollaborator mockCollaborator; + @Before - public void setUp() { + public void setup() { ClassPathXmlApplicationContext ctx = - new ClassPathXmlApplicationContext(getClass().getSimpleName() + ".xml", getClass()); + new ClassPathXmlApplicationContext(getClass().getSimpleName() + ".xml", getClass()); testBean = (ITestBean) ctx.getBean("testBean"); afterThrowingAdviceAspect = (AfterThrowingAdviceBindingTestAspect) ctx.getBean("testAspect"); @@ -51,6 +52,7 @@ public class AfterThrowingAdviceBindingTests { afterThrowingAdviceAspect.setCollaborator(mockCollaborator); } + @Test(expected = Throwable.class) public void testSimpleAfterThrowing() throws Throwable { this.testBean.exceptional(new Throwable()); @@ -132,5 +134,4 @@ final class AfterThrowingAdviceBindingTestAspect { public void noArgsOnRuntimeExceptionMatch() { this.collaborator.noArgsOnRuntimeExceptionMatch(); } - } diff --git a/spring-context/src/test/java/org/springframework/aop/aspectj/AspectAndAdvicePrecedenceTests.java b/spring-context/src/test/java/org/springframework/aop/aspectj/AspectAndAdvicePrecedenceTests.java index 7e844c9bc71..a58178c5ea0 100644 --- a/spring-context/src/test/java/org/springframework/aop/aspectj/AspectAndAdvicePrecedenceTests.java +++ b/spring-context/src/test/java/org/springframework/aop/aspectj/AspectAndAdvicePrecedenceTests.java @@ -49,9 +49,9 @@ public class AspectAndAdvicePrecedenceTests { @Before - public void setUp() { + public void setup() { ClassPathXmlApplicationContext ctx = - new ClassPathXmlApplicationContext(getClass().getSimpleName() + ".xml", getClass()); + new ClassPathXmlApplicationContext(getClass().getSimpleName() + ".xml", getClass()); highPrecedenceAspect = (PrecedenceTestAspect) ctx.getBean("highPrecedenceAspect"); lowPrecedenceAspect = (PrecedenceTestAspect) ctx.getBean("lowPrecedenceAspect"); highPrecedenceSpringAdvice = (SimpleSpringBeforeAdvice) ctx.getBean("highPrecedenceSpringAdvice"); @@ -59,7 +59,6 @@ public class AspectAndAdvicePrecedenceTests { testBean = (ITestBean) ctx.getBean("testBean"); } - // ========== end of test case set up, start of tests proper =================== @Test public void testAdviceOrder() { diff --git a/spring-context/src/test/java/org/springframework/aop/aspectj/AspectJExpressionPointcutAdvisorTests.java b/spring-context/src/test/java/org/springframework/aop/aspectj/AspectJExpressionPointcutAdvisorTests.java index 57b1794044c..c925b59223e 100644 --- a/spring-context/src/test/java/org/springframework/aop/aspectj/AspectJExpressionPointcutAdvisorTests.java +++ b/spring-context/src/test/java/org/springframework/aop/aspectj/AspectJExpressionPointcutAdvisorTests.java @@ -37,14 +37,16 @@ public class AspectJExpressionPointcutAdvisorTests { private CallCountingInterceptor interceptor; + @Before - public void setUp() { + public void setup() { ClassPathXmlApplicationContext ctx = - new ClassPathXmlApplicationContext(getClass().getSimpleName() + ".xml", getClass()); + new ClassPathXmlApplicationContext(getClass().getSimpleName() + ".xml", getClass()); testBean = (ITestBean) ctx.getBean("testBean"); interceptor = (CallCountingInterceptor) ctx.getBean("interceptor"); } + @Test public void testPointcutting() { assertEquals("Count should be 0", 0, interceptor.getCount()); diff --git a/spring-context/src/test/java/org/springframework/aop/aspectj/BeanNamePointcutAtAspectTests.java b/spring-context/src/test/java/org/springframework/aop/aspectj/BeanNamePointcutAtAspectTests.java index 1c8573390a4..8e9e6ee4961 100644 --- a/spring-context/src/test/java/org/springframework/aop/aspectj/BeanNamePointcutAtAspectTests.java +++ b/spring-context/src/test/java/org/springframework/aop/aspectj/BeanNamePointcutAtAspectTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2015 the original author or authors. + * Copyright 2002-2018 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. @@ -45,8 +45,7 @@ public class BeanNamePointcutAtAspectTests { @org.junit.Before - @SuppressWarnings("resource") - public void setUp() { + public void setup() { ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(getClass().getSimpleName() + ".xml", getClass()); @@ -55,6 +54,7 @@ public class BeanNamePointcutAtAspectTests { testBean3 = (ITestBean) ctx.getBean("testBean3"); } + @Test public void testMatchingBeanName() { assertTrue("Expected a proxy", testBean1 instanceof Advised); diff --git a/spring-context/src/test/java/org/springframework/aop/aspectj/BeanNamePointcutTests.java b/spring-context/src/test/java/org/springframework/aop/aspectj/BeanNamePointcutTests.java index cf6e831d96f..cf6599e143f 100644 --- a/spring-context/src/test/java/org/springframework/aop/aspectj/BeanNamePointcutTests.java +++ b/spring-context/src/test/java/org/springframework/aop/aspectj/BeanNamePointcutTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2018 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. @@ -55,7 +55,7 @@ public class BeanNamePointcutTests { @Before - public void setUp() { + public void setup() { ctx = new ClassPathXmlApplicationContext(getClass().getSimpleName() + ".xml", getClass()); testBean1 = (ITestBean) ctx.getBean("testBean1"); testBean2 = (ITestBean) ctx.getBean("testBean2"); diff --git a/spring-context/src/test/java/org/springframework/aop/aspectj/BeforeAdviceBindingTests.java b/spring-context/src/test/java/org/springframework/aop/aspectj/BeforeAdviceBindingTests.java index 9121ab34f05..bfed14eef21 100644 --- a/spring-context/src/test/java/org/springframework/aop/aspectj/BeforeAdviceBindingTests.java +++ b/spring-context/src/test/java/org/springframework/aop/aspectj/BeforeAdviceBindingTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2018 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. @@ -44,14 +44,11 @@ public class BeforeAdviceBindingTests { private TestBean testBeanTarget; - protected String getConfigPath() { - return "before-advice-tests.xml"; - } @Before - public void setUp() throws Exception { + public void setup() throws Exception { ClassPathXmlApplicationContext ctx = - new ClassPathXmlApplicationContext(getClass().getSimpleName() + ".xml", getClass()); + new ClassPathXmlApplicationContext(getClass().getSimpleName() + ".xml", getClass()); testBeanProxy = (ITestBean) ctx.getBean("testBean"); assertTrue(AopUtils.isAopProxy(testBeanProxy)); diff --git a/spring-context/src/test/java/org/springframework/aop/aspectj/DeclarationOrderIndependenceTests.java b/spring-context/src/test/java/org/springframework/aop/aspectj/DeclarationOrderIndependenceTests.java index bafc712494b..f7704065df2 100644 --- a/spring-context/src/test/java/org/springframework/aop/aspectj/DeclarationOrderIndependenceTests.java +++ b/spring-context/src/test/java/org/springframework/aop/aspectj/DeclarationOrderIndependenceTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2018 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. @@ -39,14 +39,14 @@ public class DeclarationOrderIndependenceTests { @Before - @SuppressWarnings("resource") - public void setUp() { + public void setup() { ClassPathXmlApplicationContext ctx = - new ClassPathXmlApplicationContext(getClass().getSimpleName() + ".xml", getClass()); + new ClassPathXmlApplicationContext(getClass().getSimpleName() + ".xml", getClass()); aspect = (TopsyTurvyAspect) ctx.getBean("topsyTurvyAspect"); target = (TopsyTurvyTarget) ctx.getBean("topsyTurvyTarget"); } + @Test public void testTargetIsSerializable() { assertTrue("target bean is serializable",this.target instanceof Serializable); @@ -135,10 +135,9 @@ class TopsyTurvyAspect { interface TopsyTurvyTarget { - public abstract void doSomething(); - - public abstract int getX(); + void doSomething(); + int getX(); } @@ -155,7 +154,6 @@ class TopsyTurvyTargetImpl implements TopsyTurvyTarget { public int getX() { return x; } - } @@ -179,5 +177,4 @@ class AspectCollaborator implements TopsyTurvyAspect.Collaborator { public void beforeAdviceFired() { this.beforeFired = true; } - } diff --git a/spring-context/src/test/java/org/springframework/aop/aspectj/DeclareParentsDelegateRefTests.java b/spring-context/src/test/java/org/springframework/aop/aspectj/DeclareParentsDelegateRefTests.java index 0e556fe0637..ebe8cb7182f 100644 --- a/spring-context/src/test/java/org/springframework/aop/aspectj/DeclareParentsDelegateRefTests.java +++ b/spring-context/src/test/java/org/springframework/aop/aspectj/DeclareParentsDelegateRefTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2018 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. @@ -35,14 +35,15 @@ public class DeclareParentsDelegateRefTests { @Before - public void setUp() { + public void setup() { ClassPathXmlApplicationContext ctx = - new ClassPathXmlApplicationContext(getClass().getSimpleName() + ".xml", getClass()); + new ClassPathXmlApplicationContext(getClass().getSimpleName() + ".xml", getClass()); noMethodsBean = (NoMethodsBean) ctx.getBean("noMethodsBean"); counter = (Counter) ctx.getBean("counter"); counter.reset(); } + @Test public void testIntroductionWasMade() { assertTrue("Introduction must have been made", noMethodsBean instanceof ICounter); diff --git a/spring-context/src/test/java/org/springframework/aop/aspectj/DeclareParentsTests.java b/spring-context/src/test/java/org/springframework/aop/aspectj/DeclareParentsTests.java index b214670c5f3..e7d168a05aa 100644 --- a/spring-context/src/test/java/org/springframework/aop/aspectj/DeclareParentsTests.java +++ b/spring-context/src/test/java/org/springframework/aop/aspectj/DeclareParentsTests.java @@ -21,10 +21,7 @@ import org.junit.Test; import test.mixin.Lockable; import org.springframework.aop.support.AopUtils; -import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; -import org.springframework.tests.Assume; -import org.springframework.tests.TestGroup; import org.springframework.tests.sample.beans.ITestBean; import static org.junit.Assert.*; @@ -37,18 +34,22 @@ public class DeclareParentsTests { private ITestBean testBeanProxy; - private ApplicationContext ctx; + private Object introductionObject; - @Before - public void setUp() throws Exception { - ctx = new ClassPathXmlApplicationContext(getClass().getSimpleName() + ".xml", getClass()); + @Before + public void setup() { + ClassPathXmlApplicationContext ctx = + new ClassPathXmlApplicationContext(getClass().getSimpleName() + ".xml", getClass()); testBeanProxy = (ITestBean) ctx.getBean("testBean"); - assertTrue(AopUtils.isAopProxy(testBeanProxy)); + introductionObject = ctx.getBean("introduction"); } + @Test public void testIntroductionWasMade() { + assertTrue(AopUtils.isAopProxy(testBeanProxy)); + assertFalse("Introduction should not be proxied", AopUtils.isAopProxy(introductionObject)); assertTrue("Introduction must have been made", testBeanProxy instanceof Lockable); } @@ -58,11 +59,6 @@ public class DeclareParentsTests { // on the introduction, in which case this would not be a problem. @Test public void testLockingWorks() { - Assume.group(TestGroup.LONG_RUNNING); - - Object introductionObject = ctx.getBean("introduction"); - assertFalse("Introduction should not be proxied", AopUtils.isAopProxy(introductionObject)); - Lockable lockable = (Lockable) testBeanProxy; assertFalse(lockable.locked()); @@ -90,5 +86,4 @@ class NonAnnotatedMakeLockable { throw new IllegalStateException("locked"); } } - } diff --git a/spring-context/src/test/java/org/springframework/aop/aspectj/ProceedTests.java b/spring-context/src/test/java/org/springframework/aop/aspectj/ProceedTests.java index 10ef204df26..1d7feb4d272 100644 --- a/spring-context/src/test/java/org/springframework/aop/aspectj/ProceedTests.java +++ b/spring-context/src/test/java/org/springframework/aop/aspectj/ProceedTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2018 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. @@ -43,14 +43,15 @@ public class ProceedTests { @Before - public void setUp() { + public void setup() { ClassPathXmlApplicationContext ctx = - new ClassPathXmlApplicationContext(getClass().getSimpleName() + ".xml", getClass()); + new ClassPathXmlApplicationContext(getClass().getSimpleName() + ".xml", getClass()); testBean = (SimpleBean) ctx.getBean("testBean"); firstTestAspect = (ProceedTestingAspect) ctx.getBean("firstTestAspect"); secondTestAspect = (ProceedTestingAspect) ctx.getBean("secondTestAspect"); } + @Test public void testSimpleProceedWithChangedArgs() { this.testBean.setName("abc"); diff --git a/spring-context/src/test/java/org/springframework/aop/aspectj/SharedPointcutWithArgsMismatchTests.java b/spring-context/src/test/java/org/springframework/aop/aspectj/SharedPointcutWithArgsMismatchTests.java index 7ed664f8fc2..7865aff868d 100644 --- a/spring-context/src/test/java/org/springframework/aop/aspectj/SharedPointcutWithArgsMismatchTests.java +++ b/spring-context/src/test/java/org/springframework/aop/aspectj/SharedPointcutWithArgsMismatchTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2018 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. @@ -33,18 +33,18 @@ public class SharedPointcutWithArgsMismatchTests { @Before - public void setUp() { + public void setup() { ClassPathXmlApplicationContext ctx = - new ClassPathXmlApplicationContext(getClass().getSimpleName() + ".xml", getClass()); + new ClassPathXmlApplicationContext(getClass().getSimpleName() + ".xml", getClass()); toBeAdvised = (ToBeAdvised) ctx.getBean("toBeAdvised"); } + @Test public void testMismatchedArgBinding() { this.toBeAdvised.foo("Hello"); } - } @@ -66,4 +66,3 @@ class MyAspect { System.out.println(x); } } - diff --git a/spring-context/src/test/java/org/springframework/aop/aspectj/SubtypeSensitiveMatchingTests.java b/spring-context/src/test/java/org/springframework/aop/aspectj/SubtypeSensitiveMatchingTests.java index aba88f9b2ba..2e3e6dc8c06 100644 --- a/spring-context/src/test/java/org/springframework/aop/aspectj/SubtypeSensitiveMatchingTests.java +++ b/spring-context/src/test/java/org/springframework/aop/aspectj/SubtypeSensitiveMatchingTests.java @@ -40,14 +40,15 @@ public class SubtypeSensitiveMatchingTests { @Before - public void setUp() { + public void setup() { ClassPathXmlApplicationContext ctx = - new ClassPathXmlApplicationContext(getClass().getSimpleName() + ".xml", getClass()); + new ClassPathXmlApplicationContext(getClass().getSimpleName() + ".xml", getClass()); nonSerializableBean = (NonSerializableFoo) ctx.getBean("testClassA"); serializableBean = (SerializableFoo) ctx.getBean("testClassB"); bar = (Bar) ctx.getBean("testClassC"); } + @Test public void testBeansAreProxiedOnStaticMatch() { assertTrue("bean with serializable type should be proxied", @@ -68,11 +69,15 @@ public class SubtypeSensitiveMatchingTests { } + //strange looking interfaces are just to set up certain test conditions... + interface NonSerializableFoo { void foo(); } + interface SerializableFoo extends Serializable { void foo(); } + class SubtypeMatchingTestClassA implements NonSerializableFoo { @Override @@ -80,6 +85,7 @@ class SubtypeMatchingTestClassA implements NonSerializableFoo { } + @SuppressWarnings("serial") class SubtypeMatchingTestClassB implements SerializableFoo { @@ -88,8 +94,10 @@ class SubtypeMatchingTestClassB implements SerializableFoo { } + interface Bar { void bar(Object o); } + class SubtypeMatchingTestClassC implements Bar { @Override diff --git a/spring-context/src/test/java/org/springframework/aop/aspectj/TargetPointcutSelectionTests.java b/spring-context/src/test/java/org/springframework/aop/aspectj/TargetPointcutSelectionTests.java index 6e84778a356..0d960886863 100644 --- a/spring-context/src/test/java/org/springframework/aop/aspectj/TargetPointcutSelectionTests.java +++ b/spring-context/src/test/java/org/springframework/aop/aspectj/TargetPointcutSelectionTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2015 the original author or authors. + * Copyright 2002-2018 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. @@ -18,7 +18,6 @@ package org.springframework.aop.aspectj; import org.aopalliance.intercept.MethodInterceptor; import org.aopalliance.intercept.MethodInvocation; - import org.junit.Before; import org.junit.Test; @@ -47,11 +46,9 @@ public class TargetPointcutSelectionTests { @Before - @SuppressWarnings("resource") - public void setUp() { + public void setup() { ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(getClass().getSimpleName() + ".xml", getClass()); - testImpl1 = (TestInterface) ctx.getBean("testImpl1"); testImpl2 = (TestInterface) ctx.getBean("testImpl2"); testAspectForTestImpl1 = (TestAspect) ctx.getBean("testAspectForTestImpl1"); diff --git a/spring-context/src/test/java/org/springframework/aop/aspectj/ThisAndTargetSelectionOnlyPointcutsAtAspectJTests.java b/spring-context/src/test/java/org/springframework/aop/aspectj/ThisAndTargetSelectionOnlyPointcutsAtAspectJTests.java index 65efa67ed96..35097302142 100644 --- a/spring-context/src/test/java/org/springframework/aop/aspectj/ThisAndTargetSelectionOnlyPointcutsAtAspectJTests.java +++ b/spring-context/src/test/java/org/springframework/aop/aspectj/ThisAndTargetSelectionOnlyPointcutsAtAspectJTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2015 the original author or authors. + * Copyright 2002-2018 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,6 +22,7 @@ import java.lang.annotation.RetentionPolicy; import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Before; import org.junit.Test; + import org.springframework.context.support.ClassPathXmlApplicationContext; import static org.junit.Assert.*; @@ -40,11 +41,11 @@ public class ThisAndTargetSelectionOnlyPointcutsAtAspectJTests { private Counter counter; + @org.junit.Before - @SuppressWarnings("resource") - public void setUp() { + public void setup() { ClassPathXmlApplicationContext ctx = - new ClassPathXmlApplicationContext(getClass().getSimpleName() + ".xml", getClass()); + new ClassPathXmlApplicationContext(getClass().getSimpleName() + ".xml", getClass()); testBean = (TestInterface) ctx.getBean("testBean"); testAnnotatedClassBean = (TestInterface) ctx.getBean("testAnnotatedClassBean"); testAnnotatedMethodBean = (TestInterface) ctx.getBean("testAnnotatedMethodBean"); @@ -52,6 +53,7 @@ public class ThisAndTargetSelectionOnlyPointcutsAtAspectJTests { counter.reset(); } + @Test public void thisAsClassDoesNotMatch() { testBean.doIt(); diff --git a/spring-context/src/test/java/org/springframework/aop/aspectj/ThisAndTargetSelectionOnlyPointcutsTests.java b/spring-context/src/test/java/org/springframework/aop/aspectj/ThisAndTargetSelectionOnlyPointcutsTests.java index 7e48352cfe5..d6e1f0b7259 100644 --- a/spring-context/src/test/java/org/springframework/aop/aspectj/ThisAndTargetSelectionOnlyPointcutsTests.java +++ b/spring-context/src/test/java/org/springframework/aop/aspectj/ThisAndTargetSelectionOnlyPointcutsTests.java @@ -39,18 +39,16 @@ public class ThisAndTargetSelectionOnlyPointcutsTests { private Counter thisAsInterfaceAndTargetAsInterfaceCounter; private Counter thisAsInterfaceAndTargetAsClassCounter; + @Before - public void setUp() { + public void setup() { ClassPathXmlApplicationContext ctx = - new ClassPathXmlApplicationContext(getClass().getSimpleName() + ".xml", getClass()); - + new ClassPathXmlApplicationContext(getClass().getSimpleName() + ".xml", getClass()); testBean = (TestInterface) ctx.getBean("testBean"); - thisAsClassCounter = (Counter) ctx.getBean("thisAsClassCounter"); thisAsInterfaceCounter = (Counter) ctx.getBean("thisAsInterfaceCounter"); targetAsClassCounter = (Counter) ctx.getBean("targetAsClassCounter"); targetAsInterfaceCounter = (Counter) ctx.getBean("targetAsInterfaceCounter"); - thisAsClassAndTargetAsClassCounter = (Counter) ctx.getBean("thisAsClassAndTargetAsClassCounter"); thisAsInterfaceAndTargetAsInterfaceCounter = (Counter) ctx.getBean("thisAsInterfaceAndTargetAsInterfaceCounter"); thisAsInterfaceAndTargetAsClassCounter = (Counter) ctx.getBean("thisAsInterfaceAndTargetAsClassCounter"); @@ -59,12 +57,12 @@ public class ThisAndTargetSelectionOnlyPointcutsTests { thisAsInterfaceCounter.reset(); targetAsClassCounter.reset(); targetAsInterfaceCounter.reset(); - thisAsClassAndTargetAsClassCounter.reset(); thisAsInterfaceAndTargetAsInterfaceCounter.reset(); thisAsInterfaceAndTargetAsClassCounter.reset(); } + @Test public void testThisAsClassDoesNotMatch() { testBean.doIt(); diff --git a/spring-context/src/test/java/org/springframework/aop/aspectj/autoproxy/AnnotationBindingTests.java b/spring-context/src/test/java/org/springframework/aop/aspectj/autoproxy/AnnotationBindingTests.java index a7f24b51bae..0c626a752a7 100644 --- a/spring-context/src/test/java/org/springframework/aop/aspectj/autoproxy/AnnotationBindingTests.java +++ b/spring-context/src/test/java/org/springframework/aop/aspectj/autoproxy/AnnotationBindingTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2018 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. @@ -33,7 +33,7 @@ public class AnnotationBindingTests { @Before - public void setUp() { + public void setup() { ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(getClass().getSimpleName() + "-context.xml", getClass()); testBean = (AnnotatedTestBean) ctx.getBean("testBean"); diff --git a/spring-context/src/test/java/org/springframework/aop/aspectj/autoproxy/AtAspectJAnnotationBindingTests.java b/spring-context/src/test/java/org/springframework/aop/aspectj/autoproxy/AtAspectJAnnotationBindingTests.java index 002bc42b664..c5f789ecf77 100644 --- a/spring-context/src/test/java/org/springframework/aop/aspectj/autoproxy/AtAspectJAnnotationBindingTests.java +++ b/spring-context/src/test/java/org/springframework/aop/aspectj/autoproxy/AtAspectJAnnotationBindingTests.java @@ -40,7 +40,7 @@ public class AtAspectJAnnotationBindingTests { @Before - public void setUp() { + public void setup() { ctx = new ClassPathXmlApplicationContext(getClass().getSimpleName() + "-context.xml", getClass()); testBean = (AnnotatedTestBean) ctx.getBean("testBean"); } @@ -84,7 +84,7 @@ class ResourceArrayFactoryBean implements FactoryBean { @Override @TestAnnotation("some value") - public Object getObject() throws Exception { + public Object getObject() { return new Resource[0]; } diff --git a/spring-context/src/test/java/org/springframework/aop/aspectj/generic/AfterReturningGenericTypeMatchingTests.java b/spring-context/src/test/java/org/springframework/aop/aspectj/generic/AfterReturningGenericTypeMatchingTests.java index d64913d61c0..cf62cc75754 100644 --- a/spring-context/src/test/java/org/springframework/aop/aspectj/generic/AfterReturningGenericTypeMatchingTests.java +++ b/spring-context/src/test/java/org/springframework/aop/aspectj/generic/AfterReturningGenericTypeMatchingTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2018 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. @@ -48,9 +48,9 @@ public class AfterReturningGenericTypeMatchingTests { @Before - public void setUp() { + public void setup() { ClassPathXmlApplicationContext ctx = - new ClassPathXmlApplicationContext(getClass().getSimpleName() + "-context.xml", getClass()); + new ClassPathXmlApplicationContext(getClass().getSimpleName() + "-context.xml", getClass()); counterAspect = (CounterAspect) ctx.getBean("counterAspect"); counterAspect.reset(); @@ -58,6 +58,7 @@ public class AfterReturningGenericTypeMatchingTests { testBean = (GenericReturnTypeVariationClass) ctx.getBean("testBean"); } + @Test public void testReturnTypeExactMatching() { testBean.getStrings(); diff --git a/spring-context/src/test/java/org/springframework/aop/aspectj/generic/GenericBridgeMethodMatchingTests.java b/spring-context/src/test/java/org/springframework/aop/aspectj/generic/GenericBridgeMethodMatchingTests.java index 6168fa1d340..f999c4f17f1 100644 --- a/spring-context/src/test/java/org/springframework/aop/aspectj/generic/GenericBridgeMethodMatchingTests.java +++ b/spring-context/src/test/java/org/springframework/aop/aspectj/generic/GenericBridgeMethodMatchingTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2018 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. @@ -48,9 +48,9 @@ public class GenericBridgeMethodMatchingTests { @SuppressWarnings("unchecked") @org.junit.Before - public void setUp() { + public void setup() { ClassPathXmlApplicationContext ctx = - new ClassPathXmlApplicationContext(getClass().getSimpleName() + "-context.xml", getClass()); + new ClassPathXmlApplicationContext(getClass().getSimpleName() + "-context.xml", getClass()); counterAspect = (GenericCounterAspect) ctx.getBean("counterAspect"); counterAspect.count = 0; diff --git a/spring-context/src/test/java/org/springframework/aop/aspectj/generic/GenericParameterMatchingTests.java b/spring-context/src/test/java/org/springframework/aop/aspectj/generic/GenericParameterMatchingTests.java index 2bea833ec19..af95ba6d89b 100644 --- a/spring-context/src/test/java/org/springframework/aop/aspectj/generic/GenericParameterMatchingTests.java +++ b/spring-context/src/test/java/org/springframework/aop/aspectj/generic/GenericParameterMatchingTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2018 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. @@ -43,9 +43,9 @@ public class GenericParameterMatchingTests { @SuppressWarnings("unchecked") @org.junit.Before - public void setUp() { + public void setup() { ClassPathXmlApplicationContext ctx = - new ClassPathXmlApplicationContext(getClass().getSimpleName() + "-context.xml", getClass()); + new ClassPathXmlApplicationContext(getClass().getSimpleName() + "-context.xml", getClass()); counterAspect = (CounterAspect) ctx.getBean("counterAspect"); counterAspect.reset();