1
1
/*
2
- * Copyright 2002-2010 the original author or authors.
2
+ * Copyright 2002-2014 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
18
18
19
19
import org .junit .Test ;
20
20
21
+ import org .springframework .beans .factory .NoUniqueBeanDefinitionException ;
21
22
import org .springframework .beans .factory .support .DefaultListableBeanFactory ;
23
+ import org .springframework .beans .factory .support .RootBeanDefinition ;
24
+
25
+ import static org .junit .Assert .*;
22
26
23
27
/**
24
28
* @author Juergen Hoeller
@@ -28,9 +32,27 @@ public class GenericApplicationContextTests {
28
32
29
33
@ Test
30
34
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
+ }
34
56
}
35
57
36
58
}
0 commit comments