|
|
|
@ -1,5 +1,5 @@ |
|
|
|
/* |
|
|
|
/* |
|
|
|
* Copyright 2002-2013 the original author or authors. |
|
|
|
* Copyright 2002-2014 the original author or authors. |
|
|
|
* |
|
|
|
* |
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
@ -14,24 +14,23 @@ |
|
|
|
* limitations under the License. |
|
|
|
* limitations under the License. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
package org.springframework.beans.factory; |
|
|
|
package org.springframework.beans.factory.support; |
|
|
|
|
|
|
|
|
|
|
|
import static org.junit.Assert.*; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.Arrays; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import org.junit.Test; |
|
|
|
import org.junit.Test; |
|
|
|
|
|
|
|
|
|
|
|
import org.springframework.beans.BeansException; |
|
|
|
import org.springframework.beans.BeansException; |
|
|
|
import org.springframework.beans.factory.support.DefaultSingletonBeanRegistry; |
|
|
|
import org.springframework.beans.factory.ObjectFactory; |
|
|
|
import org.springframework.tests.sample.beans.DerivedTestBean; |
|
|
|
import org.springframework.tests.sample.beans.DerivedTestBean; |
|
|
|
import org.springframework.tests.sample.beans.TestBean; |
|
|
|
import org.springframework.tests.sample.beans.TestBean; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import static org.junit.Assert.*; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* @author Juergen Hoeller |
|
|
|
* @author Juergen Hoeller |
|
|
|
* @author Chris Beams |
|
|
|
* @author Chris Beams |
|
|
|
* @since 04.07.2006 |
|
|
|
* @since 04.07.2006 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public final class SharedBeanRegistryTests { |
|
|
|
public class DefaultSingletonBeanRegistryTests { |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testSingletons() { |
|
|
|
public void testSingletons() { |
|
|
|
@ -52,9 +51,10 @@ public final class SharedBeanRegistryTests { |
|
|
|
assertSame(tb, beanRegistry.getSingleton("tb")); |
|
|
|
assertSame(tb, beanRegistry.getSingleton("tb")); |
|
|
|
assertSame(tb2, beanRegistry.getSingleton("tb2")); |
|
|
|
assertSame(tb2, beanRegistry.getSingleton("tb2")); |
|
|
|
assertEquals(2, beanRegistry.getSingletonCount()); |
|
|
|
assertEquals(2, beanRegistry.getSingletonCount()); |
|
|
|
assertEquals(2, beanRegistry.getSingletonNames().length); |
|
|
|
String[] names = beanRegistry.getSingletonNames(); |
|
|
|
assertTrue(Arrays.asList(beanRegistry.getSingletonNames()).contains("tb")); |
|
|
|
assertEquals(2, names.length); |
|
|
|
assertTrue(Arrays.asList(beanRegistry.getSingletonNames()).contains("tb2")); |
|
|
|
assertEquals("tb", names[0]); |
|
|
|
|
|
|
|
assertEquals("tb2", names[1]); |
|
|
|
|
|
|
|
|
|
|
|
beanRegistry.destroySingletons(); |
|
|
|
beanRegistry.destroySingletons(); |
|
|
|
assertEquals(0, beanRegistry.getSingletonCount()); |
|
|
|
assertEquals(0, beanRegistry.getSingletonCount()); |
|
|
|
@ -72,8 +72,9 @@ public final class SharedBeanRegistryTests { |
|
|
|
|
|
|
|
|
|
|
|
assertSame(tb, beanRegistry.getSingleton("tb")); |
|
|
|
assertSame(tb, beanRegistry.getSingleton("tb")); |
|
|
|
assertEquals(1, beanRegistry.getSingletonCount()); |
|
|
|
assertEquals(1, beanRegistry.getSingletonCount()); |
|
|
|
assertEquals(1, beanRegistry.getSingletonNames().length); |
|
|
|
String[] names = beanRegistry.getSingletonNames(); |
|
|
|
assertTrue(Arrays.asList(beanRegistry.getSingletonNames()).contains("tb")); |
|
|
|
assertEquals(1, names.length); |
|
|
|
|
|
|
|
assertEquals("tb", names[0]); |
|
|
|
assertFalse(tb.wasDestroyed()); |
|
|
|
assertFalse(tb.wasDestroyed()); |
|
|
|
|
|
|
|
|
|
|
|
beanRegistry.destroySingletons(); |
|
|
|
beanRegistry.destroySingletons(); |
|
|
|
@ -82,4 +83,22 @@ public final class SharedBeanRegistryTests { |
|
|
|
assertTrue(tb.wasDestroyed()); |
|
|
|
assertTrue(tb.wasDestroyed()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
|
|
public void testDependentRegistration() { |
|
|
|
|
|
|
|
DefaultSingletonBeanRegistry beanRegistry = new DefaultSingletonBeanRegistry(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
beanRegistry.registerDependentBean("a", "b"); |
|
|
|
|
|
|
|
beanRegistry.registerDependentBean("b", "c"); |
|
|
|
|
|
|
|
beanRegistry.registerDependentBean("c", "b"); |
|
|
|
|
|
|
|
assertTrue(beanRegistry.isDependent("a", "b")); |
|
|
|
|
|
|
|
assertTrue(beanRegistry.isDependent("b", "c")); |
|
|
|
|
|
|
|
assertTrue(beanRegistry.isDependent("c", "b")); |
|
|
|
|
|
|
|
assertTrue(beanRegistry.isDependent("a", "c")); |
|
|
|
|
|
|
|
assertFalse(beanRegistry.isDependent("c", "a")); |
|
|
|
|
|
|
|
assertFalse(beanRegistry.isDependent("b", "a")); |
|
|
|
|
|
|
|
assertFalse(beanRegistry.isDependent("a", "a")); |
|
|
|
|
|
|
|
assertTrue(beanRegistry.isDependent("b", "b")); |
|
|
|
|
|
|
|
assertTrue(beanRegistry.isDependent("c", "c")); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |