11/*
2- * Copyright 2002-2010 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.
1818
1919import org .junit .Test ;
2020
21+ import org .springframework .beans .factory .NoUniqueBeanDefinitionException ;
2122import org .springframework .beans .factory .support .DefaultListableBeanFactory ;
23+ import org .springframework .beans .factory .support .RootBeanDefinition ;
24+
25+ import static org .junit .Assert .*;
2226
2327/**
2428 * @author Juergen Hoeller
@@ -28,9 +32,27 @@ public class GenericApplicationContextTests {
2832
2933 @ Test
3034 public void nullBeanRegistration () {
31- DefaultListableBeanFactory bf = new DefaultListableBeanFactory ();
32- bf .registerSingleton ("nullBean" , null );
33- new GenericApplicationContext (bf ).refresh ();
35+ DefaultListableBeanFactory bf = new DefaultListableBeanFactory ();
36+ bf .registerSingleton ("nullBean" , null );
37+ new GenericApplicationContext (bf ).refresh ();
38+ }
39+
40+ @ Test
41+ public void getBeanForClass () {
42+ GenericApplicationContext ac = new GenericApplicationContext ();
43+ ac .registerBeanDefinition ("testBean" , new RootBeanDefinition (String .class ));
44+ ac .refresh ();
45+
46+ assertSame (ac .getBean ("testBean" ), ac .getBean (String .class ));
47+ assertSame (ac .getBean ("testBean" ), ac .getBean (CharSequence .class ));
48+
49+ try {
50+ assertSame (ac .getBean ("testBean" ), ac .getBean (Object .class ));
51+ fail ("Should have thrown NoUniqueBeanDefinitionException" );
52+ }
53+ catch (NoUniqueBeanDefinitionException ex ) {
54+ // expected
55+ }
3456 }
3557
3658}
0 commit comments