1   
2   
3   
4   
5   
6   
7   
8   
9   
10  
11  
12  
13  
14  
15  
16  package org.kuali.rice.kcb.util;
17  
18  import org.junit.Assert;
19  import org.junit.Before;
20  import org.junit.Test;
21  import org.springframework.beans.factory.support.StaticListableBeanFactory;
22  
23  import java.lang.reflect.Proxy;
24  
25  
26  
27  
28  
29  
30  
31  public class BeanFactoryInvocationHandlerTest {
32      private static interface BadInterface {
33          public int add(int a, int b);
34  
35          public void notAGetter();
36  
37          public void get();
38  
39          public Object getBean();
40      }
41  
42      private BadInterface bad;
43  
44      @Before
45      public void createBadInstance() {
46          StaticListableBeanFactory bf = new StaticListableBeanFactory();
47          bf.addBean("bean", "This is a bean");
48          bad = (BadInterface)
49                  Proxy.newProxyInstance(this.getClass().getClassLoader(),
50                          new Class[]{BadInterface.class},
51                          new BeanFactoryInvocationHandler(bf));
52      }
53  
54      @Test(expected = RuntimeException.class)
55      public void testRandomMethod() {
56          int result = bad.add(2, 2);
57      }
58  
59      @Test(expected = RuntimeException.class)
60      public void testNotAGetter() {
61          bad.notAGetter();
62      }
63  
64      @Test(expected = RuntimeException.class)
65      public void testAnotherBadGetter() {
66          bad.get();
67      }
68  
69      @Test
70      public void testGoodGetter() {
71          Assert.assertEquals("This is a bean", bad.getBean());
72      }
73  }