1 package org.apache.commons.beanutils2;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 import static org.apache.commons.beanutils2.BeanUtils.onClassName;
21 import static org.junit.Assert.assertNotNull;
22 import static org.junit.Assert.assertTrue;
23
24 import org.apache.commons.beanutils2.testbeans.TestBean;
25 import org.junit.Test;
26
27 public class OnClassNameTestCase
28 {
29
30 @Test( expected = NullPointerException.class )
31 public void onClassNameNull()
32 {
33 onClassName( null );
34 }
35
36 @Test( expected = BeanClassNotFoundException.class )
37 public void onClassNameUnknown()
38 throws Exception
39 {
40 onClassName( "unknown" ).loadWithBeanUtilsClassLoader();
41 }
42
43 @Test( expected = NullPointerException.class )
44 public void onClassNameTestBeanWithClassLoaderNull()
45 throws Exception
46 {
47 onClassName( TestBean.class.getName() ).loadWith( null );
48 }
49
50 @Test
51 public void onClassNameTestBeanWithThreadContextClassLoader()
52 throws Exception
53 {
54 assertNotNull( onClassName( TestBean.class.getName() ).loadWithThreadContextClassLoader() );
55 }
56
57 @Test
58 public void onClassNameTestBeanWithBeanUtilsClassLoader()
59 throws Exception
60 {
61 assertNotNull( onClassName( TestBean.class.getName() ).loadWithBeanUtilsClassLoader() );
62 }
63
64 @Test
65 public void onClassNameTestBeanWithJUnitClassLoader()
66 throws Exception
67 {
68 assertNotNull( onClassName( TestBean.class.getName() ).loadWith( getClass().getClassLoader() ) );
69 }
70
71 @Test
72 public void correctInstanceThreadContextClassLoader()
73 throws Exception
74 {
75 Object instance =
76 onClassName( TestBean.class.getName() ).loadWithThreadContextClassLoader().newInstance().get();
77 assertTrue( instance instanceof TestBean );
78 }
79
80 @Test
81 public void correctInstanceBeanUtilsClassLoader()
82 throws Exception
83 {
84 Object instance = onClassName( TestBean.class.getName() ).loadWithBeanUtilsClassLoader().newInstance().get();
85 assertTrue( instance instanceof TestBean );
86 }
87
88 @Test
89 public void correctInstanceJUnitClassLoader()
90 throws Exception
91 {
92 Object instance =
93 onClassName( TestBean.class.getName() ).loadWith( getClass().getClassLoader() ).newInstance().get();
94 assertTrue( instance instanceof TestBean );
95 }
96
97 }