@ -1,5 +1,5 @@
@@ -1,5 +1,5 @@
/ *
* Copyright 2002 - 2010 the original author or authors .
* Copyright 2002 - 2014 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,11 @@ package org.springframework.context.support;
@@ -18,7 +18,11 @@ package org.springframework.context.support;
import org.junit.Test ;
import org.springframework.beans.factory.NoUniqueBeanDefinitionException ;
import org.springframework.beans.factory.support.DefaultListableBeanFactory ;
import org.springframework.beans.factory.support.RootBeanDefinition ;
import static org.junit.Assert.* ;
/ * *
* @author Juergen Hoeller
@ -28,9 +32,27 @@ public class GenericApplicationContextTests {
@@ -28,9 +32,27 @@ public class GenericApplicationContextTests {
@Test
public void nullBeanRegistration ( ) {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory ( ) ;
bf . registerSingleton ( "nullBean" , null ) ;
new GenericApplicationContext ( bf ) . refresh ( ) ;
DefaultListableBeanFactory bf = new DefaultListableBeanFactory ( ) ;
bf . registerSingleton ( "nullBean" , null ) ;
new GenericApplicationContext ( bf ) . refresh ( ) ;
}
@Test
public void getBeanForClass ( ) {
GenericApplicationContext ac = new GenericApplicationContext ( ) ;
ac . registerBeanDefinition ( "testBean" , new RootBeanDefinition ( String . class ) ) ;
ac . refresh ( ) ;
assertSame ( ac . getBean ( "testBean" ) , ac . getBean ( String . class ) ) ;
assertSame ( ac . getBean ( "testBean" ) , ac . getBean ( CharSequence . class ) ) ;
try {
assertSame ( ac . getBean ( "testBean" ) , ac . getBean ( Object . class ) ) ;
fail ( "Should have thrown NoUniqueBeanDefinitionException" ) ;
}
catch ( NoUniqueBeanDefinitionException ex ) {
// expected
}
}
}