From a07dc80d728c73cd4f267123f5d1dc2dd35868ac Mon Sep 17 00:00:00 2001 From: Sam Brannen Date: Mon, 11 May 2020 14:59:49 +0200 Subject: [PATCH] Polishing --- .../BeanNameAutoProxyCreatorTests.java | 45 +++++----------- .../BeanNameAutoProxyCreatorTests-context.xml | 54 ++++++++----------- 2 files changed, 36 insertions(+), 63 deletions(-) diff --git a/spring-context/src/test/java/org/springframework/aop/framework/autoproxy/BeanNameAutoProxyCreatorTests.java b/spring-context/src/test/java/org/springframework/aop/framework/autoproxy/BeanNameAutoProxyCreatorTests.java index ce3123e71bf1..4e03a4a2db08 100644 --- a/spring-context/src/test/java/org/springframework/aop/framework/autoproxy/BeanNameAutoProxyCreatorTests.java +++ b/spring-context/src/test/java/org/springframework/aop/framework/autoproxy/BeanNameAutoProxyCreatorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 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,7 +16,6 @@ package org.springframework.aop.framework.autoproxy; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import test.mixin.Lockable; import test.mixin.LockedException; @@ -40,42 +39,36 @@ * @author Rob Harrop * @author Chris Beams */ -public class BeanNameAutoProxyCreatorTests { +class BeanNameAutoProxyCreatorTests { - private BeanFactory beanFactory; - - - @BeforeEach - public void setup() { - // Note that we need an ApplicationContext, not just a BeanFactory, - // for post-processing and hence auto-proxying to work. - beanFactory = new ClassPathXmlApplicationContext(getClass().getSimpleName() + "-context.xml", getClass()); - } + // Note that we need an ApplicationContext, not just a BeanFactory, + // for post-processing and hence auto-proxying to work. + private final BeanFactory beanFactory = new ClassPathXmlApplicationContext(getClass().getSimpleName() + "-context.xml", getClass()); @Test - public void testNoProxy() { + void noProxy() { TestBean tb = (TestBean) beanFactory.getBean("noproxy"); assertThat(AopUtils.isAopProxy(tb)).isFalse(); assertThat(tb.getName()).isEqualTo("noproxy"); } @Test - public void testJdkProxyWithExactNameMatch() { + void proxyWithExactNameMatch() { ITestBean tb = (ITestBean) beanFactory.getBean("onlyJdk"); jdkAssertions(tb, 1); assertThat(tb.getName()).isEqualTo("onlyJdk"); } @Test - public void testJdkProxyWithDoubleProxying() { + void proxyWithDoubleProxying() { ITestBean tb = (ITestBean) beanFactory.getBean("doubleJdk"); jdkAssertions(tb, 2); assertThat(tb.getName()).isEqualTo("doubleJdk"); } @Test - public void testJdkIntroduction() { + void jdkIntroduction() { ITestBean tb = (ITestBean) beanFactory.getBean("introductionUsingJdk"); NopInterceptor nop = (NopInterceptor) beanFactory.getBean("introductionNopInterceptor"); assertThat(nop.getCount()).isEqualTo(0); @@ -110,7 +103,7 @@ public void testJdkIntroduction() { } @Test - public void testJdkIntroductionAppliesToCreatedObjectsNotFactoryBean() { + void jdkIntroductionAppliesToCreatedObjectsNotFactoryBean() { ITestBean tb = (ITestBean) beanFactory.getBean("factory-introductionUsingJdk"); NopInterceptor nop = (NopInterceptor) beanFactory.getBean("introductionNopInterceptor"); assertThat(nop.getCount()).as("NOP should not have done any work yet").isEqualTo(0); @@ -118,8 +111,7 @@ public void testJdkIntroductionAppliesToCreatedObjectsNotFactoryBean() { int age = 5; tb.setAge(age); assertThat(tb.getAge()).isEqualTo(age); - boolean condition = tb instanceof TimeStamped; - assertThat(condition).as("Introduction was made").isTrue(); + assertThat(tb).as("Introduction was made").isInstanceOf(TimeStamped.class); assertThat(((TimeStamped) tb).getTimeStamp()).isEqualTo(0); assertThat(nop.getCount()).isEqualTo(3); @@ -144,21 +136,21 @@ public void testJdkIntroductionAppliesToCreatedObjectsNotFactoryBean() { } @Test - public void testJdkProxyWithWildcardMatch() { + void proxyWithWildcardMatch() { ITestBean tb = (ITestBean) beanFactory.getBean("jdk1"); jdkAssertions(tb, 1); assertThat(tb.getName()).isEqualTo("jdk1"); } @Test - public void testCglibProxyWithWildcardMatch() { + void cglibProxyWithWildcardMatch() { TestBean tb = (TestBean) beanFactory.getBean("cglib1"); cglibAssertions(tb); assertThat(tb.getName()).isEqualTo("cglib1"); } @Test - public void testWithFrozenProxy() { + void withFrozenProxy() { ITestBean testBean = (ITestBean) beanFactory.getBean("frozenBean"); assertThat(((Advised)testBean).isFrozen()).isTrue(); } @@ -195,25 +187,16 @@ private void cglibAssertions(TestBean tb) { class CreatesTestBean implements FactoryBean { - /** - * @see org.springframework.beans.factory.FactoryBean#getObject() - */ @Override public Object getObject() throws Exception { return new TestBean(); } - /** - * @see org.springframework.beans.factory.FactoryBean#getObjectType() - */ @Override public Class getObjectType() { return TestBean.class; } - /** - * @see org.springframework.beans.factory.FactoryBean#isSingleton() - */ @Override public boolean isSingleton() { return true; diff --git a/spring-context/src/test/resources/org/springframework/aop/framework/autoproxy/BeanNameAutoProxyCreatorTests-context.xml b/spring-context/src/test/resources/org/springframework/aop/framework/autoproxy/BeanNameAutoProxyCreatorTests-context.xml index 95f25cdedb96..15e9b0e9cd55 100644 --- a/spring-context/src/test/resources/org/springframework/aop/framework/autoproxy/BeanNameAutoProxyCreatorTests-context.xml +++ b/spring-context/src/test/resources/org/springframework/aop/framework/autoproxy/BeanNameAutoProxyCreatorTests-context.xml @@ -4,38 +4,28 @@ - - - + + + - - Automatically proxies using JDK dynamic proxies - - jdk*,onlyJdk,doubleJdk - - - nopInterceptor - - + Automatically proxies using JDK dynamic proxies + + - - + + - - - cglib* - + + + Use the inherited ProxyConfig property to force CGLIB proxying + true - - Use the inherited ProxyConfig property to force CGLIB proxying - true - Interceptors and Advisors to apply automatically @@ -49,14 +39,14 @@ Illustrates a JDK introduction - *introductionUsingJdk - + + introductionNopInterceptor timestampIntroduction lockableAdvisor - + @@ -74,11 +64,11 @@ - introductionUsingJdk + - second-introductionUsingJdk +