11/*
2- * Copyright 2002-2013 the original author or authors.
2+ * Copyright 2002-2014 the original author or authors.
33 *
44 * Licensed under the Apache License, Version 2.0 (the "License");
55 * you may not use this file except in compliance with the License.
1616
1717package org .springframework .context .annotation ;
1818
19- import junit .framework . TestCase ;
19+ import org . junit .Test ;
2020
2121import org .springframework .aop .scope .ScopedObject ;
2222import org .springframework .aop .support .AopUtils ;
2525import org .springframework .beans .factory .support .RootBeanDefinition ;
2626import org .springframework .context .annotation4 .DependencyBean ;
2727import org .springframework .context .annotation4 .FactoryMethodComponent ;
28+ import org .springframework .context .support .AbstractApplicationContext ;
2829import org .springframework .context .support .GenericApplicationContext ;
2930import org .springframework .tests .context .SimpleMapScope ;
3031import org .springframework .tests .sample .beans .TestBean ;
3132import org .springframework .util .ClassUtils ;
3233
34+ import static org .junit .Assert .*;
35+
3336/**
3437 * @author Mark Pollack
3538 * @author Juergen Hoeller
3639 */
37- public class ClassPathFactoryBeanDefinitionScannerTests extends TestCase {
40+ public class ClassPathFactoryBeanDefinitionScannerTests {
3841
3942 private static final String BASE_PACKAGE = FactoryMethodComponent .class .getPackage ().getName ();
4043
4144
45+ @ Test
4246 public void testSingletonScopedFactoryMethod () {
4347 GenericApplicationContext context = new GenericApplicationContext ();
4448 ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner (context );
@@ -52,13 +56,13 @@ public void testSingletonScopedFactoryMethod() {
5256 FactoryMethodComponent fmc = context .getBean ("factoryMethodComponent" , FactoryMethodComponent .class );
5357 assertFalse (fmc .getClass ().getName ().contains (ClassUtils .CGLIB_CLASS_SEPARATOR ));
5458
55- TestBean tb = (TestBean )context .getBean ("publicInstance" ); //2
59+ TestBean tb = (TestBean ) context .getBean ("publicInstance" ); //2
5660 assertEquals ("publicInstance" , tb .getName ());
57- TestBean tb2 = (TestBean )context .getBean ("publicInstance" ); //2
61+ TestBean tb2 = (TestBean ) context .getBean ("publicInstance" ); //2
5862 assertEquals ("publicInstance" , tb2 .getName ());
5963 assertSame (tb2 , tb );
6064
61- tb = (TestBean )context .getBean ("protectedInstance" ); //3
65+ tb = (TestBean ) context .getBean ("protectedInstance" ); //3
6266 assertEquals ("protectedInstance" , tb .getName ());
6367 assertSame (tb , context .getBean ("protectedInstance" ));
6468 assertEquals ("0" , tb .getCountry ());
@@ -78,8 +82,9 @@ public void testSingletonScopedFactoryMethod() {
7882 assertTrue (bean instanceof ScopedObject );
7983
8084 QualifiedClientBean clientBean = context .getBean ("clientBean" , QualifiedClientBean .class );
81- assertSame (clientBean .testBean , context .getBean ("publicInstance" ));
82- assertSame (clientBean .dependencyBean , context .getBean ("dependencyBean" ));
85+ assertSame (context .getBean ("publicInstance" ), clientBean .testBean );
86+ assertSame (context .getBean ("dependencyBean" ), clientBean .dependencyBean );
87+ assertSame (context , clientBean .applicationContext );
8388 }
8489
8590
@@ -90,6 +95,9 @@ public static class QualifiedClientBean {
9095
9196 @ Autowired
9297 public DependencyBean dependencyBean ;
98+
99+ @ Autowired
100+ AbstractApplicationContext applicationContext ;
93101 }
94102
95103}
0 commit comments