Polishing

This commit is contained in:
Juergen Hoeller 2018-07-27 17:46:21 +02:00
parent c037e75f26
commit 1fd6248d84
23 changed files with 97 additions and 102 deletions

View File

@ -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());
}

View File

@ -44,8 +44,9 @@ 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());
AdviceBindingTestAspect afterAdviceAspect = (AdviceBindingTestAspect) ctx.getBean("testAspect");
@ -60,6 +61,7 @@ public class AfterAdviceBindingTests {
afterAdviceAspect.setCollaborator(mockCollaborator);
}
@Test
public void testOneIntArg() {
testBeanProxy.setAge(5);

View File

@ -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,12 +48,8 @@ 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());

View File

@ -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,8 +39,9 @@ public class AfterThrowingAdviceBindingTests {
private AfterThrowingAdviceBindingCollaborator mockCollaborator;
@Before
public void setUp() {
public void setup() {
ClassPathXmlApplicationContext ctx =
new ClassPathXmlApplicationContext(getClass().getSimpleName() + ".xml", getClass());
@ -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();
}
}

View File

@ -49,7 +49,7 @@ public class AspectAndAdvicePrecedenceTests {
@Before
public void setUp() {
public void setup() {
ClassPathXmlApplicationContext ctx =
new ClassPathXmlApplicationContext(getClass().getSimpleName() + ".xml", getClass());
highPrecedenceAspect = (PrecedenceTestAspect) ctx.getBean("highPrecedenceAspect");
@ -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() {

View File

@ -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());
testBean = (ITestBean) ctx.getBean("testBean");
interceptor = (CallCountingInterceptor) ctx.getBean("interceptor");
}
@Test
public void testPointcutting() {
assertEquals("Count should be 0", 0, interceptor.getCount());

View File

@ -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);

View File

@ -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");

View File

@ -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,12 +44,9 @@ 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());

View File

@ -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());
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;
}
}

View File

@ -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,7 +35,7 @@ public class DeclareParentsDelegateRefTests {
@Before
public void setUp() {
public void setup() {
ClassPathXmlApplicationContext ctx =
new ClassPathXmlApplicationContext(getClass().getSimpleName() + ".xml", getClass());
noMethodsBean = (NoMethodsBean) ctx.getBean("noMethodsBean");
@ -43,6 +43,7 @@ public class DeclareParentsDelegateRefTests {
counter.reset();
}
@Test
public void testIntroductionWasMade() {
assertTrue("Introduction must have been made", noMethodsBean instanceof ICounter);

View File

@ -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());
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");
}
}
}

View File

@ -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,7 +43,7 @@ public class ProceedTests {
@Before
public void setUp() {
public void setup() {
ClassPathXmlApplicationContext ctx =
new ClassPathXmlApplicationContext(getClass().getSimpleName() + ".xml", getClass());
testBean = (SimpleBean) ctx.getBean("testBean");
@ -51,6 +51,7 @@ public class ProceedTests {
secondTestAspect = (ProceedTestingAspect) ctx.getBean("secondTestAspect");
}
@Test
public void testSimpleProceedWithChangedArgs() {
this.testBean.setName("abc");

View File

@ -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());
toBeAdvised = (ToBeAdvised) ctx.getBean("toBeAdvised");
}
@Test
public void testMismatchedArgBinding() {
this.toBeAdvised.foo("Hello");
}
}
@ -66,4 +66,3 @@ class MyAspect {
System.out.println(x);
}
}

View File

@ -40,7 +40,7 @@ public class SubtypeSensitiveMatchingTests {
@Before
public void setUp() {
public void setup() {
ClassPathXmlApplicationContext ctx =
new ClassPathXmlApplicationContext(getClass().getSimpleName() + ".xml", getClass());
nonSerializableBean = (NonSerializableFoo) ctx.getBean("testClassA");
@ -48,6 +48,7 @@ public class SubtypeSensitiveMatchingTests {
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

View File

@ -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");

View File

@ -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,9 +41,9 @@ 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());
testBean = (TestInterface) ctx.getBean("testBean");
@ -52,6 +53,7 @@ public class ThisAndTargetSelectionOnlyPointcutsAtAspectJTests {
counter.reset();
}
@Test
public void thisAsClassDoesNotMatch() {
testBean.doIt();

View File

@ -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());
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();

View File

@ -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");

View File

@ -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<Object> {
@Override
@TestAnnotation("some value")
public Object getObject() throws Exception {
public Object getObject() {
return new Resource[0];
}

View File

@ -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,7 +48,7 @@ public class AfterReturningGenericTypeMatchingTests {
@Before
public void setUp() {
public void setup() {
ClassPathXmlApplicationContext ctx =
new ClassPathXmlApplicationContext(getClass().getSimpleName() + "-context.xml", getClass());
@ -58,6 +58,7 @@ public class AfterReturningGenericTypeMatchingTests {
testBean = (GenericReturnTypeVariationClass) ctx.getBean("testBean");
}
@Test
public void testReturnTypeExactMatching() {
testBean.getStrings();

View File

@ -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,7 +48,7 @@ public class GenericBridgeMethodMatchingTests {
@SuppressWarnings("unchecked")
@org.junit.Before
public void setUp() {
public void setup() {
ClassPathXmlApplicationContext ctx =
new ClassPathXmlApplicationContext(getClass().getSimpleName() + "-context.xml", getClass());

View File

@ -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,7 +43,7 @@ public class GenericParameterMatchingTests {
@SuppressWarnings("unchecked")
@org.junit.Before
public void setUp() {
public void setup() {
ClassPathXmlApplicationContext ctx =
new ClassPathXmlApplicationContext(getClass().getSimpleName() + "-context.xml", getClass());